summaryrefslogtreecommitdiff
path: root/std/flags/README.md
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-10-10 05:31:23 -0400
committerGitHub <noreply@github.com>2019-10-10 05:31:23 -0400
commite7562eed8c816cd0d97aab6b818d7c8453dbaa2b (patch)
treec5a9f536e79d2c8d2d02897511a9138acaf35394 /std/flags/README.md
parent3882c9d19a641e0c919f1350d87c6d7ee280cf78 (diff)
parent93f7f00c956c14620ef031626f124b57397ca867 (diff)
Merge deno_std in main repo (#3091)
The history of deno_std is persevered but rewritten to update links to issues and PRs Fixes denoland/deno_std#603
Diffstat (limited to 'std/flags/README.md')
m---------std0
-rw-r--r--std/flags/README.md72
2 files changed, 72 insertions, 0 deletions
diff --git a/std b/std
deleted file mode 160000
-Subproject 43aafbf33285753e7b42230f0eb7969b300f71c
diff --git a/std/flags/README.md b/std/flags/README.md
new file mode 100644
index 000000000..41692b619
--- /dev/null
+++ b/std/flags/README.md
@@ -0,0 +1,72 @@
+# flags
+
+Command line arguments parser for Deno based on minimist
+
+# Example
+
+```ts
+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:
+ ```ts
+ 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`.