1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00
denoland-deno/std/flags
Bartek Iwańczuk 8e914be742
build: migrate to dlint (#8176)
This commit migrates repository from using "eslint" 
to "dlint" for linting JavaScript code.
2020-11-03 16:19:29 +01:00
..
all_bool_test.ts BREAKING: remove overload of Deno.test() (#4951) 2020-04-28 12:33:09 +02:00
bool_test.ts BREAKING: remove overload of Deno.test() (#4951) 2020-04-28 12:33:09 +02:00
dash_test.ts Use dprint for internal formatting (#6682) 2020-07-14 15:24:17 -04:00
default_bool_test.ts BREAKING: remove overload of Deno.test() (#4951) 2020-04-28 12:33:09 +02:00
dotted_test.ts BREAKING: remove overload of Deno.test() (#4951) 2020-04-28 12:33:09 +02:00
kv_short_test.ts BREAKING: remove overload of Deno.test() (#4951) 2020-04-28 12:33:09 +02:00
long_test.ts BREAKING: remove overload of Deno.test() (#4951) 2020-04-28 12:33:09 +02:00
mod.ts build: migrate to dlint (#8176) 2020-11-03 16:19:29 +01:00
num_test.ts BREAKING: remove overload of Deno.test() (#4951) 2020-04-28 12:33:09 +02:00
parse_test.ts fix(std/flags): Fix parse incorrectly parsing alias flags with equals signs in the value #8136 (#8216) 2020-11-02 23:17:26 +01:00
README.md docs(std): version all imports in README (#7442) 2020-10-04 14:18:36 +02:00
short_test.ts BREAKING: remove overload of Deno.test() (#4951) 2020-04-28 12:33:09 +02:00
stop_early_test.ts BREAKING: remove overload of Deno.test() (#4951) 2020-04-28 12:33:09 +02:00
test.ts chore: add copyright (#7593) 2020-09-21 08:26:41 -04:00
unknown_test.ts Use dprint for internal formatting (#6682) 2020-07-14 15:24:17 -04:00
whitespace_test.ts BREAKING: remove overload of Deno.test() (#4951) 2020-04-28 12:33:09 +02:00

flags

Command line arguments parser for Deno based on minimist.

Example

import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";

console.dir(parse(Deno.args));
$ deno run https://deno.land/std/examples/flags.ts -a beep -b boop
{ _: [], a: 'beep', b: 'boop' }
$ deno run https://deno.land/std/examples/flags.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:
    // $ deno run example.ts -- a arg1
    import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
    console.dir(parse(Deno.args, { "--": false }));
    // output: { _: [ "a", "arg1" ] }
    console.dir(parse(Deno.args, { "--": true }));
    // output: { _: [], --: [ "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.