commander#Option TypeScript Examples
The following examples show how to use
commander#Option.
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: cli.ts From jmix-frontend with Apache License 2.0 | 6 votes |
export function createAndLaunchCli() {
const {program}: {program: Command} = require('commander');
// Add options that configure which generators to use
program
.addOption(new Option(
'--custom-generator-paths <paths...>',
'Use custom generators from the filesystem.'
))
.allowUnknownOption(true); // Otherwise program.parse below will fail when any other (command-specific) options are provided. We set allowUnknownOption back to false once we know the full list of options.
const {customGeneratorPaths} = program.parse().opts<CustomGeneratorConfig>();
const expandRelativePath = (p: string) => path.resolve(p);
const clients: GeneratedClientInfo[] = collectClients(undefined, {
customGeneratorPaths: customGeneratorPaths?.map(expandRelativePath),
});
const cli: Command = createCli(ownVersion, clients, undefined, undefined, program);
launchCli(cli);
}
Example #2
Source File: getCliOptions.ts From build-scripts with MIT License | 6 votes |
module.exports = (program: Command): IHash<JsonValue> => {
const cliOptions: IHash<JsonValue> = {};
program.options.forEach((option: Option): void => {
const key = camelcase(option.long, {
pascalCase: false,
});
// 不传参数时是 undefined,这里不判断的话,lib/build 里跟 default 参数 merge 会有问题
// version等参数的类型为function,需要过滤掉
if (program[key] !== undefined && typeof program[key] !== 'function') {
cliOptions[key] = program[key];
}
});
return cliOptions;
};
Example #3
Source File: tzgen.ts From nft-tutorial with MIT License | 6 votes |
//prettier-ignore
program
.command('spec')
.alias('s')
.description('generate specification file for contract generation')
.argument('<file>', 'resulting specification file')
.addOption(new Option('-k --kind <kind>', 'core FA2 implementation kind')
.makeOptionMandatory()
.choices(['NFT', 'FT', 'MFT']))
.addOption(new Option('-a --admin <admin>', 'type of the contract admin')
.makeOptionMandatory()
.choices(['NO_ADMIN', 'SIMPLE', 'PAUSABLE', 'MULTI']))
.addOption(new Option('-m --minter [minter...]', 'optional minter functionality')
.choices(['MINT', 'BURN', 'FREEZE']))
.addOption(new Option('-ma --minter_admin <minter_admin>', 'type of the minter admin implementation' )
.choices(['NO_MINTER', 'CONTRACT_ADMIN', 'MULTI'])
.default('NO_MINTER', 'NO_MINTER useful if not mint/burn functionality is specified')
)
.action((file, options) => createGenSpec(
file, options.kind, options.admin, options.minter, options.minter_admin
));
Example #4
Source File: change.ts From squid with GNU General Public License v3.0 | 6 votes |
async function main(): Promise<void> {
let command = new Command()
command.description('Create change file for a package')
command.requiredOption('-p, --package <dir>', 'package dir (must be relative to workspace root)')
command.addOption(
new Option('-t, --type <type>', 'type of change').choices([
'major',
'minor',
'patch',
'none'
]).makeOptionMandatory(true)
)
command.requiredOption('-m, --message <text>', 'change description')
command.parse()
let options: Options = command.opts()
let pkgJsonLoc = path.join(options.package, 'package.json')
let pkg = JSON.parse(fs.readFileSync(pkgJsonLoc, 'utf-8'))
let packageName = assertNotNull(pkg.name, `.name is not defined in ${pkgJsonLoc}`)
let dir = new OutDir('common/changes').child(packageName)
dir.write(createChangeFileName(), JSON.stringify({
changes: [
{
packageName,
type: options.type,
comment: options.message
}
],
packageName
}, null, 2))
}
Example #5
Source File: cli.ts From yarn-audit-fix with MIT License | 5 votes |
flags = new Command()
.addOption(
new Option(
'--audit-level [level]',
'Include only vulnerabilities with the specified level or higher',
)
.choices(['low', 'moderate', 'high', 'critical'])
.default(env.YAF_AUDIT_LEVEL),
)
.option('--cwd [path]', 'CWD. Defaults to `process.cwd()`', env.YAF_CWD)
.option(
'--dry-run [bool]',
'Get an idea of what audit fix will do',
env.YAF_DRY_RUN,
)
.addOption(
new Option('--flow [flow]', 'Define how `yarn.lock` is modified')
.choices(['convert', 'patch'])
.default(env.YAF_FLOW || 'patch'),
)
.option(
'--force [bool]',
'Have audit fix install semver-major updates to toplevel dependencies, not just semver-compatible ones',
env.YAF_FORCE,
)
.option(
'--ignore-engines [bool]',
'Ignore engines check',
env.YAF_IGNORE_ENGINES,
)
.option('--loglevel [level]', 'Set custom log level', env.YAF_LOGLEVEL)
.option(
'--legacy-peer-deps [bool]',
'Accept an incorrect (potentially broken) deps resolution',
env.YAF_LEGACY_PEER_DEPS,
)
.addOption(
new Option(
'--npm-path [path]',
"Switch to system default version of npm instead of package's own.",
)
.choices(['system', 'local'])
.default(env.YAF_NPM_PATH || 'system'),
)
.addOption(
new Option('--only [scope]', 'Set package updating scope')
.choices(['prod', 'dev'])
.default(env.YAF_ONLY),
)
.option(
'--package-lock-only [bool]',
'Run audit fix without modifying `node_modules`.',
env.YAF_PACKAGE_LOCK_ONLY,
)
.option('--registry [registry]', 'Custom registry url', env.YAF_REGISTRY)
.option('--silent [bool]', 'Disable log output', env.YAF_SILENT)
.addOption(
new Option(
'--symlink',
'Define symlink type for `node_modules` assets',
).choices(['junction', 'dir']),
)
.option('--temp [dir]', 'Directory for temporary assets')
.option(
'--verbose [bool]',
'Switch log level to verbose/debug',
env.YAF_VERBOSE,
)
.option(
'--version, -v',
'Print current yarn-audit-fix version'
)
.allowUnknownOption()
.parse(process.argv)
.opts()
Example #6
Source File: client.ts From eufy-security-ws with MIT License | 5 votes |
program
.addOption(new Option("-s, --schemaVersion <host>", "Schema version the server should support").default(maxSchemaVersion, "max client supported version"))
.addOption(new Option("-H, --host <host>", "Host to connect to").default("localhost"))
.addOption(new Option("-p, --port <port>", "Port to connect to").default(3000))
.addOption(new Option("-v, --verbose"));
Example #7
Source File: server.ts From eufy-security-ws with MIT License | 5 votes |
program
.addOption(new Option("-c, --config <file>", "Configuration file").default("config.json", "looks in current directory"))
.addOption(new Option("-p, --port <port>", "Listening port").default(3000))
.addOption(new Option("-H, --host <host>", "Listening Host").default("localhost"))
.addOption(new Option("-v, --verbose"))
.addOption(new Option("-q, --quiet"));
Example #8
Source File: cmd.ts From cross-seed with Apache License 2.0 | 5 votes |
createCommandWithSharedOptions("search", "Search for cross-seeds")
.requiredOption(
"-o, --offset <offset>",
"Offset to start from",
(n) => parseInt(n),
0
)
.requiredOption(
"-d, --delay <delay>",
"Pause duration (seconds) between searches",
parseFloat,
fallback(fileConfig.delay, 10)
)
.addOption(
new Option(
"--torrents <torrents...>",
"torrent files separated by spaces. This is a debug option and may be removed without warning."
).hideHelp()
)
.action(async (options) => {
try {
const runtimeConfig = processOptions(options);
setRuntimeConfig(runtimeConfig);
initializeLogger();
initializePushNotifier();
logger.verbose({
label: Label.CONFIGDUMP,
message: inspect(runtimeConfig),
});
if (process.env.DOCKER_ENV === "true") {
generateConfig({ docker: true });
}
await doStartupValidation();
await main();
} catch (e) {
if (e instanceof CrossSeedError) {
e.print();
process.exitCode = 1;
return;
}
throw e;
}
});
Example #9
Source File: cmd.ts From cross-seed with Apache License 2.0 | 4 votes |
function createCommandWithSharedOptions(name, description) {
return program
.command(name)
.description(description)
.option(
"-u, --jackett-server-url <url>",
"DEPRECATED: Your Jackett server url",
fileConfig.jackettServerUrl
)
.option(
"-k, --jackett-api-key <key>",
"DEPRECATED: Your Jackett API key",
fileConfig.jackettApiKey
)
.option(
"-t, --trackers <tracker1>,<tracker2>",
"DEPRECATED: Comma-separated list of Jackett tracker ids to search (Tracker ids can be found in their Torznab feed paths)",
fallback(fileConfig.trackers?.join(","), "")
)
.option(
"-T, --torznab <urls...>",
"Torznab urls with apikey included (separated by spaces)",
fallback(fileConfig.torznab)
)
.requiredOption(
"-i, --torrent-dir <dir>",
"Directory with torrent files",
fileConfig.torrentDir
)
.requiredOption(
"-s, --output-dir <dir>",
"Directory to save results in",
fileConfig.outputDir
)
.requiredOption(
"-a, --search-all",
"Search for all torrents regardless of their contents",
fallback(fileConfig.searchAll, false)
)
.option(
"-e, --include-episodes",
"Include single-episode torrents in the search",
fallback(fileConfig.includeEpisodes, false)
)
.requiredOption(
"--fuzzy-size-threshold <decimal>",
"The size difference allowed to be considered a match.",
fallback(fileConfig.fuzzySizeThreshold, 0.02)
)
.option(
"-x, --exclude-older <cutoff>",
"Exclude torrents first seen more than n minutes ago. Bypasses the -a flag.",
(n) => parseInt(n),
fileConfig.excludeOlder
)
.option(
"-r, --exclude-recent-search <cutoff>",
"Exclude torrents which have been searched more recently than n minutes ago. Bypasses the -a flag.",
(n) => parseInt(n),
fileConfig.excludeRecentSearch
)
.requiredOption("-v, --verbose", "Log verbose output", false)
.addOption(
new Option(
"-A, --action <action>",
"If set to 'inject', cross-seed will attempt to add the found torrents to your torrent client."
)
.default(fallback(fileConfig.action, Action.SAVE))
.choices(Object.values(Action))
.makeOptionMandatory()
)
.option(
"--rtorrent-rpc-url <url>",
"The url of your rtorrent XMLRPC interface. Requires '-A inject'. See the docs for more information.",
fileConfig.rtorrentRpcUrl
)
.option(
"--qbittorrent-url <url>",
"The url of your qBittorrent webui. Requires '-A inject'. See the docs for more information.",
fileConfig.qbittorrentUrl
)
.option(
"--notification-webhook-url <url>",
"cross-seed will send POST requests to this url with a JSON payload of { title, body }",
fileConfig.notificationWebhookUrl
);
}