From 700b4ce0d99dca02fe192c8722ab1bb7a33dc709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 19 Dec 2018 19:06:31 +0100 Subject: Add flags module (denoland/deno_std#32) Original: https://github.com/denoland/deno_std/commit/b15b0d20d722ad16ebba363c0e8e35bbbc869f20 --- flags/README.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 flags/README.md (limited to 'flags/README.md') diff --git a/flags/README.md b/flags/README.md new file mode 100644 index 000000000..baa9c19c4 --- /dev/null +++ b/flags/README.md @@ -0,0 +1,59 @@ +# flags + +Command line arguments parser for Deno based on minimist + +# Example + +``` ts +import { args } from "deno"; +import parseArgs from "https://deno.land/x/parseargs/index.ts"; + +console.dir(parseArgs(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 = parseArgs(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`. -- cgit v1.2.3