1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-17 21:03:01 -05:00
denoland-deno/flags
Vincent LE GOFF dcd01dd025 Eslint fixes (denoland/deno_std#356)
Make warnings fail
Original: 4543b563a9
2019-04-24 07:41:22 -04:00
..
all_bool_test.ts Eslint fixes (denoland/deno_std#356) 2019-04-24 07:41:22 -04:00
bool_test.ts Eslint fixes (denoland/deno_std#356) 2019-04-24 07:41:22 -04:00
dash_test.ts Eslint fixes (denoland/deno_std#356) 2019-04-24 07:41:22 -04:00
default_bool_test.ts Eslint fixes (denoland/deno_std#356) 2019-04-24 07:41:22 -04:00
dotted_test.ts Eslint fixes (denoland/deno_std#356) 2019-04-24 07:41:22 -04:00
example.ts Change import { x } from "deno" to const { x } = Deno (denoland/deno_std#218) 2019-02-26 00:35:50 -05:00
kv_short_test.ts Eslint fixes (denoland/deno_std#356) 2019-04-24 07:41:22 -04:00
long_test.ts Eslint fixes (denoland/deno_std#356) 2019-04-24 07:41:22 -04:00
mod.ts Eslint fixes (denoland/deno_std#356) 2019-04-24 07:41:22 -04:00
num_test.ts Eslint fixes (denoland/deno_std#356) 2019-04-24 07:41:22 -04:00
parse_test.ts Eslint fixes (denoland/deno_std#356) 2019-04-24 07:41:22 -04:00
README.md Docs: Added missing example in flags module - README.md (denoland/deno_std#348) 2019-04-21 08:59:38 -04:00
short_test.ts Eslint fixes (denoland/deno_std#356) 2019-04-24 07:41:22 -04:00
stop_early_test.ts Eslint fixes (denoland/deno_std#356) 2019-04-24 07:41:22 -04:00
test.ts move test file out of tests dir in flags module (denoland/deno_std#293) 2019-03-19 13:24:11 -04:00
unknown_test.ts Eslint fixes (denoland/deno_std#356) 2019-04-24 07:41:22 -04:00
whitespace_test.ts Eslint fixes (denoland/deno_std#356) 2019-04-24 07:41:22 -04:00

flags

Command line arguments parser for Deno based on minimist

Example

const { args } = Deno;
import { parse } from "https://deno.land/std/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:
    const { args } = Deno;
    import { parse } from "https://deno.land/std/flags/mod.ts";
    // options['--'] is now set to false
    console.dir(parse(args, { "--": false }));
    // $ deno example.ts -- a arg1
    // output: { _: [ "example.ts", "a", "arg1" ] }
    // options['--'] is now set to true
    console.dir(parse(args, { "--": true }));
    // $ deno example.ts -- a arg1
    // output: { _: [ "example.ts" ], --: [ "a", "arg1" ] }
    
  • 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.