-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Why can't I get this parameter argv. template | | argv. t #51
Comments
You specified the generic types for minimist, but you didn't actually pass a runtime value with that config to the function, so it doesn't know about any of them. Types don't matter since they're all erased before runtime; the actual JS is what matters. |
I don't mean on the command line - I mean as an option in the object passed to |
const argv = minimist(process.argv.slice(2)) I'm sorry to bother you, I can run the script locally using node, but pushing it to NPM is not enough |
If you want the arguments |
Remove |
The work-around is to use Try putting
|
The same error will be reported if the ‘_’ in minimist is removed. |
I don’t know why the -t parameter can be recognized by removing the directory parameter. |
Are you referring to the That is a special key used by Minimist in the results. It should not be included in the configuration You showed:
but I would expect just:
|
To explain a little more, Minimist does not need or support predefining what non-option arguments are expected. |
Oh! Looking at the Minimist code, I can see that works to prevent a conversion to number. I had not previously been aware that was possible. Thanks for the references. Line 243 in 9080fa7
|
Do you want to display an error if both are supplied? If so, you will need to check for that yourself. Or does the full program not allow both at once? I can specify both in a test program. const minimist = require('minimist');
const commandLineArgs = process.argv.slice(2);
// The { string: ['_'] } is to prevent positional arguments from being parsed as numbers.
const argv = minimist(commandLineArgs, { string : ['_'] });
console.log('Parse: %o', commandLineArgs);
const argTargetDir = argv._[0];
const argTemplate = argv.template || argv.t;
console.log({ argTargetDir, argTemplate }); % node index.js 1234
Parse: [ '1234', [length]: 1 ]
{ argTargetDir: '1234', argTemplate: undefined }
% node index.js my-vue-app
Parse: [ 'my-vue-app', [length]: 1 ]
{ argTargetDir: 'my-vue-app', argTemplate: undefined }
% node index.js -t TEMPLATE
Parse: [ '-t', 'TEMPLATE', [length]: 2 ]
{ argTargetDir: undefined, argTemplate: 'TEMPLATE' }
% node index.js --template TEMPLATE
Parse: [ '--template', 'TEMPLATE', [length]: 2 ]
{ argTargetDir: undefined, argTemplate: 'TEMPLATE' }
% node index.js my-vue-app -t TEMPLATE
Parse: [ 'my-vue-app', '-t', 'TEMPLATE', [length]: 3 ]
{ argTargetDir: 'my-vue-app', argTemplate: 'TEMPLATE' }
% node index.js -t TEMPLATE my-vue-app
Parse: [ '-t', 'TEMPLATE', 'my-vue-app', [length]: 3 ]
{ argTargetDir: 'my-vue-app', argTemplate: 'TEMPLATE' } |
I can do it locally, but it won’t work if I put it on npm and use scaffolding. |
I have not written a package initializer, but it looks like the main trick is using the The documentation for npm-init shows:
|
Why can't I get this parameter argv. template | | argv. t? Did I pass the values incorrectly
"@types/minimist": "^1.2.2" 这个是我使用的版本
The text was updated successfully, but these errors were encountered: