1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-17 21:03:01 -05:00
denoland-deno/flags
2019-01-26 23:19:56 -05:00
..
tests Port prettier (denoland/deno_std#156) 2019-01-26 23:19:56 -05:00
example.ts Reorgnanize repos, examples and tests (denoland/deno_std#105) 2019-01-12 16:50:04 -05:00
mod.ts Reorgnanize repos, examples and tests (denoland/deno_std#105) 2019-01-12 16:50:04 -05:00
README.md fix wrong links for flags (denoland/deno_std#112) 2019-01-14 00:34:46 -05:00
test.ts Add flags module (denoland/deno_std#32) 2018-12-19 13:06:31 -05:00

flags

Command line arguments parser for Deno based on minimist

Example

import { args } from "deno";
import { parse } from "https://deno.land/x/flags/mod.ts";

console.dir(parse(args));
$ deno example.ts -a beep -b boop
{ _: [], a: 'beep', b: 'boop' }
$ deno example.ts -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
{ _: [ 'foo', 'bar', 'baz' ],
  x: 3,
  y: 4,
  n: 5,
  a: true,
  b: true,
  c: true,
  beep: 'boop' }

API

const parsedArgs = parse(args, options = {});

parsedArgs._ contains all the arguments that didn't have an option associated with them.

Numeric-looking arguments will be returned as numbers unless options.string or options.boolean is set for that argument name.

Any arguments after '--' will not be parsed and will end up in parsedArgs._.

options can be:

  • options.string - a string or array of strings argument names to always treat as strings
  • options.boolean - a boolean, string or array of strings to always treat as booleans. if true will treat all double hyphenated arguments without equal signs as boolean (e.g. affects --foo, not -f or --foo=bar)
  • options.alias - an object mapping string names to strings or arrays of string argument names to use as aliases
  • options.default - an object mapping string argument names to default values
  • options.stopEarly - when true, populate parsedArgs._ with everything after the first non-option
  • options['--'] - when true, populate parsedArgs._ with everything before the -- and parsedArgs['--'] with everything after the --. Here's an example:
  • options.unknown - a function which is invoked with a command line parameter not defined in the options configuration object. If the function returns false, the unknown option is not added to parsedArgs.