Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always print 1.0.0 and exit process #2386

Open
foolzhang opened this issue Jan 10, 2024 · 2 comments
Open

always print 1.0.0 and exit process #2386

foolzhang opened this issue Jan 10, 2024 · 2 comments

Comments

@foolzhang
Copy link

node: v16.20.2
yargs: "version": "17.7.2"

// demo
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')

const getArgs = function () {
    const argv = yargs(hideBin(process.argv)).argv
    return argv;
}

getArgs();
console.log("---------------doing");

then run shell
node ci.js --version 21

expect print : {version:'21'}

@shadowspawn
Copy link
Member

By default, Yargs adds a --version option which displays the package version number. If you want to disable the built-in behaviour, call .version(false) on the yargs instance.

e.g.

const argv = yargs(hideBin(process.argv)).version(false).argv

https://yargs.js.org/docs/#api-reference-versionoption-description-version

@foolzhang
Copy link
Author

thanks @shadowspawn , it works for me, i recormmand to add this to REAMDME.md, also you depends on your step

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants