escli 0.0.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 38

commander.dart

Build Status License Dart

The complete solution for Dart command-line interfaces, inspired by node commander.js which created by tj.

Why

cause I don't like build the cli app with other exist lib.

those api are not graceful enough. so I want build a lib use like commander.js

it make you move cli tool from Nodejs easier.

This lib in developing. I can't make sure it work like expect even I have write many test cases.

Enjoy it!

Requirement

  • dart>=1.20.0

Supports

  • [x] Windows
  • [x] Linux
  • [x] MacOS

Example

Option parsing

#!/usr/bin/env dart

import 'package:escli/escli.dart' show Commander;

void main(List<String> arguments){
  Commander program = new Commander();
  
  program
    ..name('test')
    ..version('1.2.0')
    ..description('test desc')
    ..usage('<command> [options]')
    ..option('-p, --peppers', 'Add peppers')
    ..option('-P, --pineapple', 'Add pineapple')
    ..option('-b, --bbq-sauce', 'Add bbq sauce')
    ..option('-c, --cheese [type]', 'Add the specified type of cheese [marble]');
  
  program.parseArgv(arguments);
  
  print('--peppers: ${program.$option["peppers"]}');
  print('--pineapple: ${program.$option["pineapple"]}');
  print('--bbq-sauce: ${program.$option["bbqSauce"]}');
  print('--cheese: ${program.$option["cheese"]}');
  
  print('enjoy it');
}

Coercion

import 'package:escli/escli.dart' show Commander;
void main(List<String> arguments) {
  Commander program = new Commander();

  parseInt(int n){
    print('--interger: $n');
  }
  parseFlow(num n){
    print('--float: $n');
  }
  range(val) {
    print('--float: $val');
  }

  list(val) {
    print('--list: $val');
  }

  collect(val) {
    print('--optional: $val');
  }

  increaseVerbosity(val) {
    print('--verbose: $val');
  }

  program
    ..name('test')
    ..version('1.2.0')
    ..description('test desc')
    ..usage('<command> [options]')
    ..option('-i, --integer <n>', 'An integer argument', parseInt)
    ..option('-f, --float <n>', 'A float argument', parseFlow)
    ..option('-r, --range <a>..<b>', 'A range', range)
    ..option('-l, --list <items>', 'A list', list)
    ..option('-o, --optional [value]', 'An optional value')
    ..option('-c, --collect [value]', 'A repeatable value', collect)
    ..option('-v, --verbose', 'A value that can be increased', increaseVerbosity, 0)
    ..parseArgv(arguments);
}

Specify the argument syntax

import 'package:escli/escli.dart' show Commander;

void main(List<String> arguments){
  Commander program = new Commander();

  program
    ..version('0.0.1')
    ..arguments('<cmd> [env]')
    ..action((Map argv, Map options) {
    print(argv);
    print(options);
  });

  program.parseArgv(arguments);
}

Git-style sub-commands (Recommend)

import 'package:escli/escli.dart' show Commander;

void main(List<String> arguments) {
  Commander program = new Commander();

  program
    ..version('0.0.1');

  program
    .command('install [name]', 'install one or more packages')
    .action((Map argv, Map options) {

    });

  program
    .command('search [query]', 'search with optional query')
    .action((Map argv, Map options) {

    });
  
  program
    .command('list', 'list packages installed')
    .action((Map argv, Map options) {

    });
}

Automated -h, --help

$ gpmx -h

  Usage: gpmx <command> [options]

    Git Package Manager, make you manage the repository easier, Power by Dart

  Commands:
    ls|list              display the all repo.
    ad|add <repo>        clone repo into local dir.
    rm|remove            remove a repo.
    cl|clean             clean the temp/cache.
    rt|runtime           print the program runtime, useful for submit a issue.
    rl|relink            relink the base dir which contain repositories if you delete repository manually.
    ip|import <dir>      register a repository to GPM.

  Options:
    -V, --version      print the current version
    -h, --help         print the help info about 

Automated -V, --version

$ gpmx --version
0.0.1

Complete Demo

https://github.com/gpmer/gpm.dart

Test

./scripts/test

Contribute

git clone https://github.com/axetroy/commander.dart.git
cd ./commander.dart
pub get
./scripts/test

You can flow Contribute Guide

License

The MIT License

Changelog

0.0.1

  • Initial version, created by Stagehand

Use this package as a library

1. Depend on it

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


dependencies:
  escli: ^0.0.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:escli/escli.dart';
  
Version Uploaded Documentation Archive
0.0.1 Mar 6, 2017 Go to the documentation of escli 0.0.1 Download escli 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
41
Overall:
Weighted score of the above. [more]
38
Learn more about scoring.

We analyzed this package on Aug 18, 2018, and provided a score, details, and suggestions below. Analysis was completed with status tool failures using:

  • Dart: 2.0.0
  • pana: 0.11.8

Platforms

Detected platforms: unsure

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Issues and suggestions

Fix dependencies in pubspec.yaml.

Running pub upgrade failed with the following output:

ERR: The current Dart SDK version is 2.0.0.
 
 Because escli depends on ee any which requires SDK version <2.0.0, version solving failed.

Fix platform conflicts.

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Add SDK constraint in pubspec.yaml.

For information about setting SDK constraint, please see https://www.dartlang.org/tools/pub/pubspec#sdk-constraints.

Fix analysis_options.yaml.

We were unable to parse analysis_options.yaml.

Package is getting outdated.

The package was released 75 weeks ago.

The description is too short.

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v1 release.

While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction of the API.

Maintain an example.

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use escli.dart.

Format lib/command.dart.

Run dartfmt to format lib/command.dart.

Format lib/escli.dart.

Run dartfmt to format lib/escli.dart.

Format lib/option.dart.

Run dartfmt to format lib/option.dart.

Format lib/utils.dart.

Run dartfmt to format lib/utils.dart.