NyCustomCommand class abstract
Base class for custom commands
- Available extensions
Constructors
-
NyCustomCommand(List<
String> arguments) -
Creates a new command with the given
arguments.
Properties
-
arguments
↔ List<
String> -
The command-line arguments passed to the command.
getter/setter pair
- commandsPath → String
-
Path to commands directory
no setter
- configPath → String
-
Path to config directory
no setter
- controllersPath → String
-
Path to controllers directory
no setter
- eventsPath → String
-
Path to events directory
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isLinux → bool
-
Check if running on Linux
no setter
- isMacOS → bool
-
Check if running on macOS
no setter
- isWindows → bool
-
Check if running on Windows
no setter
- modelsPath → String
-
Path to models directory
no setter
- networkingPath → String
-
Path to networking directory
no setter
- pagesPath → String
-
Path to pages directory
no setter
- providersPath → String
-
Path to providers directory
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- themesPath → String
-
Path to themes directory
no setter
- widgetsPath → String
-
Path to widgets directory
no setter
- workingDirectory → String
-
Get the current working directory
no setter
Methods
-
abort(
[String? message, int exitCode = 1]) → Never - Exit the command with an error message and exit code
-
addImport(
String filePath, String importStatement) → Future< void> - Add an import statement to a Dart file The import will be added after the last existing import
-
addPackage(
String package, {String? version, bool dev = false}) → Future< void> - Add a package to the pubspec.yaml file
-
addPackages(
List< String> packages, {bool dev = false}) → Future<void> - Add multiple packages to the pubspec.yaml file
-
alert(
String message) → void - Prints a prominent alert box with a message
-
api<
T> (Future< T?> request(ApiService)) → Future<T?> - A simplified API wrapper function that doesn't require type parameter
-
appendFile(
String path, String content) → Future< void> - Append content to a file (creates the file if it doesn't exist)
-
appendToJsonArray(
String path, Map< String, dynamic> item, {String? uniqueKey}) → Future<void> - Append an item to a JSON array file
-
ask(
String question, {String defaultValue = ''}) → String - Alias for prompt for brevity.
-
builder(
CommandBuilder commandBuilder) → CommandBuilder - Define the command configuration
-
camelCase(
String input) → String - Convert a string to camelCase Example: "my_component" -> "myComponent"
-
cleanClassName(
String name, {List< String> removeSuffixes = const []}) → String - Clean and validate a class name Removes common suffixes and converts to PascalCase
-
cleanFileName(
String name, {String extension = '.dart'}) → String - Clean a file name (converts to snake_case and adds .dart extension if missing)
-
comment(
String message) → void - Prints a message in gray/muted color
-
confirm(
String question, {bool defaultValue = false}) → bool - Asks the user a yes/no question and returns a boolean
-
constantCase(
String input) → String - Convert a string to CONSTANT_CASE Example: "myComponent" -> "MY_COMPONENT"
-
copyDirectory(
String source, String destination) → Future< void> - Copy a directory and all its contents to a new location
-
copyFile(
String source, String destination) → Future< void> - Copy a file from source to destination
-
createSpinner(
String message) → ConsoleSpinner -
Available on NyCustomCommand, provided by the SpinnerExtension extension
Create and return a spinner instance for manual control -
dartAnalyze(
[String? path]) → Future< int> - Run dart analyze on a path (defaults to current directory)
-
dartFormat(
String path) → Future< int> - Run dart format on a file or directory
-
deleteDirectory(
String path) → Future< void> - Delete a directory and all its contents
-
deleteFile(
String path) → Future< void> - Delete a file if it exists
-
directoryExists(
String path) → bool - Check if a directory exists at the given path
-
ensureDirectory(
String path) → Future< void> - Ensure a directory exists, creating it if necessary
-
env(
String key, [String defaultValue = '']) → String - Get an environment variable value with optional default
-
error(
String message) → void - Prints a message in red color
-
fileContains(
String filePath, String identifier) → Future< bool> - Check if a file contains a specific string or pattern
-
fileContainsPattern(
String filePath, Pattern pattern) → Future< bool> - Check if a file contains a pattern (regex)
-
fileExists(
String path) → bool - Check if a file exists at the given path
-
findFiles(
String directory, {String? extension, Pattern? namePattern, bool recursive = true}) → List< File> - Find files matching criteria in a directory
-
flutterBuild(
String target, {List< String> args = const []}) → Future<int> - Run flutter build with a target
-
flutterClean(
) → Future< int> - Run flutter clean
-
flutterPubGet(
) → Future< int> - Run flutter pub get
-
flutterTest(
[String? path]) → Future< int> - Run flutter test
-
handle(
CommandResult result) → Future< void> - Execute the command with parsed results
-
info(
String message) → void - Prints a message in blue color
-
insertBeforeClosingBrace(
String filePath, String code) → Future< void> - Insert code before the closing brace of the last class in a file Useful for adding methods to a class
-
isValidDartIdentifier(
String name) → bool - Check if a string is a valid Dart identifier
-
kebabCase(
String input) → String - Convert a string to kebab-case Example: "MyComponent" -> "my-component"
-
line(
String message) → void - Prints a message without any color formatting
-
listDirectory(
String path, {bool recursive = false}) → List< FileSystemEntity> - List all entities in a directory
-
multiSelect(
String question, List< String> options) → List<String> - Multi-select - allows user to select multiple options
-
newLine(
[int count = 1]) → void - Prints one or more blank lines
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pascalCase(
String input) → String - Convert a string to PascalCase Example: "my_component" -> "MyComponent"
-
progressBar(
int total, {String? message}) → ConsoleProgressBar - Create a progress bar for manual control
-
projectPath(
String relativePath) → String - Build a path within the project Example: projectPath('app/models/user.dart') -> 'lib/app/models/user.dart'
-
prompt(
String question, {String defaultValue = ''}) → String - Asks the user a question and returns their response
-
promptSecret(
String question) → String - Asks the user for sensitive input (password, tokens, etc.) Input is hidden from display
-
readFile(
String path) → Future< String> - Read the contents of a file as a string
-
readFileSync(
String path) → String - Read the contents of a file synchronously
-
readJson(
String path) → Future< Map< String, dynamic> > - Read a JSON file and return its contents as a Map
-
readJsonArray(
String path) → Future< List> - Read a JSON file and return its contents as a List
-
readYaml(
String path) → Future< Map< String, dynamic> > - Read a YAML file and return its contents as a Map
-
requireArgument(
CommandResult result, {String? message}) → String - Require a non-empty first argument from the command result Exits with an error if no argument is provided
-
run(
) → Future< void> - Run the command
-
runProcess(
String command, {String? workingDirectory, bool? runInShell, bool silent = false}) → Future< int> - Run a process with the given command
-
runTasks(
List< CommandTask> tasks) → Future<void> - Run a list of named tasks with status output
-
runTasksWithSpinner(
List< CommandTask> tasks) → Future<void> - Run tasks with a spinner animation
-
scaffold(
{required String path, required String content, bool force = false, String? successMessage}) → Future< bool> - Create a file with common scaffolding patterns Returns true if the file was created successfully
-
scaffoldMany(
List< ScaffoldFile> files, {bool force = false}) → Future<void> - Create multiple files at once
-
select(
String question, List< String> options, {String? defaultOption}) → String - Asks the user to select an option from a list
-
sleep(
int seconds, [int microseconds = 0]) → Future< void> -
Sleeps for a specified number of
seconds. -
snakeCase(
String input) → String - Convert a string to snake_case Example: "MyComponent" -> "my_component"
-
success(
String message) → void - Prints a message in green color
-
table(
List< String> headers, List<List< rows) → voidString> > - Display data in a formatted table
-
titleCase(
String input) → String - Convert a string to Title Case Example: "my_component" -> "My Component"
-
toString(
) → String -
A string representation of this object.
inherited
-
warning(
String message) → void - Prints a message in yellow color
-
withProgress<
T, R> ({required List< T> items, required Future<R> process(T item, int index), String? message, String? completionMessage}) → Future<List< R> > -
Available on NyCustomCommand, provided by the SpinnerExtension extension
Process a list of items with a progress bar Returns a list of results from processing each item -
withProgressSync<
T, R> ({required List< T> items, required R process(T item, int index), String? message, String? completionMessage}) → List<R> -
Available on NyCustomCommand, provided by the SpinnerExtension extension
Process items synchronously with a progress bar -
withSpinner<
T> ({required Future< T> task(), required String message, String? successMessage, String? errorMessage}) → Future<T> -
Available on NyCustomCommand, provided by the SpinnerExtension extension
Run a task with a spinner animation -
writeFile(
String path, String content) → Future< void> - Write content to a file (creates the file if it doesn't exist)
-
writeFileSync(
String path, String content) → void - Write content to a file synchronously
-
writeJson(
String path, dynamic data, {bool pretty = true}) → Future< void> - Write data to a JSON file
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited