How to use the option function from yargs

Find comprehensive JavaScript yargs.option code examples handpicked from public code repositorys.

2
3
4
5
6
7
8
9
10
11
 * and it's a bit of a pain to look up the NIST standard and manually compute it
 * each time
 */
const yargs = require('yargs');

const options = yargs.option('l', {
  alias: 'message-length',
  describe: 'the length of the message to be padded in bits',
  type: 'number',
  demandOption: true,
fork icon159
star icon862
watch icon58

+ 13 other calls in file

63
64
65
66
67
68
69
70
71
72
.scriptName('jadmin')
.command({
  command: 'delete-user <userId>',
  describe: 'Hard delete a user and related records',
  builder: (yargs) => {
    yargs.option('force', {
      describe: 'Bypass interactive safety checks',
      type: 'boolean',
    })
    yargs.option('database-url', {
fork icon18
star icon45
watch icon7

+ 15 other calls in file

114
115
116
117
118
119
120
121
122
123
)
.command(
    'clear <user>',
    'Delete all tokens for a user',
    yargs =>
        yargs.option('user', {
            alias: 'u',
            describe: 'User to de-provision',
            demandOption: true
        }),
fork icon245
star icon3
watch icon1

+ 11 other calls in file

15
16
17
18
19
20
21
22
23
24
// add it below, and move src/index.html to src/common/index.html.
const APPS = ['public'];

// webpack v5 no longer passes command line flags so hooking into
// "name" flag instead of "app".
const argv = yargs.option('name', {
  array: true,
  alias: 'apps',
  default: APPS,
}).argv;
fork icon15
star icon196
watch icon9

210
211
212
213
214
215
216
217
218
219
/* Register command line arguments */
yargs.command('*', false, (yargs: any) => {
    common_args.add_universal_arguments(yargs);
    common_args.add_common_mqtt_arguments(yargs);
    common_args.add_direct_tls_connect_arguments(yargs);
    yargs.option('count', {
        description: '<number>: The number of messages to publish (optional, default=10)',
        type: 'int',
        required: false,
        default: 10
fork icon96
star icon170
watch icon21

+ 11 other calls in file

50
51
52
53
54
55
56
57
58
59
let vbotOpts = {verbose: true}
Object.keys(this.cmdOptions).forEach((opt) => {
  if(!this.cmdOptions[opt].show) {
    return;
  }
  yargs.option(opt, this.cmdOptions[opt])
});
yargs
.usage('vbot <-f> | vbot download <--client-key> <--scenario-id>')
.command('$0', 'run vbot test from local json file', (yargs) => {
fork icon10
star icon94
watch icon5

+ 3 other calls in file

84
85
86
87
88
89
90
91
92
93
        console.log(failures);
    })

})
.command('make:test [name]', 'Create a test', (yargs) => {
    yargs.option('for', {
      describe: 'Create a testcase for a specific framework. The default is a framework agnostic TestCase',
      default: 'default',
      choices: ['default', 'vue']
    })
fork icon2
star icon15
watch icon2

+ 3 other calls in file

4
5
6
7
8
9
10
11
12
13
const yargs = require('yargs');
const execSync = require('./exec-sync');
const { findGitRoot } = require('./monorepo/index');
const chalk = require('chalk');

const options = yargs.option('webpackConfig', { alias: 'w', type: 'string' }).argv;

const webpackConfigFilePath = options.webpackConfig || 'webpack.codepen.config.js';

const configPath = path.resolve(process.cwd(), webpackConfigFilePath);
fork icon0
star icon1
watch icon0

115
116
117
118
119
120
121
122
123
124
    }
  })

Object.keys(spec.properties).forEach(propertyKey => {
  const property = spec.properties[propertyKey]
  yargs.option(propertyKey, {
    type: property.type,
    describe: property.description,
    default: property.default,
    group: 'Preset Configuration:'
fork icon808
star icon0
watch icon1

0
1
2
3
4
5
6
7
8
9
const express = require('express')
const bodyParser = require('body-parser')
const { join } = require('path')
const app = express()
const yargs = require('yargs')
const argv = yargs.option('port', {
    alias: 'p',
    description: 'Set the port to run this server on',
    type: 'number',
}).help().alias('help', 'h').argv
fork icon155
star icon201
watch icon12

6
7
8
9
10
11
12
13
14
const fileNameLatest = `openapi-cli.latest.tar.gz`;

execSync(`tar -zcvf ${fileName} dist`);
execSync(`tar -zcvf ${fileNameLatest} dist`);

const argv = yargs.option('aws-profile', {
  alias: 'p',
  type: 'string',
}).argv;
fork icon83
star icon560
watch icon28

27
28
29
30
31
32
33
34
35
36
37
38
const yargs = require('yargs');


const { computeVersion, resolveVscodeVersion, isPublished } = require('./version');
const { dist, extensions, theiaExtension } = require('./paths.js');


const { tag, force } = yargs.option('tag', {
    choices: ['latest', 'next']
}).demandOption('tag')
    .option('force', {
        description: 'Create extension pack even if it is found to be already available',
fork icon32
star icon58
watch icon15

6
7
8
9
10
11
12
13
14
const fs = require('fs');
const glob = require('glob');
const outline = require('../outline.config');
const config = require('@phase2/outline-config/postcss.config');

const options = yargs.option('watch', {
  type: 'boolean',
  describe: 'Watch the file system for changes and render automatically',
}).argv;
fork icon25
star icon0
watch icon1

+ 7 other calls in file

32
33
34
35
36
37
38
39
40
yargs.option('cmd', {
    type: 'string',
    describe: 'CMD executable for the final Dockerfile.'
});

yargs.option('arg', {
    type: 'array',
    describe: 'CMD arguments for the final Dockerfile.'
});
fork icon18
star icon24
watch icon2

+ 11 other calls in file

71
72
73
74
75
76
77
78
79
80
  const style = fs.readFileSync(__dirname + '/email-style.css').toString()
  const html = juice(`<style>${style}</style>${converter.makeHtml(stripCharts(readme))}`)
  await mailchimp(title, html)
}
const outputOptions = yargs => {
  yargs.option('output', {
    alias: 'o',
    description: 'Output file or directory.'
  })
}
fork icon6
star icon262
watch icon0

+ 5 other calls in file

56
57
58
59
60
61
62
63
64
65
        'manually specify the archive type (entity, ' +
        'media or textures)',
    type: 'string'
});

yargs.option('merge', {
    alias: 'm',
    description: 'also dump textures that rely on two textures',
    type: 'boolean'
});
fork icon4
star icon6
watch icon3

+ 5 other calls in file

46
47
48
49
50
51
52
53
54
55
  describe: 'Skip the automatic cache purge process',
  alias: 'sp',
  type: 'boolean',
  default: false,
});
yargs.option('chunk-size', {
  describe: 'Control the chunk-size for concurrency',
  alias: 'cs',
  type: 'integer',
  default: 10,
fork icon0
star icon2
watch icon3

+ 3 other calls in file

65
66
67
68
69
70
71
72
73
74
75
    if (showdownOptions[opt].defaultValue === false) {
      showdownOptions[opt].default = null;
    } else {
      showdownOptions[opt].default = showdownOptions[opt].defaultValue;
    }
    yargs.option(opt, showdownOptions[opt]);
  }
}


function run () {
fork icon0
star icon0
watch icon1

+ 13 other calls in file

14
15
16
17
18
19
20
21
22
23
24
  .replace(/[^a-z]+/g, '-')
  .replace(/(^-|-$)/g, '')
]));


parserNames.forEach(name => {
  yargs.option(optionNames.get(name), {
    group: 'Benchmark parsers:',
    describe: name,
    type: 'boolean',
    default: name.startsWith('Acorn') || undefined
fork icon0
star icon0
watch icon1

+ 4 other calls in file

9
10
11
12
13
14
15
16
17
18
.command(
  "solve <challenge>",
  "Solve the given challenge with the given solution and input " +
    "or all of them if none is given",
  (yargs) => {
    yargs.option("challenge", {
      describe: "The challenge name",
      type: "string",
      demandOption: true, // This argument is required
    });
fork icon0
star icon0
watch icon0

Other functions in yargs

Sorted by popularity

function icon

yargs.argv is the most popular function in yargs (1012 examples)