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

What's the default value for Boolean type? #53

Closed
moonformeli opened this issue Jan 17, 2020 · 3 comments
Closed

What's the default value for Boolean type? #53

moonformeli opened this issue Jan 17, 2020 · 3 comments

Comments

@moonformeli
Copy link

Hi, I don't understand this part from Readme.md

// hello.js
const arg = require('arg');

const args = arg({
	// Types
	'--help':    Boolean,
	'--version': Boolean,
	'--verbose': arg.COUNT,   // Counts the number of times --verbose is passed
	'--port':    Number,      // --port <number> or --port=<number>
	'--name':    String,      // --name <string> or --name=<string>
	'--tag':     [String],    // --tag <string> or --tag=<string>

	// Aliases
	'-v':        '--verbose',
	'-n':        '--name',    // -n <string>; result is stored in --name
	'--label':   '--name'     // --label <string> or --label=<string>;
	                          //     result is stored in --name
});

console.log(args);
/*
{
	_: ["foo", "bar", "--foobar"],
	'--port': 1234,
	'--verbose': 4,
	'--name': "My name",
	'--tag': ["qux", "qix"]
}
*/

I think --verbose should be true, not 4, because I got true from my practice.

// t.ts
const arg = require("arg");

const args = arg(
  {
    "--project": String,
    "--pass": Boolean,

    "-p": "--project"
  },
  {
    argv: process.argv.slice(2)
  }
);

// package.json
"start": "ts-node ./t.ts -p hello --pass"

// Result
{ _: [], '--project': 'hello', '--pass': true }

So, can someone tell me why it is 4? If it should'be fixed, I'll send a pr.

@moonformeli
Copy link
Author

I think this might be a human mistake from copy-paste of this

const arg = require('arg');

const argv = ['-AAAA', '-BBBB'];

const args = arg({
	'-A': arg.COUNT,
	'-B': [Boolean]
}, {
	argv
});

console.log(args);
/*
{
	_: [],
	'-A': 4,
	'-B': [true, true, true, true]
}
*/

@Qix-
Copy link
Contributor

Qix- commented Jan 17, 2020

You're putting arg.COUNT there. If you just want a Boolean, pass Boolean.

@moonformeli
Copy link
Author

Oh. My bad. I thought it's Boolean type. Thanks

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