本文整理汇总了TypeScript中yargs.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: default_hash
function default_hash() {
let argv = yargs
.default({ x: 10, y: 10 })
.argv
;
console.log(argv.x + argv.y);
}
示例2: randomValue
function Argv$default() {
let ya = yargs
.default('random', function randomValue() {
return Math.random() * 256;
})
.argv;
}
示例3: default_singles
// EVEN MORE SHIVER ME TIMBERS!
function default_singles() {
let argv = yargs
.default('x', 10)
.default('y', 10)
.argv
;
console.log(argv.x + argv.y);
}
示例4: getFlags
export function getFlags(manualArgv?: string) {
const y = manualArgv ? yargs(manualArgv) : yargs;
return y.help('help')
.version(() => pkg.version)
.showHelpOnFail(false, 'Specify --help for available options')
.usage('lighthouse <url>')
.example(
'lighthouse <url> --view', 'Opens the HTML report in a browser after the run completes')
.example(
'lighthouse <url> --config-path=./myconfig.js',
'Runs Lighthouse with your own configuration: custom audits, report generation, etc.')
.example(
'lighthouse <url> --output=json --output-path=./report.json --save-assets',
'Save trace, screenshots, and named JSON report.')
.example(
'lighthouse <url> --disable-device-emulation --disable-network-throttling',
'Disable device emulation')
.example(
'lighthouse <url> --chrome-flags="--window-size=412,732"',
'Launch Chrome with a specific window size')
.example(
'lighthouse <url> --quiet --chrome-flags="--headless"',
'Launch Headless Chrome, turn off logging')
// List of options
.group(['verbose', 'quiet'], 'Logging:')
.describe({
verbose: 'Displays verbose logging',
quiet: 'Displays no progress, debug logs or errors'
})
.group(
[
'save-assets', 'save-artifacts', 'list-all-audits', 'list-trace-categories',
'additional-trace-categories', 'config-path', 'chrome-flags', 'perf', 'port',
'hostname', 'max-wait-for-load'
],
'Configuration:')
.describe({
'blocked-url-patterns': 'Block any network requests to the specified URL patterns',
'disable-storage-reset':
'Disable clearing the browser cache and other storage APIs before a run',
'disable-device-emulation': 'Disable Nexus 5X emulation',
'disable-cpu-throttling': 'Disable CPU throttling',
'disable-network-throttling': 'Disable network throttling',
'save-assets': 'Save the trace contents & screenshots to disk',
'save-artifacts': 'Save all gathered artifacts to disk',
'list-all-audits': 'Prints a list of all available audits and exits',
'list-trace-categories': 'Prints a list of all required trace categories and exits',
'additional-trace-categories':
'Additional categories to capture with the trace (comma-delimited).',
'config-path': 'The path to the config JSON.',
'chrome-flags':
`Custom flags to pass to Chrome (space-delimited). For a full list of flags, see http://peter.sh/experiments/chromium-command-line-switches/.
Environment variables:
CHROME_PATH: Explicit path of intended Chrome binary. If set must point to an executable of a build of Chromium version 54.0 or later. By default, any detected Chrome Canary or Chrome (stable) will be launched.
`,
'perf': 'Use a performance-test-only configuration',
'hostname': 'The hostname to use for the debugging protocol.',
'port': 'The port to use for the debugging protocol. Use 0 for a random port',
'max-wait-for-load':
'The timeout (in milliseconds) to wait before the page is considered done loading and the run should continue. WARNING: Very high values can lead to large traces and instability',
'interactive': 'Open Lighthouse in interactive mode'
})
.group(['output', 'output-path', 'view'], 'Output:')
.describe({
'output': `Reporter for the results, supports multiple values`,
'output-path': `The file path to output the results. Use 'stdout' to write to stdout.
If using JSON output, default is stdout.
If using HTML output, default is a file in the working directory with a name based on the test URL and date.
If using multiple outputs, --output-path is ignored.
Example: --output-path=./lighthouse-results.html`,
'view': 'Open HTML report in your browser'
})
// boolean values
.boolean([
'disable-storage-reset', 'disable-device-emulation', 'disable-cpu-throttling',
'disable-network-throttling', 'save-assets', 'save-artifacts', 'list-all-audits',
'list-trace-categories', 'perf', 'view', 'verbose', 'quiet', 'help', 'interactive'
])
.choices('output', GetValidOutputOptions())
// force as an array
.array('blocked-url-patterns')
// default values
.default('chrome-flags', '')
.default('disable-cpu-throttling', false)
.default('output', GetValidOutputOptions()[OutputMode.domhtml])
.default('port', 0)
.default('hostname', 'localhost')
.default('max-wait-for-load', Driver.MAX_WAIT_FOR_FULLY_LOADED)
.check((argv: {listAllAudits?: boolean, listTraceCategories?: boolean, _: Array<any>}) => {
// Make sure lighthouse has been passed a url, or at least one of --list-all-audits
// or --list-trace-categories. If not, stop the program and ask for a url
if (!argv.listAllAudits && !argv.listTraceCategories && argv._.length === 0) {
//.........这里部分代码省略.........
示例5: setUpCli
export default function setUpCli(args?: string[], log = logResult) {
// can't call argv before done setting up
const verbose = !!args.find(arg => arg === '-v' || arg === '--verbose');
const plugins = getArgs(args, ['--plugins', '-p']);
const types = getArgs(args, ['--types', '-t']);
loadConfiguration(plugins, types, verbose);
const yargsConfig = yargs(args)
.scriptName('jimp')
.wrap(yargs.terminalWidth())
.option('plugins', {
alias: 'p',
type: 'array',
describe: 'Jimp plugins to load.'
})
.option('types', {
alias: 't',
type: 'array',
describe: 'Jimp types to load.'
})
.option('verbose', {
alias: 'v',
type: 'boolean',
describe: 'enable more logging'
})
.option('loadFont', {
alias: 'f',
type: 'string',
describe: 'Path of font to load and be used in text operations'
})
.group(['plugins', 'types', 'loadFont'], 'Jimp Configuration:')
.example(
'$0 read path/to/image.png --output output.jpg',
'Convert images from one type to another. See more under jimp read --help'
)
.alias('font', 'loadFont')
.demandCommand(1, 'You need at least one command before moving on')
.command({
command: 'read [img]',
describe: 'Read and image into jimp. (PNG, JPEG, TIFF, BMP, or GIF)',
builder: yargs =>
yargs
.group(['output', 'actions'], 'Jimp Configuration:')
.option('output', {
alias: 'o',
describe: 'file to output from jimp. (PNG, JPEG, TIFF, or BMP)'
})
.option('actions', {
alias: 'a',
type: 'array',
describe: `actions (image manipulation) to run on the input image. Loaded functions ${Object.keys(
Jimp.prototype
)
.sort()
.join(', ')}`
})
.example(
'$0 read path/to/image.png -a greyscale -a resize 150 -1 --output output.jpg',
'Apply image manipulations functions'
)
.example(
'$0 read path/to/image.png --loadFont FONT_SANS_8_WHITE -a yarnprint 0 0 "Some text" --output output.jpg',
'Use fonts'
)
.example(
'$0 read path/to/image.png --plugins @jimp/plugin-circle -a circle --output output.jpg',
'Use plugins'
)
.example(
'$0 read path/to/image.png -a blit /path/to/image.png 0 0 --output output.jpg',
'Use blit composite or mask'
)
})
.command({
command: 'create',
describe: 'Create a new image',
builder: yargs =>
yargs
.group(['width', 'height', 'background'], 'New Image Configuration:')
.group(['output', 'actions'], 'Jimp Configuration:')
.demandOption(
['width', 'height'],
'Please provide both height and width to create new image'
)
.option('width', {
alias: 'w',
type: 'number',
describe: 'Width of new image'
})
.option('height', {
alias: 'he',
type: 'number',
describe: 'Height of new image'
})
.option('background', {
alias: 'b',
describe: 'Background color - either hex value or css string'
})
.option('output', {
//.........这里部分代码省略.........
示例6: yargs
import yargs from "yargs";
import {
create,
} from "./index";
const argv = yargs(process.argv.slice(2))
.usage("Usage: $0 [options]")
.example("webpack-browser-sync", "")
.options({
config: {
description: "path to webpack.config",
alias: "c",
default: "./webpack.config.js",
required: true,
},
webpack: {
description: "enable webpack",
type: "boolean",
default: true,
},
index: {
description: "index.html relative path from webpackConfig.output.path",
type: "string",
default: "index.html",
},
hot: {
description: "enable hot module replacement [need enabled webpack]",
示例7: getVersion
export const buildArgv = (maybeArgv?: Array<string>): Config.Argv => {
const version =
getVersion() +
(__dirname.includes(`packages${path.sep}jest-cli`) ? '-dev' : '');
const rawArgv: Config.Argv | Array<string> =
maybeArgv || process.argv.slice(2);
const argv: Config.Argv = yargs(rawArgv)
.usage(args.usage)
.version(version)
.alias('help', 'h')
.options(args.options)
.epilogue(args.docs)
.check(args.check).argv;
validateCLIOptions(
argv,
{...args.options, deprecationEntries},
// strip leading dashes
Array.isArray(rawArgv)
? rawArgv.map(rawArgv => rawArgv.replace(/^--?/, ''))
: Object.keys(rawArgv),
);
// strip dashed args
return Object.keys(argv).reduce(
(result, key) => {
if (!key.includes('-')) {
result[key] = argv[key];
}
return result;
},
{} as Config.Argv,
);
};
示例8: parseChromeFlags
export function parseChromeFlags(flags: string) {
let args = yargs(flags).argv;
const allKeys = Object.keys(args);
// Remove unneeded arguments (yargs includes a _ arg, $-prefixed args, and camelCase dupes)
return allKeys.filter(k => k !== '_' && !k.startsWith('$') && !/[A-Z]/.test(k))
.map(k => formatArg(k, args[k]));
}