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

Incorrect test opts in test: 'boolean and alias with chainable api' #7

Closed
nhz-io opened this issue Oct 16, 2022 · 4 comments · Fixed by #27
Closed

Incorrect test opts in test: 'boolean and alias with chainable api' #7

nhz-io opened this issue Oct 16, 2022 · 4 comments · Fixed by #27

Comments

@nhz-io
Copy link
Contributor

nhz-io commented Oct 16, 2022

in 'boolean and alias with chainable api' test:

minimist/test/bool.js

Lines 42 to 52 in 980d7ac

var opts = {
herp: { alias: 'h', boolean: true }
};
var aliasedArgv = parse(aliased, {
boolean: 'herp',
alias: { h: 'herp' }
});
var propertyArgv = parse(regular, {
boolean: 'herp',
alias: { h: 'herp' }
});

the opts is redundant - it is not used. Instead opts are passed inline to parse (twice), with incorrect value for boolean,
which should be true instead of the name of the argument.

opts should be used instead of passing inline (as it done correctly in other tests)

@ljharb
Copy link
Member

ljharb commented Oct 16, 2022

When I make that change, the test fails, so I'm not sure if your suggestion is correct. I've already removed the unused opts in 62fde7d, but it can be added back in a PR if you think the test still needs fixing.

@shadowspawn
Copy link
Collaborator

  1. I think boolean and alias with chainable api is currently identical functionally to the following boolean and alias with options hash.

  2. format of the unused opts is completely wrong! It is inverted with key of herp containing alias and boolean (like parseArgs settled on). I wonder if it is left over from an earlier approach or something that was being considered at the time.

var opts = { 
     herp: { alias: 'h', boolean: true } 
 }; 

I don't see what "chainable API" refers to so I think the redundant test could be deleted, as unclear what different test was intended.

@nhz-io
Copy link
Contributor Author

nhz-io commented Oct 17, 2022

Regarding the alias - shouldn't it be bidirectional? (regardless what is aliased from).
isn't it that when h->herp and herp = true then h == true and vice versa, when h = true then also herp == true ?
I think the from -> to order shouldn't really matter. Am i wrong?

Checked the source, aliases are bidirectoinal:

minimist/index.js

Lines 52 to 59 in 62fde7d

Object.keys(opts.alias || {}).forEach(function (key) {
aliases[key] = [].concat(opts.alias[key]);
aliases[key].forEach(function (x) {
aliases[x] = [key].concat(aliases[key].filter(function (y) {
return x !== y;
}));
});
});

@shadowspawn
Copy link
Collaborator

Yes you are right the aliases are bidirectional. But I am not sure what this affects? (My "inverted" comment?)

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

Successfully merging a pull request may close this issue.

3 participants