unscripted 0.6.1+1

  • README.md
  • Installing
  • Versions
  • --

unscripted pub package Build Status Coverage Status

Define command-line interfaces using ordinary dart methods and classes.


pub global activate den
den install unscripted


The following greet.dart script outputs a configurable greeting:

#!/usr/bin/env dart

import 'package:unscripted/unscripted.dart';

main(arguments) => new Script(greet).execute(arguments);

// All metadata annotations are optional.
@Command(help: 'Print a configurable greeting', plugins: const [const Completion()])
@ArgExample('--salutation Hi --enthusiasm 3 Bob', help: 'enthusiastic')
    @Rest(help: 'Name(s) to greet.')
    List<String> who, {
      @Option(help: 'Alternate word to greet with e.g. "Hi".')
      String salutation : 'Hello',
      @Option(help: 'How many !\'s to append.')
      int enthusiasm : 0,
      @Flag(abbr: 'l', help: 'Put names on separate lines.')
      bool lineMode : false
    }) {

  print(salutation +
        who.map((w) => (lineMode ? '\n  ' : ' ') + w).join(',') +
        '!' * enthusiasm);

We can call this script as follows:

$ greet.dart Bob
Hello Bob
$ greet.dart --salutation Hi --enthusiasm 3 -l Alice Bob

##Automatic --help

A --help/-h flag is automatically defined:

$ greet.dart --help


  Print a configurable greeting


  greet.dart [options] [WHO]...


      --salutation=<greeting>    Alternate <greeting> to greet with e.g. "Hi".
      --enthusiasm               How many !'s to append.
  -l, --line-mode                Put names on separate lines.
      --completion               Tab completion for this command.

            [install]            Install completion script to .bashrc/.zshrc.
            [print]              Print completion script to stdout.
            [uninstall]          Uninstall completion script from .bashrc/.zshrc.

  -h, --help                     Print this usage information.


  greet.dart --salutation Hi --enthusiasm 3 Bob # enthusiastic


Sub-commands are represented as SubCommand-annotated instance methods of classes, as seen in the following server.dart:

#!/usr/bin/env dart

import 'dart:io';

import 'package:unscripted/unscripted.dart';
import 'package:path/path.dart' as path;

main(arguments) => new Script(Server).execute(arguments);

class Server {

  final String configPath;

      help: 'Manages a server',
      plugins: const [const Completion()])
  Server({this.configPath: 'config.xml'});

  @SubCommand(help: 'Start the server')
  start({bool clean: false}) {
Starting the server.
Config path: $configPath''');

  @SubCommand(help: 'Stop the server')
  stop() {
    print('Stopping the server.');


We can call this script as follows:

$ server.dart start --config-path my-config.xml --clean
Starting the server.
Config path: my-config.xml

Help is also available for sub-commands:

$ server.dart help

Available commands:


Use "server.dart help [command]" for more information about a command.

$ server.dart help stop


  Stop the server


  server.dart stop [options]


  -h, --help    Print this usage information.


Any value-taking argument (option, positional, rest) can have a "parser" responsible for validating and transforming the string passed on the command line. You can give an argument a parser simply by giving it a type (such as int or DateTime) which has a static parse method, or by specifying the parser named argument of the argument's metadata (Option, Positional, or Rest).


Plugins allow you to mixin reusable chunks of cli-specific functionality (options/flags/commands) on top of your base interface.

To add a plugin to your script, just add an instance of the associated plugin class to the plugins named argument of your @Command annotation. The following plugins are available:

###Tab Completion

Add bash/zsh tab completion to your script:

@Command(/*...*/ plugins: const [const Completion()])

If your script already has sub-commands, this will add a completion sub-command (similar to npm completion), otherwise it adds a --completion option. These can then be used as follows:

# Try the tab-completion without permanently installing.
. <(greet.dart --completion print)
. <(server.dart completion print)

# Install the completion script to .bashrc/.zshrc depending on current shell.
# No-op if already installed.
greet.dart --completion install
server.dart completion install

# Uninstall a previously installed completion script.
# No-op if not installed.
greet.dart --completion uninstall
server.dart completion uninstall

Once installed, the user will be able to tab-complete all aspects of your cli, for example:

Option/Flag names: Say your script is a dart method with a longOptionName named parameter. This becomes --long-option-name in your cli, and once completion is installed, the user can type --l[TAB] and it will be completed to --long-option-name. It will also expand short options to their long equivalents, e.g. -vh[TAB] becomes --verbose --help.

Commands: If your script is a dart class having a @SubCommand() longCommandName method, that becomes a long-command-name sub-command in your cli, and the user can type l[TAB] and it will be completed to long-command-name.

Option/Positional/Rest values: The allowed named parameter of Option, Positional, and Rest specifies the allowed values, and thus completions, for those parameters. For example if you have @Option(allowed: const ['red', 'yellow', 'green']) textColor, and the user types --text-color g[TAB] this will become --text-color green. allowed can also be a callback of one of the following forms:

Iterable<String> complete(String text);
Iterable<String> complete();
Future<Iterable<String>> complete(String text);
Future<Iterable<String>> complete();

where if an arg (e.g. text here) is specified, it represents the last partial word typed by the user when completion is requested, which can be used to filter the results to match that prefix. If the arg is omitted, the filtering is done automatically for you. For example if the option/positional/rest represents a file name, you could emulate the builtin shell file name completion by returning a list of filenames in the current directory.

Tab completion is supported in cygwin, with one minor bug (#64).

###Other Plugins

There are several other plugins planned, and also the ability to write your own is planned, see #62.


den uses a large subset of the features above. Run pub global activate den to install, and then den -h to get a feel for the UX provided by unscripted.

0.6.0 #

  • Deprecated declare in favor of new Script.

Breaking changes:

  • Script.execute now calls the method asynchronously so that it can return a Future for the return value.

0.5.0 #

Breaking changes:

  • Flags without a null default value now default to null instead of false when neither the flag nor it's negation occur on the command-line (#86)

0.4.6 #


  • Improve color-support detection (#73)

0.4.5 #


  • Reference scripts as foo instead of foo.dart (expect foo.bat in cygwin) (#80)
  • Add allowTrailingOptions to Command and SubCommand (#70)

0.4.4 #


  • Fixed omission of {Rest,Positional}.allowed (#79)

0.4.3 #


  • Colorful help output (#68)
  • Add help output for positional arguments (#42)
  • Add metaVar configuration (#43)
  • Only fail completion in windows on actual usage not definition (#75)
  • Support hidden commands (#69)
  • Allow omitting arg to allowed callback (#67)
  • Allow latest args version (#74)


  • Fix some checked mode errors
  • Fix running scripts via pub run

0.4.0 #


  • Tab Completion! (#7)
  • Initial plugin support (see #62)
  • Improved examples to demo parsers and other metadata

Breaking changes:

  • Removed CallStyle

0.3.2 #


  • dart:mirror closurization operator removed (#50)

0.3.0 #


  • Demo: complete *nix cat implementation (#28)
  • Derive parsers from type annotations (#31)
  • Derive rest parameter from List type annotation (#36)
  • Derive allowMultiple from List type annotation (#34)
  • Add ellipsis to rest parameter help formatting (#22)
  • Include script name in error messages (#32)
  • Input and output parsers which transparently handle both file paths and '-' for stdin/stdout (#23)

Breaking changes:

  • Renamed sketch to declare (#37)
  • Rest.min changed to Rest.required (#26)
  • Flag.negatable now defaults to false (#25)

0.2.0 #


  • Support argument parsers (#5)
  • Support hierarchical sub-commands (#15)

Breaking changes:

  • @Command metadata must now be placed on the unnamed constructor instead of the class.
  • allowedHelp in Option is now merged into allowed.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  unscripted: ^0.6.1+1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:unscripted/unscripted.dart';
Version Uploaded Documentation Archive
0.6.2 Jun 17, 2015 Go to the documentation of unscripted 0.6.2 Download unscripted 0.6.2 archive
0.6.1+1 Apr 29, 2015 Go to the documentation of unscripted 0.6.1+1 Download unscripted 0.6.1+1 archive
0.6.1 Apr 24, 2015 Go to the documentation of unscripted 0.6.1 Download unscripted 0.6.1 archive
0.6.0 Mar 20, 2015 Go to the documentation of unscripted 0.6.0 Download unscripted 0.6.0 archive
0.5.2+1 Dec 22, 2014 Go to the documentation of unscripted 0.5.2+1 Download unscripted 0.5.2+1 archive
0.5.2 Dec 22, 2014 Go to the documentation of unscripted 0.5.2 Download unscripted 0.5.2 archive
0.5.1 Dec 10, 2014 Go to the documentation of unscripted 0.5.1 Download unscripted 0.5.1 archive
0.5.0 Dec 10, 2014 Go to the documentation of unscripted 0.5.0 Download unscripted 0.5.0 archive
0.4.7 Oct 21, 2014 Go to the documentation of unscripted 0.4.7 Download unscripted 0.4.7 archive
0.4.6 Oct 17, 2014 Go to the documentation of unscripted 0.4.6 Download unscripted 0.4.6 archive

All 29 versions...

Awaiting analysis to complete.