mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 23:10:29 +00:00
Updated types for command-line-args v5.0.2 (#24873)
* Updated types for command-line-args v5.0.2 * command-line-args: create v4 sub-folder for previous major version * Re-able lint rules. Fix lint issues.
This commit is contained in:
committed by
Ryan Cavanaugh
parent
568b33e4c6
commit
89c307ca87
@@ -1,10 +1,24 @@
|
||||
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 optionDefinitions: commandLineArgs.OptionDefinition[] = [
|
||||
{
|
||||
name: 'something',
|
||||
alias: 's',
|
||||
type: String,
|
||||
defaultValue: '1',
|
||||
multiple: true,
|
||||
lazyMultiple: true,
|
||||
defaultOption: true,
|
||||
group: 'one'
|
||||
}
|
||||
];
|
||||
|
||||
const options = commandLineArgs(optionDefinitions);
|
||||
const options = commandLineArgs(optionDefinitions, {
|
||||
argv: [ '--one', '1' ],
|
||||
partial: true,
|
||||
stopAtFirstUnknown: true,
|
||||
camelCase: true
|
||||
});
|
||||
|
||||
const unknown = options._unknown;
|
||||
const something = options.something;
|
||||
|
||||
Vendored
+79
-76
@@ -1,87 +1,90 @@
|
||||
// Type definitions for command-line-args 4.0.7
|
||||
// Type definitions for command-line-args 5.0
|
||||
// Project: https://github.com/75lb/command-line-args
|
||||
// Definitions by: CzBuCHi <https://github.com/CzBuCHi>
|
||||
// Definitions by: Lloyd Brookes <https://github.com/75lb>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Returns an object containing option values parsed from the command line. By default it parses the global `process.argv` array.
|
||||
* Parsing is strict by default. To be more permissive, enable `partial` or `stopAtFirstUnknown` modes.
|
||||
*/
|
||||
declare function commandLineArgs(optionDefinitions: commandLineArgs.OptionDefinition[], options?: commandLineArgs.Options): any;
|
||||
declare function commandLineArgs(optionDefinitions: commandLineArgs.OptionDefinition[], options?: commandLineArgs.ParseOptions): commandLineArgs.CommandLineOptions;
|
||||
|
||||
declare module commandLineArgs {
|
||||
declare namespace commandLineArgs {
|
||||
interface CommandLineOptions {
|
||||
/**
|
||||
* Command-line arguments not parsed by `commandLineArgs`.
|
||||
*/
|
||||
_unknown?: string[];
|
||||
[propName: string]: any;
|
||||
}
|
||||
|
||||
export 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[],
|
||||
/**
|
||||
* Describes the option.
|
||||
*/
|
||||
description?: string,
|
||||
/**
|
||||
* A label for the type, e.g. <ms>.
|
||||
*/
|
||||
typeLabel?: string;
|
||||
}
|
||||
interface ParseOptions {
|
||||
/**
|
||||
* An array of strings which if present will be parsed instead of `process.argv`.
|
||||
*/
|
||||
argv?: string[];
|
||||
|
||||
export 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;
|
||||
}
|
||||
/**
|
||||
* If `true`, `commandLineArgs` will not throw on unknown options or values, instead returning them in the `_unknown` property of the output.
|
||||
*/
|
||||
partial?: boolean;
|
||||
|
||||
/**
|
||||
* If `true`, `commandLineArgs` will not throw on unknown options or values. Instead, parsing will stop at the first unknown argument
|
||||
* and the remaining arguments returned in the `_unknown` property of the output. If set, `partial: true` is implied.
|
||||
*/
|
||||
stopAtFirstUnknown?: boolean;
|
||||
|
||||
/**
|
||||
* If `true`, options with hypenated names (e.g. `move-to`) will be returned in camel-case (e.g. `moveTo`).
|
||||
*/
|
||||
camelCase?: boolean;
|
||||
}
|
||||
|
||||
interface OptionDefinition {
|
||||
/**
|
||||
* The long option name.
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* A setter function (you receive the output from this) enabling you to be specific about the type and value received. Typical values
|
||||
* are `String` (the default), `Number` and `Boolean` but you can use a custom function. If no option value was set you will receive `null`.
|
||||
*/
|
||||
type?: (input: string) => any;
|
||||
|
||||
/**
|
||||
* A getopt-style short option name. Can be any single character except a digit or hyphen.
|
||||
*/
|
||||
alias?: string;
|
||||
|
||||
/**
|
||||
* Set this flag if the option accepts multiple values. In the output, you will receive an array of values each passed through the `type` function.
|
||||
*/
|
||||
multiple?: boolean;
|
||||
|
||||
/**
|
||||
* Identical to `multiple` but with greedy parsing disabled.
|
||||
*/
|
||||
lazyMultiple?: boolean;
|
||||
|
||||
/**
|
||||
* Any values unaccounted for by an option definition will be set on the `defaultOption`. This flag is typically set
|
||||
* on the most commonly-used option to enable more concise usage.
|
||||
*/
|
||||
defaultOption?: boolean;
|
||||
|
||||
/**
|
||||
* An initial value for the option.
|
||||
*/
|
||||
defaultValue?: any;
|
||||
|
||||
/**
|
||||
* One or more group names the option belongs to.
|
||||
*/
|
||||
group?: string | string[];
|
||||
}
|
||||
}
|
||||
|
||||
export = commandLineArgs;
|
||||
|
||||
@@ -1,79 +1,5 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import commandLineArgs = require('command-line-args');
|
||||
|
||||
const optionDefinitions: commandLineArgs.OptionDefinition[] = [
|
||||
{
|
||||
name: 'something',
|
||||
alias: 's',
|
||||
type: String,
|
||||
defaultValue: '1',
|
||||
multiple: true,
|
||||
defaultOption: true,
|
||||
group: 'one'
|
||||
}
|
||||
];
|
||||
|
||||
const options = commandLineArgs(optionDefinitions, {
|
||||
argv: [ '--one', '1' ],
|
||||
partial: true
|
||||
});
|
||||
|
||||
const unknown = options._unknown;
|
||||
const something = options.something;
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
// Type definitions for command-line-args 4.0
|
||||
// Project: https://github.com/75lb/command-line-args
|
||||
// Definitions by: CzBuCHi <https://github.com/CzBuCHi>, Lloyd Brookes <https://github.com/75lb>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/**
|
||||
* Returns an object containing option values parsed from the command line. By default it parses the global `process.argv` array.
|
||||
*/
|
||||
declare function commandLineArgs(optionDefinitions: commandLineArgs.OptionDefinition[], options?: commandLineArgs.ParseOptions): commandLineArgs.CommandLineOptions;
|
||||
|
||||
declare namespace commandLineArgs {
|
||||
interface CommandLineOptions {
|
||||
/**
|
||||
* Command-line arguments not parsed by `commandLineArgs`.
|
||||
*/
|
||||
_unknown?: string[];
|
||||
[propName: string]: any;
|
||||
}
|
||||
|
||||
interface ParseOptions {
|
||||
/**
|
||||
* An array of strings which if present will be parsed instead of `process.argv`.
|
||||
*/
|
||||
argv?: string[];
|
||||
|
||||
/**
|
||||
* If `true`, `commandLineArgs` will not throw on unknown options or values, instead returning them in the `_unknown` property of the output.
|
||||
*/
|
||||
partial?: boolean;
|
||||
}
|
||||
|
||||
interface OptionDefinition {
|
||||
/**
|
||||
* The long option name.
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* A setter function (you receive the output from this) enabling you to be specific about the type and value received. Typical values
|
||||
* are `String` (the default), `Number` and `Boolean` but you can use a custom function. If no option value was set you will receive `null`.
|
||||
*/
|
||||
type?: (input: string) => any;
|
||||
|
||||
/**
|
||||
* A getopt-style short option name. Can be any single character except a digit or hyphen.
|
||||
*/
|
||||
alias?: string;
|
||||
|
||||
/**
|
||||
* Set this flag if the option accepts multiple values. In the output, you will receive an array of values each passed through the `type` function.
|
||||
*/
|
||||
multiple?: boolean;
|
||||
|
||||
/**
|
||||
* Any values unaccounted for by an option definition will be set on the `defaultOption`. This flag is typically set
|
||||
* on the most commonly-used option to enable more concise usage.
|
||||
*/
|
||||
defaultOption?: boolean;
|
||||
|
||||
/**
|
||||
* An initial value for the option.
|
||||
*/
|
||||
defaultValue?: any;
|
||||
|
||||
/**
|
||||
* One or more group names the option belongs to.
|
||||
*/
|
||||
group?: string | string[];
|
||||
}
|
||||
}
|
||||
|
||||
export = commandLineArgs;
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"command-line-args": [ "command-line-args/v4" ]
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"command-line-args-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user