How to use yargs

Comprehensive yargs code examples:

How to use yargs.tag:

76
77
78
79
80
81
82
83
84
85
86
87
88


async function createReleaseNotesPr () {
  console.log(`Script running with following options: ${JSON.stringify(options)}`)


  try {
    const version = options.tag.replace('refs/tags/', '')
    console.log(`Getting version from tag: ${version}`)


    logStep('Validation')
    validateTag(version, options.force)

How to use yargs.epilogue:

81
82
83
84
85
86
87
88
89
90
yargs.positional("resource", {
  describe: "The resource to get information about",
  choices: Object.values(ResourceEnum),
});
yargs.version(false).wrap(150).help();
yargs.epilogue(`Custom help text for 'get <resource>' command.

Examples:
  - get organization            : options: --id 
  - get organizations           : (all organization for your user will be returned)

How to use yargs.app:

9
10
11
12
13
14
15
16
17
18
19
var argv        = require('yargs').argv;
var chalk       = require('chalk');
var format      = require('util').format;
var superstatic = require('superstatic');
var replace     = require('gulp-replace');
var app         = argv.app;


if (!app) {
  app = 'angu';
  plugins.util.log('no app defined with --app, defaulting to', chalk.magenta('angu'));

How to use yargs.sha:

657
658
659
660
661
662
663
664
665
666
    messageSuffix = ' after: ' + argv.after;
  } catch (e) {
    throw argv.after + " is not a valid date.";
  }
} else if (argv.sha) {
  sha = argv.sha;
  messageSuffix = ' on commit: ' + (argv.sha.length ? argv.sha : '[last commit]');
} else {
  gutil.log('git-changed-examples may be called with either an "--sha" argument like this:');
  gutil.log('   gulp git-changed-examples --sha=4d2ac96fa247306ddd2d4c4e0c8dee2223502eb2');

How to use yargs.after:

652
653
654
655
656
657
658
659
660
661
gulp.task('git-changed-examples', ['_shred-devguide-examples'], function(){
  var after, sha, messageSuffix;
  if (argv.after) {
    try {
      after = new Date(argv.after);
      messageSuffix = ' after: ' + argv.after;
    } catch (e) {
      throw argv.after + " is not a valid date.";
    }
  } else if (argv.sha) {

How to use yargs.production:

16
17
18
19
20
21
22
23
24
25
26
27
28
if (!app) {
  app = 'angu';
  plugins.util.log('no app defined with --app, defaulting to', chalk.magenta('angu'));
}


var production = argv.production;


var paths = {};


gulp.task('unit', function () {

How to use yargs.templates:

206
207
208
209
210
211
212
213
214
215
        verbose: argv.verbose
        // xxx encoding?
    };

// figure out where to look for compiled groups
baseDir = argv.templates;
if (!path.isAbsolute(baseDir)) {
    baseDir = path.join(process.cwd(), baseDir);
}
if (argv.verbose) {

How to use yargs.query:

9
10
11
12
13
14
15
16
17
18
const args = require('yargs').argv;
const progress = require('cli-progress');

(async () => {
    let url = args.url;
    let query = args.query;
    let depth = args.depth;

    if (!url.startsWith('http')) {
        url = `https://${url}`;

How to use yargs.headless:

20
21
22
23
24
25
26
27
28
29
.demandOption(['url'], 'Please define url for analyze')
.help()
.argv

const url = argv.url;
const headless = argv.headless;

(async () => {
  if (!validUrl.isUri(url)) {
    consola.error('URL is invalid')

How to use yargs.drive:

105
106
107
108
109
110
111
112
113
114
}

// get the command line arguments
var socketPath = argv.socketpath
var imgPath = argv.imgpath
var drive = argv.drive
drive = JSON.parse(drive)

// launch the rootwriter program
var rootwriter = require('./lib/rootwriter.js')

How to use yargs.domain:

31
32
33
34
35
36
37
38
39
40
        }
};

let main = async () => {
        try {
                let domain = args.domain;
                await login(domain, args.account, args.password);

                let dataColumn = {
                        "field_type": "MULTI_PICKER",

How to use yargs.task_id:

66
67
68
69
70
71
72
73
74
75
    console.error(error);
  }
}

function getTaskIdOrAbort() {
  let task_id = argv.task_id;
  if (!task_id) {
    console.error('key `task_id` required');
    process.exit(0);
  } else {

How to use yargs.messages:

178
179
180
181
182
183
184
185
186
187
      'n': { alias: 'node', default: 'examples', describe: 'name of node (e.g. queue) from which messages are received'},
      'p': { alias: 'port', default: 5672, describe: 'port to connect to'}
    }).help('help').argv;

var received = 0;
var expected = args.messages;

container.on('message', function (context) {
    if (context.message.id && context.message.id < received) {
        // ignore duplicate message

How to use yargs.publicPath:

8
9
10
11
12
13
14
15
16
17
loading any script in your HTML.
 */
let publicPath = '/';

if(argv.publicPath){
  publicPath = argv.publicPath;
}

// force leading /
if (!publicPath.startsWith('/')) {

How to use yargs.suit:

160
161
162
163
164
165
166
167
168
169
        process.exit(0);
    }
});

var matches;
if (matches = argv.suit.match(oneWordPattern))
{
    const suit = suits[matches[1]];
    var num = Math.min(Math.max(0, Number(matches[2] - 1)), suit.length - 1);
    console.log(suit[num].longdesc());

How to use yargs.depth:

10
11
12
13
14
15
16
17
18
19
const progress = require('cli-progress');

(async () => {
    let url = args.url;
    let query = args.query;
    let depth = args.depth;

    if (!url.startsWith('http')) {
        url = `https://${url}`;
    }

How to use yargs.m:

112
113
114
115
116
117
118
119
120
121
// • Categories: 'Performance,PWA,Best Practices,Accessibility,SEO'
// This first line will be followed by a line for each URL successfully audited.
// For example: John Lewis,homepage,https://johnlewis.com, 32, 40, 78, 87, 100
let pageHeadings = ['Name', 'Page type', 'URL'];
if (argv.m) {
  pageHeadings = argv.m.split(',');
}

if (argv.o) {
  outputFile = argv.o;

How to use yargs.demand:

68
69
70
71
72
73
74
75
76
#!/usr/bin/env node

const pipe = require('pipe-args').load();
const yargs = require('yargs')

const cli = yargs.demand(1)

console.log(cli.argv);
```

How to use yargs.build:

26
27
28
29
30
31
32
33
34
35
    .alias('b', 'build')
    .describe('b', 'Pass a custom build number to deploy')
    .help('h')
    .alias('h', 'help').argv;

let customBuildNumber = argv.build;

const codeDeployEnvs = {
    test: {
        applicationName: 'BLF_WWW',

How to use yargs.submissions:

21
22
23
24
25
26
27
28
29
30
  type: 'string',
}).argv;

const config = {
  dirs: argv.directories,
  submissions: argv.submissions
};

//Read subfolders under output_dir/
function readdirAsync(path) {

How to use yargs.prod:

48
49
50
51
52
53
54
55
56
57
    console.log();
  });
});

gulp.task('serve', () => {
  isProdBuild = argv.prod;
  clean()
    .then(compileAssets)
    .then(render)
    .then(startServer)

How to use yargs.defaultHash:

14
15
16
17
18
19
20
21
22
23
`

const argv = require('yargs').argv

let port = argv.port || DEFAULT_PORT
let defaultHash = argv.defaultHash
let defaultHandshake = argv.defaultHandshake

const server = http.createServer((req, res) => {
  res.writeHead(200, {

How to use yargs.defaultHandshake:

15
16
17
18
19
20
21
22
23
24

const argv = require('yargs').argv

let port = argv.port || DEFAULT_PORT
let defaultHash = argv.defaultHash
let defaultHandshake = argv.defaultHandshake

const server = http.createServer((req, res) => {
  res.writeHead(200, {
    'Content-Type': 'text/html'

How to use yargs.location:

23
24
25
26
27
28
29
30
31
32
// check the channel names
if (!channelData[args.channel]) {
  nope('Invalid channel ' + args.channel)
}

var dataPath = args.location
console.log(path.join(dataPath, 'dev', 'osx.json'))
// check that the location exists
if (!fs.existsSync(path.join(dataPath, 'dev', 'osx.json'))) {
  nope("Release data files do not exists within " + args.location)

How to use yargs.imgpath:

104
105
106
107
108
109
110
111
112
113
  electron.app.dock.hide()
}

// get the command line arguments
var socketPath = argv.socketpath
var imgPath = argv.imgpath
var drive = argv.drive
drive = JSON.parse(drive)

// launch the rootwriter program

How to use yargs.encoding:

220
221
222
223
224
225
226
227
228
// xxx
if (!argv._[1]) {
    console.log("xxx need to read from stdin");
} else {
    data = fs.readFileSync(argv._[1], {
        encoding: argv.encoding
    });
}
data = JSON.parse(data);

How to use yargs.lang:

25
26
27
28
29
30
31
32
33
34
var argv = require('yargs')
    .usage('Usage: --input InputFile --lang targetISOCode --lines [lines before stopping] --output [OutputFile]')
    .default('lines',99999)
    .demand(['input', 'lang'])
    .argv;
var targetLanguageId = argv.lang;

var RateLimiter = require('limiter').RateLimiter;
// //google translate limits us to 100 requests per second requests per second.
var googleTranslateRateLimiter = new RateLimiter(150, 'second');

How to use yargs.L:

28
29
30
31
32
33
34
35
36
37
ELECTRON_ARCH: argv.arch ? argv.arch : 'x64',
ELECTRON_ARCHES: ['all', 'ia32', 'x64', 'armv7l', 'arm64', 'mips64el'],
ELECTRON_PLATFORM: argv.platform ? argv.platform : 'linux',
ELECTRON_PLATFORMS: ['all', 'darwin', 'linux', 'mas', 'win32'],
// Default loglevel is info.
LOG_LEVEL: (argv.L && argv.L.length <= 4) ? argv.L.length : 3,
LOG_LEVELS: ['error', 'warning', 'info', 'debug'],
NODE_ENVS: ['development', 'production'],
// Safest default deploy target is `alpha`.
PUBLISH_CHANNEL: argv.channel ? argv.channel : 'alpha',

How to use yargs.sourcemap:

39
40
41
42
43
44
45
46
47
48
  css: 'hawtio-console-assembly.css',
  tsProject: plugins.typescript.createProject('tsconfig.json'),
  tsLintOptions: {
    rulesDirectory: './tslint-rules/'
  },
  sourceMap: argv.sourcemap
};

var normalSizeOptions = {
  showFiles: true

yargs functions:

Sorted by popularity