clibu 1.5.0 copy "clibu: ^1.5.0" to clipboard
clibu: ^1.5.0 copied to clipboard

A tiny library to make the writing of command-line apps intuitive.

CLI 💻 #

GitHub CI

Making the writing of command-line apps in Dart intuitive. 💻

About 📚 #

Some time ago, I wanted to make a command-line tool in Dart. This is when I noticed that I didn't have a clue about how to make a responsive and "classic" command-line app. CLI covers this need. It allows you to make command-line apps in the way you are used to from GNU programs. Flags like --help or --version are provided out of the box.

Installation 📥 #

Adding to your project #

To add CLI to your project's dependencies, add this line to your project's pubspec.yaml:

From GitHub

depdencies:
  ...
  clibu:
    git: git://github.com/iamtheblackunicorn/cli.git

From Pub.dev

depdencies:
  ...
  clibu: ^1.5.0

The three dots represent anything else that you might have in the dependencies section. Having done that, re-fetch your project's dependencies by running this in the project's root directory:

$ dart pub get

Usage 🔨 #

Importing #

Import the API like this:

import 'package:clibu/clibu.dart';

Example 📲 #

This is what a minimal example using CLI Black Unicorn would look like.

/*
CLI Black Unicorn by Alexander Abraham a.k.a. The Black Unicorn
licensed under the MIT license
*/

import 'package:clibu/clibu.dart';

// Inherits from the original class,
// "CommandLineApp".
class TestApp extends CommandLineApp {
  @override
  String appName = 'Test';
  @override
  String appVersion = '1.0';
  @override
  String appAuthor = 'The Black Unicorn';
  @override
  String appLicense = 'MIT license';
  @override
  Map<String, dynamic> argumentsDataBase = {};
}

// Function to execute when the option
// is called.
void greet(String name) {
  String greeting = 'Hello, $name!';
  print(greeting);
}

// Main entry point for the Dart VM.
void main(List<String> arguments) {
  TestApp myApp = TestApp();
  myApp.addArgument('--greet', 'greets the user with a specified name', true);
  if (myApp.argumentWasUsed(arguments, '--greet') == true) {
    greet(myApp.getArgumentData(arguments, '--greet'));
  }
  myApp.runApp(arguments); // finally running the app
}

Note 📜 #

  • CLI 💻 by Alexander Abraham 🖤 a.k.a. "The Black Unicorn" 🦄
  • Licensed under the MIT license.
3
likes
130
pub points
0%
popularity

Publisher

verified publisherblckunicorn.art

A tiny library to make the writing of command-line apps intuitive.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

pedantic

More

Packages that depend on clibu