How to use the version function from yargs

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

yargs.version is a property in the yargs module in Node.js that specifies the version number of a command-line tool built with yargs.

136
137
138
139
140
141
142
143
144
145
        .pipe(bump({version: argv.version}))
        .pipe(gulp.dest('./'));
});

gulp.task('update-version', function() {
    var message = 'Update version to ' + argv.version;
    return gulp.src(['./package.json', './package-lock.json', 'dist/' + lowercaseAppName + '.min.js'])
        .pipe(git.add())
        .pipe(git.commit(message))
        .on('data', function(err) {
fork icon475
star icon0
watch icon46

+ 5 other calls in file

25
26
27
28
29
30
31
32
33
34
    .usage("Usage: $0 login [--github|--gitlab|--bitbucket]")
    .wrap(100)
    .help();
})
.command("logout", "Logs out of your account", (yargs: any) => {
  yargs.version(false).usage("Usage: $0 logout").help();
})
.command("upload", "Upload", (yargs: any) => {
  yargs
    .option("path", {
fork icon4
star icon10
watch icon0

How does yargs.version work?

When you use yargs.version in your Node.js application, you are setting the version number of the command-line tool you are building with yargs. This property is used to display the version number when users run the tool with the --version flag. When the --version flag is present, yargs will print the version number specified in yargs.version to the console and exit the program. To use yargs.version, you would typically set it when configuring your yargs parser, like this: javascript Copy code {{{{{{{ const argv = yargs .version('1.0.0') .command('hello', 'Say hello', (yargs) => {}, (argv) => { console.log('Hello, world!'); }) .parse(); In this example, we are setting the version number to '1.0.0' using the version method, and then defining a command using the command method. When the user runs the tool with the --version flag, yargs will print '1.0.0' to the console and exit the program, without executing the command. Overall, yargs.version provides a simple way to specify the version number of a command-line tool built with yargs, and allows users to quickly check the version number of the tool when needed.

36
37
38
39
40
41
42
43
44
45
46
47
    process.exit(1);
  }
}


let cacheDir = "cache/" + argv.version;
let outDir   = "hapi/" + argv.version;


if (!fs.existsSync(cacheDir + "/info")) {fs.mkdirSync(cacheDir + "/info", {recursive: true})}
if (!fs.existsSync(outDir + "/info")) {fs.mkdirSync(outDir + "/info", {recursive: true})}

fork icon0
star icon0
watch icon3

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
const yargs = require("yargs");

const argv = yargs
  .version("1.0.0")
  .command(
    "hello",
    "Say hello",
    (yargs) => {},
    (argv) => {
      console.log("Hello, world!");
    }
  )
  .parse();

In this example, we are using yargs.version to set the version number to '1.0.0'. We then define a command using the command method, with a command name of 'hello' and a description of 'Say hello'. When the user runs the tool with the --version flag, yargs will print '1.0.0' to the console and exit the program, without executing the command. If the user runs the tool without any flags, the hello command will execute and print 'Hello, world!' to the console. Note that yargs.version is just one of many methods and properties available in the yargs module, which provides a powerful and flexible way to build command-line tools in Node.js.

Other functions in yargs

Sorted by popularity

function icon

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