From 4b0e59abeb1a23dc53533995efa2f651476131d5 Mon Sep 17 00:00:00 2001 From: Marek Date: Tue, 4 Jul 2017 09:35:25 +0200 Subject: [PATCH] command-line-args, command-line-commands --- .../command-line-args-tests.ts | 10 +++ types/command-line-args/index.d.ts | 71 +++++++++++++++++++ types/command-line-args/tsconfig.json | 22 ++++++ .../command-line-commands-tests.ts | 7 ++ types/command-line-commands/index.d.ts | 17 +++++ types/command-line-commands/tsconfig.json | 22 ++++++ 6 files changed, 149 insertions(+) create mode 100644 types/command-line-args/command-line-args-tests.ts create mode 100644 types/command-line-args/index.d.ts create mode 100644 types/command-line-args/tsconfig.json create mode 100644 types/command-line-commands/command-line-commands-tests.ts create mode 100644 types/command-line-commands/index.d.ts create mode 100644 types/command-line-commands/tsconfig.json diff --git a/types/command-line-args/command-line-args-tests.ts b/types/command-line-args/command-line-args-tests.ts new file mode 100644 index 0000000000..11848ee202 --- /dev/null +++ b/types/command-line-args/command-line-args-tests.ts @@ -0,0 +1,10 @@ +import commandLineArgs = require('command-line-args'); + +const optionDefinitions = [ + { name: 'verbose', alias: 'v', type: Boolean }, + { name: 'src', type: String, multiple: true, defaultOption: true }, + { name: 'timeout', alias: 't', type: Number } +]; + +const options = commandLineArgs(optionDefinitions); + diff --git a/types/command-line-args/index.d.ts b/types/command-line-args/index.d.ts new file mode 100644 index 0000000000..b975c9c1f2 --- /dev/null +++ b/types/command-line-args/index.d.ts @@ -0,0 +1,71 @@ +// Type definitions for command-line-args 4.0.6 +// Project: https://github.com/75lb/command-line-args +// Definitions by: CzBuCHi +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface OptionDefinition { + /** + * The only required definition property is name, the value of each option will be either a Boolean or string. + */ + name: string, + /** + * The type value is a setter function (you receive the output from this), enabling you to be specific about the type and value received. + */ + type?: (arg: string) => any, + /** + * getopt-style short option names. Can be any single character (unicode included) except a digit or hypen. + */ + alias?: string, + /** + * Set this flag if the option takes a list of values. You will receive an array of values, each passed through the type function (if specified). + */ + multiple?: boolean, + /** + * Any unclaimed command-line args will be set on this option. This flag is typically set on the most commonly-used option to make for more concise usage (i.e. $ myapp *.js instead of $ myapp --files *.js). + */ + defaultOption?: boolean, + /** + * An initial value for the option. + */ + defaultValue?: any, + /** + * When your app has a large amount of options it makes sense to organise them in groups. + * There are two automatic groups: _all (contains all options) and _none (contains options without a group specified in their definition). + */ + group?: string | string[], +} + +interface Options { + /** + * An array of strings, which if passed will be parsed instead of `process.argv`. + */ + argv?: string[]; + /** + * If `true`, an array of unknown arguments is returned in the `_unknown` property of the output. + */ + partial?: boolean; +} + +/** + * Returns an object containing all options set on the command line. By default it parses the global [`process.argv`](https://nodejs.org/api/process.html#process_process_argv) array. + * + * By default, an exception is thrown if the user sets an unknown option (one without a valid [definition](#exp_module_definition--OptionDefinition)). To enable __partial parsing__, invoke `commandLineArgs` with the `partial` option - all unknown arguments will be returned in the `_unknown` property. + * + * + * @param {module:definition[]} - An array of [OptionDefinition](#exp_module_definition--OptionDefinition) objects + * @param [options] {object} - Options. + * @param [options.argv] {string[]} - An array of strings, which if passed will be parsed instead of `process.argv`. + * @param [options.partial] {boolean} - If `true`, an array of unknown arguments is returned in the `_unknown` property of the output. + * @returns {object} + * @throws `UNKNOWN_OPTION` if `options.partial` is false and the user set an undefined option + * @throws `NAME_MISSING` if an option definition is missing the required `name` property + * @throws `INVALID_TYPE` if an option definition has a `type` value that's not a function + * @throws `INVALID_ALIAS` if an alias is numeric, a hyphen or a length other than 1 + * @throws `DUPLICATE_NAME` if an option definition name was used more than once + * @throws `DUPLICATE_ALIAS` if an option definition alias was used more than once + * @throws `DUPLICATE_DEFAULT_OPTION` if more than one option definition has `defaultOption: true` + * @alias module:command-line-args + */ +declare function commandLineArgs(optionDefinitions: OptionDefinition[], options?: Options): any; + +export = commandLineArgs; diff --git a/types/command-line-args/tsconfig.json b/types/command-line-args/tsconfig.json new file mode 100644 index 0000000000..2f22f95af1 --- /dev/null +++ b/types/command-line-args/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "command-line-args-tests.ts" + ] +} \ No newline at end of file diff --git a/types/command-line-commands/command-line-commands-tests.ts b/types/command-line-commands/command-line-commands-tests.ts new file mode 100644 index 0000000000..5ba96986d7 --- /dev/null +++ b/types/command-line-commands/command-line-commands-tests.ts @@ -0,0 +1,7 @@ +import commandLineCommands = require('command-line-commands'); + +const commands = [null, 'first', 'second']; + +const { command, argv } = commandLineCommands(commands, ['first', '--arg']); + + diff --git a/types/command-line-commands/index.d.ts b/types/command-line-commands/index.d.ts new file mode 100644 index 0000000000..ea8d66a8ea --- /dev/null +++ b/types/command-line-commands/index.d.ts @@ -0,0 +1,17 @@ +// Type definitions for command-line-commands 2.0.0 +// Project: https://github.com/75lb/command-line-commands +// Definitions by: CzBuCHi +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * Parses the `argv` value supplied (or `process.argv` by default), extracting and returning the `command` and remainder of `argv`. The command will be the first value in the `argv` array unless it is an option (e.g. `--help`). + * + * @param {string|string[]} - One or more command strings, one of which the user must supply. Include `null` to represent "no command" (effectively making a command optional). + * @param [argv] {string[]} - An argv array, defaults to the global `process.argv` if not supplied. + * @returns {{ command: string, argv: string[] }} + * @throws `INVALID_COMMAND` - user supplied a command not specified in `commands`. + */ +declare function commandLineCommands(commands: (string | null)[], argv: string[]): { command: string | null, argv: string[] }; + +export = commandLineCommands; + diff --git a/types/command-line-commands/tsconfig.json b/types/command-line-commands/tsconfig.json new file mode 100644 index 0000000000..5d98c64e58 --- /dev/null +++ b/types/command-line-commands/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "command-line-commands-tests.ts" + ] +} \ No newline at end of file