CLI :computer:

Build Status

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

About :books:

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 :inbox_tray:

Adding to your project

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

From GitHub

    git: git://


  clibu: ^1.1.2

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 :hammer:


Import the command-line API like this:

import 'package:clibu/clibu.dart';

Import the API for files like this:

import 'package:clibu/files.dart';



class CommandLineApp

Key command-line app class. The entire app lives in this class.

void addArgument(String argumentName, String helpMessage, bool isActive)

Adds an argument to your app!

void appHelpMessage()

"Batteries-included" app help text! Prints help info about the app when the app is invoked with help, --help, or -h.

void appInfoMessage()

"Batteries-included" app info text! Prints info about the app when the app is invoked with info, --info, or -i.

void appVersionMessage()

"Batteries-included" app version text! Prints version info about the app when the app is invoked with version, --version, or -v.

bool argumentWasUsed(List arguments, String argument)

User method to check if an argument was used!

String getArgumentData(List arguments, String argument)

User method to fetch the data of an argument! This will only work if the isActive flag is true.

void runApp(List arguments)

This method runs the app! Batteries-included flags of help, info, and version.


void runCommand(String shellCommand)

Runs a shell command and prints the output from STDERR and STDOUT.

String getFileContents(String filePath)

Returns the contents of a file as a string.

Map<String,dynamic> getJSONMap(String jsonString)

Returns a JSON string as a map.

String mapToJSON(Map<String,dynamic> jsonData)

Converts a Dart Map to a JSON string.

void writeToFile(String filePath, String fileContents)

Writes a string to a file.

bool fileExists(String filePath)

Checks whether a file exists.

void testFileFunctions()

A function to test all of the file functions.

Example :calling:

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

CLI 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 {
  String appName = 'Test';
  String appVersion = '1.0';
  String appAuthor = 'The Black Unicorn';
  String appLicense = 'MIT license';
  Map<String, dynamic> argumentsDataBase = {};

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

// 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 :scroll:

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