本文整理匯總了TypeScript中command-line-args類的典型用法代碼示例。如果您正苦於以下問題:TypeScript command-line-args類的具體用法?TypeScript command-line-args怎麽用?TypeScript command-line-args使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了command-line-args類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: readCommandLineOptions
/** Reads options from command line, requires command-line-args */
function readCommandLineOptions() {
function resolveKeyValuePairs(kvs: string[]) {
var o: any = {};
for (var i=0; i<kvs.length; i++) {
var kv = kvs[i].split("=");
o[kv[0]] = kv[1] || true;
}
return o;
}
var opts = commandLineArgs(optionDefinitions);
// Latest version of command-line-args doesn't set empty flags to true but null
for (var k in opts) {
if (opts[k] === null)
opts[k] = true;
}
if (opts.help) {
fableLib.stdoutLog(commandLineUsage(getAppDescription()));
fableLib.finish(0);
}
if (opts.refs) {
opts.refs = resolveKeyValuePairs(opts.refs);
}
if (opts.coreLib) {
opts.refs = Object.assign(opts.refs || {}, { "Fable.Core": opts.coreLib })
delete opts.coreLib;
}
if (opts.extra) {
opts.extra = resolveKeyValuePairs(opts.extra);
}
return opts;
}
示例2: run
'use strict';
import {polylint} from './polylint';
import * as jsconf_policy from './jsconf-policy';
import * as cliArgs from "command-line-args";
import * as fs from 'fs';
import * as path from 'path';
import * as logging from 'plylog'
import pathIsAbsolute = require('path-is-absolute');
//Trying to import this the TS leads to some really strange errors
var colors = require('colors/safe');
var argumentDefinitions = require('./args').argumentDefinitions;
var logger = logging.getLogger('lint.cli');
const cli = cliArgs(argumentDefinitions);
var usage = cli.getUsage({
header: "polylint checks Polymer apps for problematic code patterns",
title: "polylint"
});
export function run(env, args, stdout) {
return new Promise(function(resolve, reject) {
var cliOptions;
try {
cliOptions = cli.parse();
} catch (e) {
console.log(usage);
resolve();
return;
示例3: startServer
return new Promise<void>((resolve, reject) => {
let argsWithHelp : ArgDescriptor[] = args.concat({
name: 'help',
description: 'Shows this help message',
type: Boolean,
});
var cli = commandLineArgs(argsWithHelp);
try {
var cliOptions = cli.parse();
}
catch (e) {
printUsage(cli);
reject();
return;
}
var options: ServerOptions = {
port: cliOptions.port,
hostname: cliOptions.hostname,
open: cliOptions.open,
browser: cliOptions.browser,
componentDir: cliOptions['component-dir'],
packageName: cliOptions['package-name'],
}
if (cliOptions.help) {
printUsage(cli);
reject();
resolve();
} else {
return startServer(options);
}
});
示例4: commandLineArgs
(async () => {
const options = commandLineArgs(cliDefs) as CliOpts;
const skipSourceUpdate = options['skip-source-update'];
let exitCode = 0;
await Promise.all([
updateFixture({
folder: 'polymer',
branch: '2.x',
repoUrl: 'https://github.com/Polymer/polymer.git',
skipSourceUpdate,
}),
updateFixture({
folder: 'paper-button',
branch: '2.x',
repoUrl: 'https://github.com/PolymerElements/paper-button.git',
skipSourceUpdate,
}),
updateFixture({
folder: 'iron-icon',
branch: '2.x',
repoUrl: 'https://github.com/PolymerElements/iron-icon.git',
skipSourceUpdate,
}),
].map((p) => p.catch((e) => {
// Exit with an error code if any fixture fails, but let them all finish.
console.error(e);
exitCode = 1;
})));
process.exit(exitCode);
})();
示例5: runWorkspaceCommand
export async function run() {
const options = commandLineArgs(optionDefinitions) as CliOptions;
if (options['help']) {
const getUsage = require('command-line-usage');
const usage = getUsage([
{
header: 'modulizer',
content: `Convert HTML Imports to JavaScript modules
If no GitHub repository names are given, modulizer converts the current
directory as a package. If repositories are provided, they are cloned into a
workspace directory as sibling folders as they would be in a Bower
installation.
`,
},
{
header: 'Options',
optionList: optionDefinitions,
}
]);
console.log(usage);
return;
}
if (options['version']) {
console.log(require('../../package.json').version);
return;
}
if (options['repo']) {
await runWorkspaceCommand(options);
return;
}
const importStyle = options['import-style'];
if (importStyle !== 'name' && importStyle !== 'path') {
throw new Error(
`import-style "${importStyle}" not supported. ` +
`Supported styles: "name", "path".`);
}
const packageType = options['package-type'];
if (packageType !== 'element' && packageType !== 'application') {
throw new Error(
`package-type "${packageType}" is not supported. ` +
`Supported types: "element", "application".`);
}
await runPackageCommand(options);
}
示例6: main
const optionDescriptors = [
{name: 'help', type: Boolean}, {name: 'version', type: Boolean},
{name: 'logToFile', type: String},
// these args are passed in by vscode by default, even though
// we don't care about them right now we don't want to fail
// if they're given.
{name: 'stdio'}, {name: 'clientProcessId', type: Number}
];
interface Options {
help?: boolean;
version?: boolean;
logToFile?: string;
}
const options = commandLineArgs(optionDescriptors, {}) as Options;
/**
* Implements the [language server protocol][1] v3.0 for Web Components and
* Polymer.
*
* Communicates over stdin/stdout.
*
* [1]: https://github.com/Microsoft/language-server-protocol
*/
async function main(options: Options) {
// This import *must* come before all others.
await import('./intercept-logs');
//
const {createConnection} = await import('vscode-languageserver');
示例7: parseInt
const cli = cliArgs([
{name: 'help', type: Boolean, alias: 'h', description: 'Print usage.'},
{
name: 'maxChanges',
type: (x: string) => {
if (!x) {
return 0;
}
if (/^[0-9]+$/.test(x)) {
return parseInt(x, 10);
}
throw new Error(`invalid max changes, expected an integer: ${x}`);
},
alias: 'c',
description: 'The maximum number of repos to push. Default: 0',
defaultValue: 0
},
{
name: 'repo',
type: (s) => {
if (!s) {
throw new Error('Value expected for --repo|-r flag');
}
const parts = s.split('/');
if (parts.length !== 2) {
throw new Error(`Given repo ${s} is not in form user/repo`);
}
return {user: parts[0], repo: parts[1]};
},
defaultValue: [],
multiple: true,
alias: 'r',
description:
'Explicit repos to process. Specifying explicit repos will disable running on the implicit set of repos for the user.'
},
{
name: 'pass',
multiple: true,
type: (passName) => {
if (passNames.indexOf(passName) < 0) {
throw new Error(`Unknown cleanup pass name "${passName}"`);
}
return passName;
},
defaultValue: [],
description:
`Cleanup passes to run. If this flag is used then only the given passes will run, and they will run even if they're disabled by default. Pass names: ${
passNames.join(', ')}`
},
{
name: 'branchToFix',
alias: 'b',
description:
`The branch to apply changes to. Repos without a branch of this name will be skipped.`,
type: String,
defaultValue: 'master'
},
{
name: 'noProgress',
description: `If true, does not display a progress bar while it works.`,
type: Boolean,
defaultValue: false
},
{
name: 'forceReview',
description:
`If true, all changes will go through review, even if tedium thinks they're safe and boring.`,
type: Boolean,
defaultValue: false
},
{
name: 'prBranchName',
description:
'When sending up a PR, push to this branch and then make a PR from it.',
type: String,
defaultValue: 'tedium-change'
},
{
name: 'prAssignee',
description:
'When sending up a PR, assign it to this person to review. If not given, the asignee will be inferred from the github token (i.e. it will be assigned to YOU!)',
type: String,
defaultValue: undefined,
}
]);
示例8: printHelp
'polymer-bundler --exclude "path/to/target/subpath/" --exclude "path/to/target/subpath2/" target.html'
},
{
desc:
'Inline scripts in \`target.html\` as well as HTML Imports. Exclude flags will apply to both Imports and Scripts.',
example: 'polymer-bundler --inline-scripts target.html'
},
{
desc: 'Route URLs starting with "myapp://" to folder "src/myapp".',
example: 'polymer-bundler --redirect="myapp://|src/myapp" target.html'
}
]
},
];
const options = commandLineArgs(optionDefinitions);
const projectRoot = resolvePath(ensureTrailingSlash(options.root || '.'));
const entrypoints: PackageRelativeUrl[] = options['in-file'];
function printHelp() {
console.log(commandLineUsage(usage));
}
const pkg = require('../../package.json');
function printVersion() {
console.log('polymer-bundler:', pkg.version);
}
if (options.version) {
printVersion();
示例9: args
alias: "h",
description: "Display this usage guide.",
name: "help",
type: Boolean,
},
{
alias: "c",
defaultValue: "config.yaml",
description: "The AS config file.",
name: "config",
type: String,
typeLabel: "<config.yaml>",
},
];
const options = args(optionDefinitions);
if (options.help) {
/* tslint:disable:no-console */
console.log(usage([
{
content: "A tool to fix channels of rooms already bridged " +
"to matrix, to make sure their names, icons etc. are correctly.",
header: "Fix bridged channels",
},
{
header: "Options",
optionList: optionDefinitions,
},
]));
process.exit(0);
示例10: parseInt
const cli = cliArgs([
{name: "help", type: Boolean, alias: "h", description: "Print usage."},
{
name: "max_changes",
type: (x: string) => {
if (!x) {
return 0;
}
if (/^[0-9]+$/.test(x)) {
return parseInt(x, 10);
}
throw new Error(`invalid max changes, expected an integer: ${x}`);
},
alias: "c",
description: "The maximum number of repos to push. Default: 0",
defaultValue: 0
},
{
name: 'repo',
type: (s) => {
if (!s) {
throw new Error('Value expected for --repo|-r flag');
}
let parts = s.split('/');
if (parts.length !== 2) {
throw new Error(`Given repo ${s} is not in form user/repo`);
}
return {user: parts[0], repo: parts[1]};
},
defaultValue: [],
multiple: true,
alias: 'r',
description:
'Explicit repos to process. Specifying explicit repos will disable running on the implicit set of repos for the user.'
},
{
name: 'pass',
multiple: true,
type: (passName) => {
if (passNames.indexOf(passName) < 0) {
throw new Error(`Unknown cleanup pass name "${passName}"`);
}
return passName;
},
defaultValue: [],
description: `Cleanup passes to run. If this flag is used then only the given passes will run, and they will run even if they're disabled by default. Pass names: ${passNames.join(', ')}`
}
]);