vader_console
Vader Console Package for simplify development of CLI Dart programs.
Installation
Add the following dependency to your pubspec.yaml file:
dependencies:
vader_console: ^1.0.0
Then run:
flutter pub get
Usage:
- Define Commands:
List<Command> commands = [
...CoreCommands.list,
Command(
flag: 'm',
name: 'message',
commandType: CommandType.option,
commandHelp: 'Print message.',
),
];
- Define Arguments:
class ExampleArguments extends Arguments {
ExampleArguments({
required super.showVersion,
required super.showHelp,
required super.isVerbose,
this.message,
});
final String? message;
factory ExampleArguments.parse(List<String> arguments, List<Command> commands) {
final results = ArgumentParser(commands).parse(arguments);
return ExampleArguments(
showHelp: results.wasParsed(CoreCommands.help.name),
isVerbose: results.wasParsed(CoreCommands.verbose.name),
showVersion: results.wasParsed(CoreCommands.version.name),
message: Arguments.getOptionOrNull(results, option: "message"),
);
}
}
- Setup main function:
void main(List<String> args) {
runCliApp(
arguments: args,
commands: commands,
parser: ExampleArguments.parse,
app: (args) {
print("Main part of my app...");
print("Message: ${args.message}");
},
);
}
Author
👤 Martin Jablečník
- Website: martin-jablecnik.cz
- Github: @mjablecnik
- Blog: dev.to/mjablecnik
Show your support
Give a ⭐️ if this project helped you!
📝 License
Copyright © 2024 Martin Jablečník.
This project is licensed under MIT License.