@xornot/command-line
Command line parser and usage helper.
Last updated a year ago by chrisackerman .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @xornot/command-line 
SYNC missed versions from official npm registry.

xornot.io command-line

Command line parser and usage helper.

Args

import {ArgsBuilder} from "command-line";

const args: Args = new ArgsBuilder()
  .command("command") // Argument without a "-" prefix, before all "-" prefixed arguments.
  .option("foo", "f") // Argument prefixed with a "-", with a value.
  .flag("bar", "b") // Argument prefixed with a "-", without a value.
  .positional("baz") // Argument without a "-" prefix or after a "--" argument, not used by another argument.
  .get();

const command: string = args.command.last.value; // throws if there are no values.
const foo: string[] = args.foo.all; // All values (options can be used more than once).
const bar: boolean = args.bar.isPresent; // Flags have no values, they're just present or missing.
const baz: string = args.baz.last.or("default");
const unused: string[] = args.$argv; // All values not consumed by defined args.

// Re-open the args builder to add new args.
// * The new args will still have all values from the source args.
const newArgs: Args = args.$builder
  .option("abc")
  .get();

Usage

import {Usage} from "command-line";

// The least common indent is stripped from the beginning of all lines.
const usage = new Usage(`
  Usage:  tool [options...]
`);

// The following commands all print the usage text and exit immediately.
usage.show();
usage.error();
usage.error("Error message");

Current Tags

  • 1.1.1                                ...           latest (a year ago)

5 Versions

  • 1.1.1                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |