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

added addArguments method #1467

Merged
merged 10 commits into from Mar 27, 2021
Merged

added addArguments method #1467

merged 10 commits into from Mar 27, 2021

Conversation

Niryo
Copy link
Contributor

@Niryo Niryo commented Feb 6, 2021

Pull Request

Problem

inconsistent arguments and options syntax

Solution

introducing new addArgument function

ChangeLog

New command method: addArgument() and .argument()

@Niryo
Copy link
Contributor Author

Niryo commented Feb 6, 2021

@shadowspawn This is a draft with the mvp for addArguments method. can you take a look and tell me what you think and what are the chances for a merge, before I continue to tests, docs and qa?
If this PR looks fine, i'll continue with adding choices.

@shadowspawn
Copy link
Collaborator

Modified code less than I expected for first draft, which is nice for reading the diff. Sticking to the features which are already supported (argument name and argument description) keeps it simpler.

what are the chances for a merge, before I continue to tests, docs and qa?

50%
Stick to the code for now, I'm going to add a few comments.

I am actually liking this more by leaving out the default value and custom coerce functions for now. There is room in the syntax to add them later if there is demand.

index.js Outdated Show resolved Hide resolved
@shadowspawn
Copy link
Collaborator

I wouldn't release .addArgument() without a matching convenience routine on the Command for .argument(), like .option() and .addOption().

@Niryo
Copy link
Contributor Author

Niryo commented Feb 12, 2021

@shadowspawn do you think we should deprecate .arguments() in order to keep the api small? I think that the syntax of .argument() is more elegant and robust (no need to specify the description separately using hash and open the door for typos)

@shadowspawn
Copy link
Collaborator

@shadowspawn do you think we should deprecate .arguments() in order to keep the api small?

At least to some extent, yes. I am thinking the description hash would get dropped from the README, but maybe still mention briefly that can use .arguments('<a> <b> [c...]') as a shortcut for adding multiple arguments. The example code in the README would switch to using .argument().

@Niryo
Copy link
Contributor Author

Niryo commented Feb 13, 2021

I wouldn't release .addArgument() without a matching convenience routine on the Command for .argument(), like .option() and .addOption().

What about the tests? Can I convert the tests that use arguments to tests that use argement and add argument, in order to verify that everything is working? It will be more convenient to change the tests instead of duplicate everything

@shadowspawn
Copy link
Collaborator

The old functionality is not being removed (yet), so the existing tests are still relevant to prevent regressions.

@Niryo Niryo marked this pull request as ready for review February 13, 2021 16:41
@Niryo
Copy link
Contributor Author

Niryo commented Feb 15, 2021

@shadowspawn this pr is ready for review

@shadowspawn
Copy link
Collaborator

Oh drat, I have been making comments but they were not visible yet as I had not started a review. I wondered why you were ignoring them!

index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
Readme.md Outdated Show resolved Hide resolved
tests/command.action.test.js Outdated Show resolved Hide resolved
@shadowspawn
Copy link
Collaborator

FYI: opened an issue to poll reactions to API changes in #1471

index.js Outdated Show resolved Hide resolved
@shadowspawn
Copy link
Collaborator

One thing I have been wondering about but undecided is whether .argument() should update an existing argument with same name and signature. This would allow adding descriptions after using a shortcut/old method. For example:

program
  .command('build <target>')
  .argument('target', 'source file for compilation')

@Niryo
Copy link
Contributor Author

Niryo commented Feb 28, 2021

It's quite redundant because if someone will add the argument expression in order to add description, he can just remove the arg from the command expression on the way.

@Niryo
Copy link
Contributor Author

Niryo commented Mar 11, 2021

I think all comments are resolved

@shadowspawn
Copy link
Collaborator

shadowspawn commented Mar 13, 2021

I had a go at consistently using Argument class for _args and removing the previous/intermediate untyped argDetails object. A second commit adds separate processing for legacy argument descriptions and new descriptions.

I added a draft PR to your branch. It led me to wonder whether to be more lenient with what should be done with incorrectly formatted argument. e.g.

.argument('foo')
# could be treated same as
.argument('<foo>')

@Niryo
Copy link
Contributor Author

Niryo commented Mar 13, 2021

I think that the direction we should go to should be towards more explicit syntax, for example I would prefer using something like new Argument('bla').required(), instead of remembering which means required - <> or [].
Also, with the explicit syntax you get auto complete..

program
.version('0.1.0')
.addArgument(new Argument('<username>', 'user to login'))
.argument('[password]', 'password')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description from arguments.js would be better, 'password for user, if required'.

@@ -0,0 +1,7 @@
const commander = require('../');

test('should throw on bad argument', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test naming convention being used is:

  • when something then result

@shadowspawn
Copy link
Collaborator

shadowspawn commented Mar 20, 2021

I think that the direction we should go to should be towards more explicit syntax, for example I would prefer using something like new Argument('bla').required(), instead of remembering which means required - <> or [].

I am comfortable with <foo> as the compact form since it matches the help, but supporting long form is good too. There are some routines on the Option class, but not for required as the interaction of the possibilities is more complicated. Simpler with Argument so could support required, optional, and variadic. Also Command and Option both have .name() so probably should add that.

We are using two patterns, with either getter/setter depending on whether an argument is passed, or setter with no argument or optional argument. The pure setters sometimes have a verb like hideHelp or allowUnknownOption.

Option has required and optional and variadic so using those names for the data properties is consistent. But that means other names for the setters.

@Niryo
Copy link
Contributor Author

Niryo commented Mar 20, 2021

Anyways, it was just a general thought, it's not really important for this PR, we'll discuss it further in the future if I want to add aa required prop:)

@Niryo
Copy link
Contributor Author

Niryo commented Mar 26, 2021

@shadowspawn The PR is ready on my side, if you need something else add more comments

@shadowspawn
Copy link
Collaborator

The two comments I had left are:

(But they are small and I can fix them up later.)

@shadowspawn
Copy link
Collaborator

I am thinking of pulling this onto a branch and dong some more work on it, and including in Commander v8 in June. The changes to how non-conforming arguments are processed/rejected make it a breaking change for a small subset of users. (e.g. <foo> and [bar] stay the same but what-did-you-expect changes)

@shadowspawn shadowspawn changed the base branch from develop to feature/argument March 26, 2021 23:57
Copy link
Collaborator

@shadowspawn shadowspawn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving for merging onto a feature branch (for some further work).

@shadowspawn shadowspawn added the semver: major Releasing requires a major version bump, not backwards compatible label Mar 27, 2021
@shadowspawn shadowspawn merged commit 9a77be4 into tj:feature/argument Mar 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: major Releasing requires a major version bump, not backwards compatible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants