mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
f184332c09
* Prepend underscores to private modules * Remove collectUint8Arrays() It would be a misuse of Deno.iter()'s result. * Move std/_util/async.ts to std/async * Move std/util/sha*.ts to std/hash
2.2 KiB
2.2 KiB
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 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 stringsoptions.boolean
- a boolean, string or array of strings to always treat as booleans. iftrue
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 aliasesoptions.default
- an object mapping string argument names to default valuesoptions.stopEarly
- when true, populateparsedArgs._
with everything after the first non-optionoptions['--']
- when true, populateparsedArgs._
with everything before the--
andparsedArgs['--']
with everything after the--
. Here's an example:// $ deno run example.ts -- a arg1 const { args } = Deno; import { parse } from "https://deno.land/std/flags/mod.ts"; console.dir(parse(args, { "--": false })); // output: { _: [ "a", "arg1" ] } console.dir(parse(args, { "--": true })); // output: { _: [], --: [ "a", "arg1" ] }
options.unknown
- a function which is invoked with a command line parameter not defined in theoptions
configuration object. If the function returnsfalse
, the unknown option is not added toparsedArgs
.