core/core library

Core utilities for CLI application development.

This library provides a comprehensive set of utilities for building command-line applications, including file operations, process execution, console output, and system utilities.

Modules

Console and Display

  • ANSI: Color and formatting utilities for terminal output
  • Loading: Animated loading indicators for long-running operations
  • Print: Error output utilities for stderr

File System Operations

  • File Operations: Copy, move, create, delete files and directories
  • Path Utilities: Path normalization and resolution
  • File Search: Find files and directories with glob patterns
  • File I/O: Read and write text files

Process and Command Execution

  • String Extensions: Execute commands with enhanced process control
  • Command Parsing: Parse command-line strings into arguments

System Utilities

  • Environment Detection: Check for CI/CD environments
  • Path Search: Find executables in system PATH
  • File Type Detection: Check file system entity types

Text Processing

  • Content Replacement: Find and replace text in files
  • Logging: Simple file-based logging utilities

Example Usage

import 'package:morpheme_cli/core/core.dart';

// File operations
copy('/path/to/source.txt', '/path/to/dest.txt');
createDir('/path/to/new/directory', recursive: true);

// Console output with colors
print(red('Error: Something went wrong'));
print(green('Success: Operation completed'));

// Process execution
await 'flutter build apk'.run;

// File search
find('*.dart').forEach(print);

// Loading animation
final loading = Loading();
loading.start();
// ... long operation ...
loading.stop();

Classes

Ansi
Helper class for ANSI escape sequence detection and management.
AnsiColor
ANSI color management class for terminal text formatting.
CommandlineConverter
Command-line string parsing utilities.
Find
Implementation for the _find function.
FindItem
Holds details of a file system entity returned by the find function.
FindProgress
Progress tracker for find operations.
InternalProgress
Base class for operations that return progress information.
Loading
Loading animation manager for CLI applications.
Which
Search results container for executable location queries.
WhichSearch
Individual search result for a single PATH directory.

Extensions

StringExtension on String
String extensions for command execution and file operations.

Constants

capturePrinterrKey → const String
Zone key for capturing stderr output.

Properties

isCiCdEnvironment bool
Check if the current environment is a CI/CD environment.
no setter

Functions

black(String text, {AnsiColor background = AnsiColor.white, bool bold = true}) String
Apply black color to text.
blue(String text, {AnsiColor background = AnsiColor.none, bool bold = true}) String
Apply blue color to text.
copy(String from, String to, {bool overwrite = false}) → void
Copy a file from one location to another.
copyTree(String from, String to, {bool overwrite = false, bool filter(String file) = _allowAll, bool includeHidden = false, bool recursive = true}) → void
Copy an entire directory tree from one location to another.
createDir(String path, {bool recursive = true}) String
Create a directory at the specified path.
cyan(String text, {AnsiColor background = AnsiColor.none, bool bold = true}) String
Apply cyan color to text.
delete(String path) → void
Delete a file from the file system.
deleteDir(String path, {bool recursive = true}) → void
Delete a directory from the file system.
exists(String path, {bool followLinks = true}) bool
File system existence and type checking utilities.
find(String pattern, {bool caseSensitive = false, bool recursive = true, bool includeHidden = false, String workingDirectory = '.', List<FileSystemEntityType> types = const [Find.file]}) FindProgress
Find files and directories matching a glob pattern.
findCore(String pattern, {required ProgressCallback progress, bool caseSensitive = false, bool recursive = true, bool includeHidden = false, String workingDirectory = '.', List<FileSystemEntityType> types = const [Find.file]}) → void
Returns the list of files in the current and child directories that match the passed glob pattern.
green(String text, {AnsiColor background = AnsiColor.none, bool bold = true}) String
Apply green color to text.
grey(String text, {double level = 0.5, AnsiColor background = AnsiColor.none, bool bold = true}) String
Apply grey color to text with adjustable brightness level.
isDirectory(String path) bool
Check if a path points to a directory.
Check if a path points to a symbolic link.
magenta(String text, {AnsiColor background = AnsiColor.none, bool bold = true}) String
Apply magenta color to text.
move(String from, String to, {bool overwrite = false}) → void
Move a file from one location to another.
moveDir(String from, String to) Future<void>
Move a directory from one location to another.
orange(String text, {AnsiColor background = AnsiColor.none, bool bold = true}) String
Apply orange color to text.
printerr(String? line) → void
Write a message to stderr (standard error output).
printerrMessage(String? message) → void
printMessage(String? message) → void
Global console output utilities with loading animation support.
read(String path) List<String>
File reading utilities for text files.
readFile(String path) String
Read the entire content of a text file as a single string.
red(String text, {AnsiColor background = AnsiColor.none, bool bold = true}) String
ANSI color utility functions for terminal text formatting.
replace(String path, Pattern existing, String replacement, {bool all = false}) int
Text replacement utilities for file content modification.
Resolves a symbolic link to its target path.
touch(String path, {bool create = false}) String
Create a file or update its timestamps.
truepath(String part1, [String? part2, String? part3, String? part4, String? part5, String? part6, String? part7]) String
Path normalization and resolution utilities.
which(String appname, {bool first = true, bool verbose = false, bool extensionSearch = true, void progress(WhichSearch)?}) Which
Path search utilities for finding executable applications.
white(String text, {AnsiColor background = AnsiColor.none, bool bold = true}) String
Apply white color to text.
yellow(String text, {AnsiColor background = AnsiColor.none, bool bold = true}) String
Apply yellow color to text.

Typedefs

CancelableLineAction = bool Function(String line)
Callback function type for cancellable line processing. Returns true to continue processing, false to stop.
CaptureZonePrintErr = void Function(String?)
Error output utilities for CLI applications.
LineAction = void Function(String line)
File system search and discovery utilities.
ProgressCallback = bool Function(FindItem item)