escli 0.0.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 39

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

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

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages 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

Analysis

We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
77 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
81 / 100
Overall score:
Weighted score of the above. [more]
39
Learn more about scoring.

Platforms

Detected platforms: Flutter, other

Primary library: package:escli/escli.dart with components: io.

Suggestions

  • Use constrained dependencies.

    The pubspec.yaml contains 1 dependency without version constraints. Specify version ranges for the following dependencies: ee.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 2 errors 5 hints.

    Strong-mode analysis of lib/escli.dart failed with the following error:

    line: 32 col: 63
    The argument type '(bool) → Null' can't be assigned to the parameter type '(dynamic) → void'.

    Run dartfmt to format lib/command.dart.

    Similar analysis of the following files failed:

    • lib/option.dart (hint)
    • lib/utils.dart (hint)
  • Fix analysis_options.yaml.

    We were unable to parse analysis_options.yaml.

  • 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 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.

  • Enable strong mode analysis.

    Strong mode helps you to detect bugs and potential issues earlier.Start your analysis_options.yaml file with the following:

    analyzer:
      strong-mode: true
    

Dependencies

Package Constraint Resolved Available
Direct dependencies
ee 0.0.3
Dev dependencies
test