yargs#options TypeScript Examples
The following examples show how to use
yargs#options.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Runner.ts From mpflow with MIT License | 6 votes |
/**
* 注册 CLI 命令
* @param command
* @param describe
* @param positional
* @param options
* @param handler
*/
registerCommand<
P extends Record<string, PositionalOptions> = Record<string, PositionalOptions>,
O extends Record<string, Options> = Record<string, Options>
>(
command: CommandModule['command'],
describe: CommandModule['describe'],
positional: P,
options: O,
handler: (args: Arguments<InferredOptionTypes<P> & InferredOptionTypes<O>>) => void,
): void {
this.service.registerCommand(command, describe, positional, options, handler)
}
Example #2
Source File: Runner.ts From mpflow with MIT License | 6 votes |
/**
* 注册 CLI 命令
* @param command
* @param describe
* @param positional
* @param options
* @param handler
*/
registerCommand<
P extends Record<string, PositionalOptions> = Record<string, PositionalOptions>,
O extends Record<string, Options> = Record<string, Options>
>(
command: CommandModule['command'],
describe: CommandModule['describe'],
positional: P,
options: O,
handler: (args: Arguments<InferredOptionTypes<P> & InferredOptionTypes<O>>) => void,
): void {
this._registerCommand(
command,
describe,
yargs => {
Object.keys(positional).forEach(key => (yargs = yargs.positional(key, positional[key])))
yargs = yargs.options(options)
return yargs
},
handler,
)
}
Example #3
Source File: gen-docs.ts From yaclt with Mozilla Public License 2.0 | 6 votes |
sortByHidden = (
option1: [string, Options],
option2: [string, Options]
): number => {
if (option1[1].hidden === option2[1].hidden) {
return 0;
}
if (option1[1].hidden) {
return 1;
}
if (option2[1].hidden) {
return -1;
}
return 0;
}
Example #4
Source File: validate.ts From yaclt with Mozilla Public License 2.0 | 6 votes |
ValidateCommandOptions: { [key: string]: Options } = {
validationPattern: {
describe:
"A regular expression used to validate each individual changelog entry",
type: "string",
default: "\\[.*\\]\\s+.*\\s{#[\\d]+}",
},
preValidate: {
describe:
"A hook function to run before performing validation. Throw an error or return false to halt execution. Only usable from a Javascript configuration file. May be async.",
demandOption: false,
hidden: true,
},
postValidate: {
describe:
"A hook function to run after performing validation. Only usable from a Javascript configuration file. May be async.",
demandOption: false,
hidden: true,
},
}
Example #5
Source File: validate-argv-middleware.ts From yaclt with Mozilla Public License 2.0 | 6 votes |
Commands.forEach((command: CommandModule) => {
const builderKeys = Object.keys(command.builder ?? {});
if (builderKeys.length === 0) {
return;
}
allValidOptions.push(...builderKeys);
for (const key of builderKeys) {
const alias = (command.builder as Record<string, Options> | undefined)?.[
key
]?.alias;
if (alias) {
if (Array.isArray(alias)) {
allValidOptions.push(...alias);
} else {
allValidOptions.push(alias as string);
}
}
}
});
Example #6
Source File: args.d.ts From amazon-kinesis-video-streams-webrtc-sdk-js-with-amazon-cognito with MIT No Attribution | 5 votes |
options: Record<'cache' | 'config' | 'debug' | 'version' | 'watchman', Options>
Example #7
Source File: args.d.ts From amazon-kinesis-video-streams-webrtc-sdk-js-with-amazon-cognito with MIT No Attribution | 5 votes |
options: Record<'cache' | 'config' | 'debug' | 'version' | 'watchman', Options>
Example #8
Source File: validateCLIOptions.d.ts From amazon-kinesis-video-streams-webrtc-sdk-js-with-amazon-cognito with MIT No Attribution | 5 votes |
export default function validateCLIOptions(argv: Config.Argv, options: {
deprecationEntries: DeprecatedOptions;
[s: string]: Options;
}, rawArgv?: Array<string>): boolean;
Example #9
Source File: validateCLIOptions.d.ts From amazon-kinesis-video-streams-webrtc-sdk-js-with-amazon-cognito with MIT No Attribution | 5 votes |
export default function validateCLIOptions(argv: Config.Argv, options: {
deprecationEntries: DeprecatedOptions;
[s: string]: Options;
}, rawArgv?: Array<string>): boolean;
Example #10
Source File: validateCLIOptions.d.ts From nlw2-proffy with MIT License | 5 votes |
export default function validateCLIOptions(argv: Config.Argv, options: {
deprecationEntries: DeprecatedOptions;
[s: string]: Options;
}, rawArgv?: Array<string>): boolean;
Example #11
Source File: gen-docs.ts From yaclt with Mozilla Public License 2.0 | 5 votes |
formatLongOption = (option: [string, Options]): string => {
if (option[1].hidden === true) {
return `JS: \`${option[0]}\``;
}
return `\`--${option[0]}\``;
}
Example #12
Source File: options.ts From yaclt with Mozilla Public License 2.0 | 5 votes |
CliOptions: { [key: string]: Options } = {
logsDir: {
type: "string",
normalize: true,
default: "changelogs/",
describe: "The directory to find and place individual changelog entries",
global: true,
},
branchFormat: {
type: "string",
describe:
"Regular expression with a capturing group to parse the issue ID out of your git branch. Implies --requireIssueIds and assumes that --format includes %issueid%",
global: true,
},
changelogFile: {
type: "string",
normalize: true,
default: "CHANGELOG.md",
describe: "The name of the global changelog file to collect entries into",
coerce: coerceFileArg(true),
global: true,
},
changeTypes: {
type: "array",
default: ["NEW", "IMPROVED", "FIXED"],
describe: "The allowed change type tags",
global: true,
},
requireIssueIds: {
type: "boolean",
default: true,
describe: "Require issue IDs in changelog entries",
global: true,
},
format: {
type: "string",
default: `[{{${StringFormatParams.changeType}}}] {{${StringFormatParams.message}}} {{echo "{"}}#{{${StringFormatParams.issueId}}}{{echo "}"}}\n`,
describe:
"Changelog entry format, as a Handlebars template. To make change type tags optional, simply don't include the Handlebars variable for it.",
global: true,
},
plumbing: {
alias: "p",
type: "boolean",
default: false,
describe:
"Reduce output to just the relevant data, e.g. filepaths for `new` and `prepare-release`, `true/false` for `validate`, for scripting purposes. Also disables opening `$EDITOR`. Passing this option will override `--quiet` or `--verbose`.",
global: true,
},
quiet: {
alias: "q",
type: "boolean",
default: false,
describe: "Silence all output.",
global: true,
},
verbose: {
alias: "v",
type: "boolean",
default: false,
describe: "Output additional command logs and information.",
global: true,
},
}
Example #13
Source File: index.ts From office-booker with MIT License | 5 votes |
args = options({
stack: { type: 'string', demandOption: true },
'first-run': { type: 'boolean', default: false },
'pre-check': { type: 'boolean', default: false },
}).argv