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

Refactoring cli index #2613

Merged
merged 2 commits into from
Feb 20, 2017
Merged

Conversation

voxsim
Copy link
Contributor

@voxsim voxsim commented Feb 1, 2017

I almost cover with tests every case in src/cli/index.js and after I extracted an help command.

This simplify the file and maybe it enables some other refactorings.

cheers :D
voxsim

EDIT:

Test Plan, I think I covered almost every case in the cli, in detail:

  1. run help/--help/-h command
  2. run a command with --help/-h option
  3. run help/--help/-h with a command name as argument
  4. run version/--version command
  5. Run install command with no args are provided
  6. Run install command if first arg looks like a flag
  7. Interpolate aliases properly
  8. Yarn should use a flag if provided before --
  9. The custom script should use a flag if provided after --

@voxsim
Copy link
Contributor Author

voxsim commented Feb 2, 2017

Ops there are some regressions and I forget to lint my code, sorry ^^'

I'll let you know when I finished ;)

@voxsim voxsim force-pushed the refactoring_cli_index branch from 36aec1c to 23bb7fc Compare February 2, 2017 13:37
@voxsim
Copy link
Contributor Author

voxsim commented Feb 2, 2017

I finished with one test skipped, but @bestander do you know why we delete the args after -- and some lines after we concatenate for the args that we pass to the command?

References:

Maybe I can add another test after understanding the use case

Let me know!
cheers,
Simon

@voxsim voxsim force-pushed the refactoring_cli_index branch from 23bb7fc to e8229f1 Compare February 12, 2017 10:34
Copy link
Member

@bestander bestander left a comment

Choose a reason for hiding this comment

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

@voxsim we ignore arguments after -- for run command, for example.
You can do yarn run test -- no-cache and no-cache argument will be passed through as argument to whatever is executed in test command.

Could you rebase on master to trigger tests?

}
}

const getDocsLink = (name) => `https://yarnpkg.com/en/docs/cli/${name || ''}`;
Copy link
Member

Choose a reason for hiding this comment

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

We moved the hardcoded paths to src/constants.js, could you put it there?

for (let i = 0; i < args.length; i++) {
const arg = args[i];
if (arg === '--') {
args = args.slice(0, i);
Copy link
Member

Choose a reason for hiding this comment

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

should you have a break statement here?

@@ -160,7 +140,7 @@ if (command && typeof command.setFlags === 'function') {
command.setFlags(commander);
}

if (commandName === 'help' || args.indexOf('--help') >= 0 || args.indexOf('-h') >= 0) {
if (args.indexOf('--help') >= 0 || args.indexOf('-h') >= 0) {
Copy link
Member

Choose a reason for hiding this comment

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

why commandName is not used anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This if now covers only the 2nd case, before it was covering the the 1st, 2nd and the 3rd.

@bestander
Copy link
Member

@voxsim, thanks for the PR, it looks good.
Could you add Test Plan section to the description of your PR?
We do this to make sure everyone does the minimum testing for changes.

@voxsim voxsim force-pushed the refactoring_cli_index branch from e8229f1 to 671ab12 Compare February 19, 2017 11:31
@voxsim
Copy link
Contributor Author

voxsim commented Feb 19, 2017

@bestander I added a Test Plan and rebased with master.

IMHO we should create a Command class to clash the number of ifs and maybe delegate some stuff to it or its child (e.g. only the run command should do stuff with --). If you like the idea I can go ahead with other pull request after this one ;)

@bestander bestander merged commit 7aaee9b into yarnpkg:master Feb 20, 2017
@bestander
Copy link
Member

@voxsim, thanks for the tests and a great test plan.
I agree, having a single class for all commands flags is hard to maintain.
Go ahead, ping me on the PR!

@TimvdLippe
Copy link
Contributor

It seems that this PR is failing the AppVeyor builds: https://ci.appveyor.com/project/kittens/yarn/build/1646/job/9hcyyn0tj9xh7ldk#L309 This test is also failing for other pull requests.

@bestander
Copy link
Member

Thanks, @TimvdLippe.
Appveyor tests were failing for the last few days for another reason so I missed that.
@voxsim, looks like this PR broke on Windows.

should run help of custom-script if --help is after --
    expect(received).toEqual(expected)
    
    Expected value to equal:
      "A message from custom script with args --help"
    Received:
      "Unable to initialize device PRN"
      
      at __tests__\index.js:203:37

@voxsim
Copy link
Contributor Author

voxsim commented Feb 21, 2017

@bestander @TimvdLippe The main problem is the test itself: I do some tricks to test a npm script with arguments and for simplicity I used a bash script. First of all, we can skip the test if we are on windows and maybe think to do another test with the same trick in powershell, what do you think?

@bestander
Copy link
Member

bestander commented Feb 21, 2017 via email

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 this pull request may close these issues.

3 participants