How to use the argv function from optimist

Find comprehensive JavaScript optimist.argv code examples handpicked from public code repositorys.

optimist.argv is a JavaScript object that represents the command-line arguments passed to a Node.js application using the Optimist library.

21
22
23
24
25
26
27
28
29
30
    .alias('?', 'help')
    .describe('?', 'Print usage information');

// get credentials either from command line or config.json in ~/.teslams/config.js
var creds = require('./config.js').config(argv);
argv = argv.argv;

if (argv.help === true) {
    console.log('Usage: teslacmd.js -u <username> -p <password> -XZ');
    console.log('                   -P [listen port (default 8888)]');
fork icon112
star icon418
watch icon58

30
31
32
33
34
35
36
37
38
39
.options('h', {
        'alias' : 'help',
        'describe' : 'Help infomation'
    });

var options = userArgv.argv;
if(options['h']){userArgv.showHelp();process.exit();}
var settings = require('./instance/'+options['i']+'/'+'settings.json');
settings['instance'] = options['i'];
////log level/////////////////////////////////////////////////////////////////
fork icon54
star icon151
watch icon16

+ 2 other calls in file

How does optimist.argv work?

optimist.argv works by parsing the command-line arguments passed to a Node.js application using the Optimist library. The object contains properties that correspond to the command-line options and arguments, with the option names as keys and the option values as values. By default, Optimist automatically detects the presence of common command-line flags such as -h and --help, and generates help output based on the defined options. Developers can also define their own command-line options using the option() method of the Optimist instance, which allows for a variety of customizations such as default values, boolean flags, and aliases. By providing a simple and intuitive way to access and manipulate command-line arguments, Optimist.argv can help to streamline the development and testing process for Node.js applications.

35
36
37
38
39
40
41
42
43
44
    .options('h', {
      alias: 'help',
      descripe: 'Show help info'
    });

var argv = opt.argv;

if (argv.help) {
  return opt.showHelp();
}
fork icon51
star icon349
watch icon20

31
32
33
34
35
36
37
38
39
40
    h: {alias: 'help', boolean: false, describe: 'Show help (generic or specific operation)'}
  })
  .usage(usage)
  .demand(1, 'Please provide a data source and at least one transform')
;
var argv = yargs.argv;

if (argv.h) {
  if (argv._.length > 0) {
    var opName = argv._[0];
fork icon17
star icon118
watch icon44

+ 7 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const optimist = require("optimist");

// Define some command-line options using Optimist
const options = optimist.usage("Usage: $0 --file [filename]").options({
  file: {
    alias: "f",
    demand: true,
    describe: "The name of the file to process",
    type: "string",
  },
  verbose: {
    alias: "v",
    describe: "Enable verbose output",
    type: "boolean",
  },
}).argv;

// Access the command-line options using Optimist.argv
console.log(`Processing file: ${options.file}`);
console.log(`Verbose mode enabled: ${options.verbose}`);

In this example, we use optimist to define some command-line options for a Node.js application. We define two options using the options() method of the Optimist instance: --file (or -f for short), which takes a string value and is required, and --verbose (or -v for short), which is a boolean flag that can be omitted. We then access the command-line options using optimist.argv, which returns an object containing the values of the defined options. We output the values of the --file and --verbose options to the console using string interpolation. By using optimist.argv, we can easily access and manipulate command-line arguments in a Node.js application and customize its behavior based on user input.

33
34
35
36
37
38
39
40
41
42
43
44
];


/**
 * @type {{ build: boolean; run: string; runGlob: string; coverage: boolean; help: boolean; }}
 */
const argv = optimist.argv;


if (argv.help) {
	optimist.showHelp();
	process.exit(1);
fork icon55
star icon19
watch icon0

10
11
12
13
14
15
16
17
18
19
var home = osenv.home();

function rc(name, cwd, argv) {
  var argvConfig;

  argv = argv || optimist.argv;

  // Parse --config.foo=false
  argvConfig = object.map(argv.config || {}, function (value) {
    return value === 'false' ? false : value;
fork icon30
star icon0
watch icon2

13
14
15
16
17
18
19
20
21
22
  .describe('h', 'Print this help message')
  .alias('o', 'out')
  .describe('o', 'output directory relative to temporary')
  .describe('dere', "I-its's not like I'm an option so DON'T GET THE WRONG IDEA!")

var argv = options.argv

if (argv._.length === 1) {
  runCode(argv)
}
fork icon16
star icon205
watch icon7

40
41
42
43
44
45
46
47
48
49
  .options("f", {
    alias: "outfile",
    describe: "Output file for compiled protos"
  });

var argv = optimist.argv;

if( argv.help ) { optimist.showHelp(); process.exit(0); }

if( argv._.length == 0 && fs.existsSync("./protos.json")) Protofile.protoPaths.push("./protos.json");
fork icon12
star icon77
watch icon27

9
10
11
12
13
14
15
16
17
18
19
20
const Tx = wanutil.wanchainTx
const EthTx = require('ethereumjs-tx').Transaction


let web3url, owner, leader, admin, leaderPk, web3;


const args = optimist.argv;
const whiteCountAll = 4;
const whiteBackup = 3;
const whiteCount = whiteCountAll - whiteBackup;
const memberCountDesign = 4;
fork icon10
star icon10
watch icon6

+ 3 other calls in file

50
51
52
53
54
55
56
57
58
59
60
61
62
var all_passed = false;


var osx_cached_defaults = null;


function main() {
  var config_path = path.join(__dirname, optimist.argv.config + '.json');


  fs.readFile(config_path, 'utf8', function (err, data) {
    if (err) {
      console.error('ERROR: Could not locate configuration file ', config_path);
fork icon1
star icon0
watch icon1

+ 45 other calls in file

99
100
101
102
103
104
105
106
107
108
109
    .describe('maxunrankedhandicap', 'Max handicap for unranked games')
    .describe('nopause', 'Do not allow games to be paused')
    .describe('nopauseranked', 'Do not allow ranked games to be paused')
    .describe('nopauseunranked', 'Do not allow unranked games to be paused')
;
let argv = optimist.argv;


if (!argv._ || argv._.length == 0) {
    optimist.showHelp();
    process.exit();
fork icon0
star icon0
watch icon1