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

[SHACK-136] Ensure help works consistently #79

Merged
merged 2 commits into from
Apr 20, 2018

Conversation

marcparadise
Copy link
Member

@marcparadise marcparadise commented Apr 12, 2018

Ensure help works consistently.

If help is visible anywhere in the command as --help, -h, or help
this will treat it as the 'help' flag and ensure that the lowest
level subcommand (before the 'help' word was encountered) is the one
that renders help.

Version has been moved to its own command, but we have retained a '-v'
flag for easy-of-use.

Signed-off-by: Marc A. Paradise marc.paradise@gmail.com

@marcparadise marcparadise requested a review from a team April 12, 2018 21:51
@marcparadise marcparadise force-pushed the SHACK-136/help-usage-consistency branch 4 times, most recently from 87e27b5 to 30bf9a5 Compare April 16, 2018 21:48
@marcparadise marcparadise force-pushed the SHACK-136/help-usage-consistency branch from 30bf9a5 to 893f6c6 Compare April 16, 2018 22:10
@marcparadise marcparadise changed the title Experimental WIP [SHACK-136] Ensure help works consistently Apr 17, 2018
show_help
elsif params.include?("-v") || params.include?("--version")
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 shouldn't be necessary since we force the version command at the cli.rb level - will verify and remove

@marcparadise marcparadise force-pushed the SHACK-136/help-usage-consistency branch from 893f6c6 to dc19c6c Compare April 17, 2018 16:37
@marcparadise
Copy link
Member Author

Fixed failing rubocop

Copy link
Member Author

@marcparadise marcparadise left a comment

Choose a reason for hiding this comment

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

Group review pass comments w/ @cheeseplus @robbkidd @tyler-ball

Converge the specified <TARGET> with the single <RESOURCE>. [PROPERTIES]
should be specified as key=value. EG:
chef target converge <TARGET> <RESOURCE> <RESOURCE_NAME> [PROPERTIES] [FLAGS]

Copy link
Member Author

Choose a reason for hiding this comment

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

missing target converge for recipe

Copy link
Contributor

Choose a reason for hiding this comment

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

Added

# rescue OptionParser::InvalidOption, OptionParser::MissingArgument
# raise Shak::OptionParserError.new(opt_parser.to_s)
Log.debug "Completed #{@command_spec.qualified_name} command without exception"
# rescue OptionParser::InvalidOption, OptionParser::MissingArgument
Copy link
Member Author

Choose a reason for hiding this comment

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

add TODO for follow-up on commented out code

Copy link
Contributor

@tyler-ball tyler-ball Apr 18, 2018

Choose a reason for hiding this comment

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

Comment removed - we handle the error fine now

end

def run(params)
raise NotImplementedError.new
show_help
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this is necessary - verify that that 'chef help' with no args works without it.

Copy link
Contributor

Choose a reason for hiding this comment

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

In my tests, we did still need this

private

def show_version
UI::Terminal.output(ChefWorkstation::VERSION)
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we need this method - it should all be handled by the new version.rb command

Copy link
Contributor

Choose a reason for hiding this comment

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

Removed

# In a future pass, we may want to actually structure it that way
# such that a "Base' instance named 'chef' is the root command.
if self.class == Base
ChefWorkstation.commands_map.command_specs
Copy link
Member Author

Choose a reason for hiding this comment

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

Verify that we don't actually have @command_spec even for Base.

Copy link
Contributor

Choose a reason for hiding this comment

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

We do have @command_spec for the hidden base because we manually populate that in builtin_commands.rb. I'm definitely thinking we want to restructure that have a root command whose subcommands are all the subcommands to the chef command

Copy link
Contributor

Choose a reason for hiding this comment

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

I also think we want two pieces of functionality for help - First, we would have a help command that is a child of the chef command and would show the top level help. Second, I think we want some shared logic that all commands have for showing their help text. In the case of the root command it could shortcut this by still calling the help subcommand

@@ -19,7 +19,7 @@
require "chef-workstation/command/target/converge"

RSpec.describe ChefWorkstation::Command::Target::Converge do
let(:cmd_spec) { instance_double(ChefWorkstation::CommandsMap::CommandSpec) }
let(:cmd_spec) { ChefWorkstation::CommandsMap::CommandSpec.new }
Copy link
Member Author

Choose a reason for hiding this comment

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

revert this line - should work with the original

Copy link
Contributor

Choose a reason for hiding this comment

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

reverted!

@tyler-ball tyler-ball force-pushed the SHACK-136/help-usage-consistency branch from dc19c6c to 645c4a9 Compare April 18, 2018 15:06
Copy link
Contributor

@tyler-ball tyler-ball left a comment

Choose a reason for hiding this comment

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

I'm 👍 on this but it really makes the case for fixing the Commands Map. What we have now is an improvement, but there are still a lot of weird inconsistencies. I think making a root command will help with that. We know we are going to have to deal with some wonkyness (-v being automatically translated to the version command, having both a help command and every subcommand able to show its own help text, etc.) but I think we can encapsulate those weird side cases better than we are now.

I also think we need some integration/functional (possibly via Aruba) testing that covers all the different help text formats we specified in the card. Maybe we do that as another PR, but leave it in the scope of the current card?

marcparadise and others added 2 commits April 18, 2018 16:20
Ensure help works consistently.

If help is visible anywhere in the command as --help, -h, or help
this will treat it as the 'help' flag and ensure that the lowest
level subcommand (before the 'help' word was encountered) is the one
that renders help.

Version has been moved to its own command, but we have retained a '-v'
flag for easy-of-use.
@tyler-ball tyler-ball force-pushed the SHACK-136/help-usage-consistency branch from 645c4a9 to 481c3e6 Compare April 18, 2018 22:23
@marcparadise
Copy link
Member Author

Yeah, +1 on fixing command map. I see you have a card already.

I also had created a card that's in flight now SHACK-155 - which covers adding CLI integration tests.

@marcparadise marcparadise merged commit ea3f7ea into master Apr 20, 2018
@chef-ci chef-ci deleted the SHACK-136/help-usage-consistency branch April 20, 2018 17:01
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.

2 participants