@types/dashdash
- Version 1.14.3
- Published
- 12.8 kB
- No dependencies
- MIT license
Install
npm i @types/dashdash
yarn add @types/dashdash
pnpm add @types/dashdash
Overview
TypeScript definitions for dashdash
Index
Functions
Classes
Interfaces
Type Aliases
Functions
function addOptionType
addOptionType: (optionType: OptionType) => void;
Add a new option type.
function bashCompletionFromOptions
bashCompletionFromOptions: (args: BashCompletionConfiguration) => string;
function bashCompletionSpecFromOptions
bashCompletionSpecFromOptions: (args: BashCompletionSpecConfiguration) => string;
function createParser
createParser: (config: ParserConfiguration) => Parser;
function getOptionType
getOptionType: (name: string) => OptionType;
function parse
parse: (config: ParsingConfiguration) => Results;
Parse argv with the given options.
Parameter config
A merge of all the available fields from
dashdash.Parser
anddashdash.Parser.parse
: options, interspersed, argv, env, slice.
function synopsisFromOpt
synopsisFromOpt: (o: Option) => string;
Return a synopsis string for the given option spec.
Examples: > synopsisFromOpt({names: ['help', 'h'], type: 'bool'}); '[ --help | -h ]' > synopsisFromOpt({name: 'file', type: 'string', helpArg: 'FILE'}); '[ --file=FILE ]'
Classes
class Parser
class Parser {}
constructor
constructor(config: ParserConfiguration);
property allowUnknown
allowUnknown: boolean;
Don't allow unknown flags. true
property interpersed
interpersed: boolean;
Allow interspersed arguments. true
method bashCompletion
bashCompletion: (args: BashCompletionConfiguration) => string;
Return a string suitable for a Bash completion file for this tool.
method help
help: (config?: HelpConfiguration) => string;
Return help output for the current options.
E.g.: if the current options are: [{names: ['help', 'h'], type: 'bool', help: 'Show help and exit.'}] then this would return: ' -h, --help Show help and exit.\n'
method parse
parse: (inputs?: string[] | ParsingConfiguration) => Results;
Parse options from the given argv.
Interfaces
interface Arg
interface Arg {}
interface BashCompletionConfiguration
interface BashCompletionConfiguration {}
property argtypes
argtypes?: string[] | undefined;
Array of completion types for positional args (i.e. non-options). If not given, positional args will use Bash's 'default' completion.
property name
name: string;
The tool name.
property options
options?: Array<Option | Group> | undefined;
The array of dashdash option specs.
property specExtra
specExtra?: string | undefined;
Extra Bash code content to add to the end of the "spec". Typically this is used to append Bash "complete_TYPE" functions for custom option types.
interface BashCompletionSpecConfiguration
interface BashCompletionSpecConfiguration {}
property argtypes
argtypes?: string[] | undefined;
Array of completion types for positional args (i.e. non-options). If not given, positional args will use Bash's 'default' completion.
property context
context?: string | undefined;
A context string for the "local cmd*" vars in the spec. By default it is the empty string. When used to scope for completion on a *sub-command*.
property includeHidden
includeHidden?: boolean | undefined;
By default hidden options and subcmds are "excluded". Here excluded means they won't be offered as a completion, but if used, their argument type will be completed. "Hidden" options and subcmds are ones with the
hidden: true
attribute to exclude them from default help output.
property options
options: Array<Option | Group>;
The array of dashdash option specs.
interface HelpConfiguration
interface HelpConfiguration {}
property headingIndent
headingIndent?: number | string | undefined;
Set to a number (for that many spaces) or a string for the literal indent. This indent applies to group heading lines, between normal option lines. Default: half length of
indent
property helpCol
helpCol?: number | undefined;
If not set a reasonable value will be determined between minHelpCol and maxHelpCol.
property helpWrap
helpWrap?: boolean | undefined;
Set to
false
to have optionhelp
strings not be textwrapped to the helpCol..maxCol range. Default: true
property includeDefault
includeDefault?: boolean | undefined;
If the option has a default value (via the default option spec attribute, or a default on the option's type), then a "Default: VALUE" string will be appended to the help string. Default: false
property includeEnv
includeEnv?: boolean | undefined;
If the option has associated environment variables (via the env option spec attribute), then append mentioned of those envvars to the help string. Default: false
property indent
indent?: number | string | undefined;
Set to a number (for that many spaces) or a string for the literal indent. Default: 4
property maxCol
maxCol?: number | undefined;
Note that reflow is just done on whitespace so a long token in the option help can overflow maxCol. Default: 80
property maxHelpCol
maxHelpCol?: number | undefined;
Default: 40
property minHelpCol
minHelpCol?: number | undefined;
Default: 20
property nameSort
nameSort?: string | undefined;
By default the names are sorted to put the short opts first (i.e. '-h, --help' preferred to '--help, -h'). Set to 'none' to not do this sorting. Default: 'length'
interface OptionBase
interface OptionBase {}
property completionType
completionType?: string | undefined;
This is used for Bash completion for an option argument. If not specified, then the value of type is used. Any string may be specified, but only the following values have meaning: - none: Provide no completions. - file: Bash's default completion (i.e. complete -o default), which includes filenames. - Any string FOO for which a function complete_FOO Bash function is defined. This is for custom completions for a given tool. Typically these custom functions are provided in the specExtra argument to dashdash.bashCompletionFromOptions().
property default
default?: string | undefined;
A default value used for this option, if the option isn't specified in argv.
property env
env?: string | string[] | undefined;
An environment variable name (or names) that can be used as a fallback for this option. An environment variable is only used as a fallback, i.e. it is ignored if the associated option is given in
argv
.
property help
help?: string | undefined;
Used for parser.help() output.
property helpArg
helpArg?: string | undefined;
Used in help output as the placeholder for the option argument.
property helpWrap
helpWrap?: boolean | undefined;
Set this to false to have that option's help not be text wrapped in .help() output.
property hidden
hidden?: boolean | undefined;
If true, help output will not include this option.
property type
type: string;
One of: bool, string, number, integer, positiveInteger, arrayOfBool, arrayOfString, arrayOfNumber, arrayOfInteger, arrayOfPositiveInteger, arrayOfDate, date (epoch seconds, e.g. 1396031701, or ISO 8601 format YYYY-MM-DD[THH:MM:SS[.sss][Z]], e.g. "2014-03-28T18:35:01.489Z"). You can add your own custom option types with
dashdash.addOptionType
These names attempt to match with asserts onassert-plus
.
interface OptionType
interface OptionType {}
property array
array?: boolean | undefined;
Set to true if this is an 'arrayOf' type that collects multiple usages of the option in process.argv and puts results in an array.
property arrayFlatten
arrayFlatten?: boolean | undefined;
property completionType
completionType?: any;
property default
default?: any;
Default value for options of this type, if no default is specified in the option type usage.
property helpArg
helpArg?: string | undefined;
Required iff
takesArg === true
. The string to show in generated help for options of this type.
property name
name: string;
property takesArg
takesArg: boolean;
Whether this type of option takes an argument on process.argv. Typically this is true for all but the "bool" type.
method parseArg
parseArg: (option: Option, optstr: string, arg: string) => any;
parser that takes a string argument and returns an instance of the appropriate type, or throws an error if the arg is invalid.
interface OptionWithAliases
interface OptionWithAliases extends OptionBase {}
property names
names: string[];
The option name and aliases. The first name (if more than one given) is the key for the parsed
opts
object.
interface OptionWithoutAliases
interface OptionWithoutAliases extends OptionBase {}
property name
name: string;
The option name
interface ParserConfiguration
interface ParserConfiguration {}
property allowUnknown
allowUnknown?: boolean | undefined;
Whether to throw on unknown options. If false, then unknown args are included in the _args array. Default: false
property interspersed
interspersed?: boolean | undefined;
Whether to allow interspersed arguments (non-options) and options.
E.g.: node tool.js arg1 arg2 -v
'-v' is after some args here. If
interspersed: false
then '-v' would not be parsed out. Note that regardless ofinterspersed
the presence of '--' will stop option parsing, as all good option parsers should.Default: true
property options
options: Array<Option | Group>;
Array of option specs.
interface ParsingConfiguration
interface ParsingConfiguration {}
property argv
argv?: string[] | undefined;
The argv to parse. Defaults to
process.argv
.
property env
env?: any;
The env to use for 'env' entries in the option specs. Defaults to
process.env
.
property options
options?: Array<Option | Group> | undefined;
property slice
slice?: number | undefined;
The index into argv at which options/args begin. Default is 2, as appropriate for
process.argv
.
interface Results
interface Results {}
index signature
[key: string]: any;
Type Aliases
type Option
type Option = OptionWithoutAliases | OptionWithAliases;
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/dashdash
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/dashdash)
- HTML<a href="https://www.jsdocs.io/package/@types/dashdash"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4568 ms. - Missing or incorrect documentation? Open an issue for this package.