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

Override yargs help output with custom help renderer #229

Merged
merged 11 commits into from
Apr 18, 2018

Conversation

agubler
Copy link
Member

@agubler agubler commented Apr 2, 2018

Type: feature

The following has been addressed in the PR:

Description:

Handles help output explicitly for the CLI and commands with a custom help renderer. Also needed some significant changes in the way that commands are registered:

  • Normalise the previous CommandMap and YargsCommandNames to a single GroupMap so that they are not managed over two objects
  • Added extra optional property on the command API for global, defaults to false
  • Added extra options on the internal CommandWrapper - global, installed, default
  • default is set on the first registered command for a group (same as before)
  • installed is set to false for commands found from npm
  • Removed support for command aliases as no commands currently use it and it complicates the help renderer.

Temporarily hard coded create-app to be a global command as it's the "dojo" global external command.

Main CLI help output

1__anthony_red-sky____development_test-beds_dojo-cli

Group CLI help output

1__anthony_red-sky____development_test-beds_dojo-cli

Command CLI help output

1__anthony_red-sky____development_test-beds_dojo-cli

Installable command CLI help output

1__anthony_red-sky____development_test-beds_dojo-cli

Resolves #227
Resolves #228

@agubler
Copy link
Member Author

agubler commented Apr 2, 2018

Am completely open to suggestions to the formatting and colours and also if I've missed anything.

@codecov
Copy link

codecov bot commented Apr 2, 2018

Codecov Report

Merging #229 into master will decrease coverage by 0.91%.
The diff coverage is 95.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #229      +/-   ##
==========================================
- Coverage   95.04%   94.13%   -0.92%     
==========================================
  Files          19       20       +1     
  Lines         525      597      +72     
  Branches       70       95      +25     
==========================================
+ Hits          499      562      +63     
- Misses         13       17       +4     
- Partials       13       18       +5
Impacted Files Coverage Δ
src/commands/version.ts 98.41% <100%> (+0.05%) ⬆️
src/commands/init.ts 100% <100%> (ø) ⬆️
src/installableCommands.ts 89.36% <100%> (-0.97%) ⬇️
src/allCommands.ts 100% <100%> (ø) ⬆️
src/loadCommands.ts 100% <100%> (+5.12%) ⬆️
src/validation.ts 100% <100%> (ø)
src/index.ts 100% <100%> (ø) ⬆️
src/commands/eject.ts 94.33% <100%> (+0.22%) ⬆️
src/CommandHelper.ts 90.47% <81.81%> (-9.53%) ⬇️
src/command.ts 94.44% <85.71%> (-2.86%) ⬇️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 538eff7...91035f7. Read the comment docs.

@agubler
Copy link
Member Author

agubler commented Apr 2, 2018

Needs more test coverage!

@agubler agubler force-pushed the customise-command-help branch from 4f33e59 to 5dfce09 Compare April 2, 2018 13:02
Copy link
Member

@tomdye tomdye left a comment

Choose a reason for hiding this comment

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

Looks good visually. Might be worth using the cliui package for layout

@@ -19,12 +15,12 @@ export type RenderFilesConfig = {
* allowing commands to call one another. Provides 'run' and 'exists' functions
*/
export class SingleCommandHelper implements CommandHelper {
private _commandsMap: CommandsMap;
private _groupMap: GroupMap;
Copy link
Contributor

Choose a reason for hiding this comment

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

Funny that we're renaming these to "commands" in the README and changing them FROM commands in the code 😂

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it’s because we already have a commands map that is the value of the group map. Traditionally it’s easier to understand these things as different (as they really are) when it comes to code. Open to other name suggestions though.

@@ -26,6 +25,8 @@ export function initCommandLoader(searchPrefixes: string[]): (path: string) => C
alias,
description,
register,
installed: true,
global: group === 'create' && name === 'app' ? true : global,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should move this into a utility or something so that the next time we need to force a global like this we don't have to modify the logic in here?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a totally temporary thing, this PR introduces an optional global property on the API that commands can mark whether that are global and then we can remove this logic completely

@agubler
Copy link
Member Author

agubler commented Apr 6, 2018

@tomdye I think for now the padding works but I defo want to look at using cli-table for the layout.

Copy link
Member

@dylans dylans left a comment

Choose a reason for hiding this comment

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

One test description should be clearer. Overall the code looks fine, I don't know enough about this space to know if you've introduced any regressions.

}
});

it('Should not return validation error for when option provided', () => {
Copy link
Member

Choose a reason for hiding this comment

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

"Should not return validation error for when option provided" might want to make this clearer?

@dylans dylans added this to the 2018.04 milestone Apr 6, 2018
@agubler
Copy link
Member Author

agubler commented Apr 8, 2018

Updated CLI output with some extra colour and different ascii art for dojo

Main CLI help output

1__anthony_red-sky____development_test-beds_dojo-cli

Group CLI help output

1__anthony_red-sky____development_test-beds_dojo-cli

Command CLI help output

1__anthony_red-sky____development_test-beds_dojo-cli

@agubler
Copy link
Member Author

agubler commented Apr 9, 2018

@tomdye @rorticus Have changed the output slightly if you could take another look.

@rorticus
Copy link
Contributor

rorticus commented Apr 9, 2018

wow that's fancy :)

@agubler
Copy link
Member Author

agubler commented Apr 9, 2018

Art courtesy of @matt-gadd 😄

@agubler agubler merged commit b3d4146 into dojo:master Apr 18, 2018
@dylans dylans removed this from the 2018.04 milestone Apr 24, 2018
@dylans dylans added this to the 2.0.0 milestone Apr 24, 2018
@agubler agubler mentioned this pull request Oct 17, 2018
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.

4 participants