Skip to content

Commit

Permalink
Cleaning up various issues from the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-ball committed Apr 18, 2018
1 parent 893f6c6 commit 645c4a9
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 36 deletions.
10 changes: 4 additions & 6 deletions components/chef-workstation/i18n/en.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# Shared and top-level CLI output text.
cli:
# CLI option, banner, and usage text
aborted: Canceling request due to interrupt.
config: Location of config file. Defaults to %1
creating_config: "Creating config file in %1."
subcommands: "SUBCOMMANDS:"
target: ""

# Text specific to each command
commands:
base:
version: "Show the current version of this tool"
config: Location of config file. Defaults to %1
version: Show the current version of Chef Workstation.
version_for_help: "Chef Workstation Version: %1\n\n"
description: |
Congratulations! You are using chef: your gateway
Expand Down Expand Up @@ -61,10 +57,12 @@ commands:
usage_full: chef target [SUBCOMMAND] [FLAGS]

converge:
aborted: Canceling request due to interrupt.
description: Apply a change to a target node.

usage: |
chef target converge <TARGET> <RESOURCE> <RESOURCE_NAME> [PROPERTIES] [FLAGS]
chef target converge <TARGET> <RECIPE> [FLAGS]
usage_full: |
chef target converge <TARGET> <RESOURCE> <RESOURCE_NAME> [PROPERTIES] [FLAGS]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

# Version works inversely - if someone specifies '-v' we will swap that out
# to use the Version command.
c.top_level("version", :Version, text.base, "chef-workstation/command/version")
c.top_level("version", :Version, text.version, "chef-workstation/command/version")

# This is our root command 'chef'. Giving it all top-level subcommands (which will
# exclude this hidden one at time of evaluation) means that 'chef help' will be able to show
Expand Down
18 changes: 2 additions & 16 deletions components/chef-workstation/lib/chef-workstation/command/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Base
option :config_path,
:short => "-c PATH",
:long => "--config PATH",
:description => Text.cli.config(ChefWorkstation::Config.default_location),
:description => T.config(ChefWorkstation::Config.default_location),
:default => ChefWorkstation::Config.default_location,
:proc => Proc.new { |path| ChefWorkstation::Config.custom_location(path) }

Expand All @@ -64,17 +64,12 @@ def run_with_default_options(params = [])
# We ignore options for all 'help' commands.
Log.debug "Showing help for #{@command_spec.qualified_name}"
show_help
elsif params.include?("-v") || params.include?("--version")
Log.debug "Showing version for #{@command_spec.qualified_name}"
show_version
else
Log.debug "Starting #{@command_spec.qualified_name} command"
parse_options(params)
run(params)
end
Log.debug "Completed #{@command_spec.qualified_name} command without exception"
# rescue OptionParser::InvalidOption, OptionParser::MissingArgument
# raise Shak::OptionParserError.new(opt_parser.to_s)
end

def run(params)
Expand Down Expand Up @@ -119,13 +114,8 @@ def usage
self.class.usage
end


private

def show_version
UI::Terminal.output(ChefWorkstation::VERSION)
end

# TODO - does this all just belong in a HelpFormatter? Seems weird
# to encumber the base with all this...
def show_help
Expand Down Expand Up @@ -196,11 +186,7 @@ def subcommands
# of top-level commands - those are subcommands of 'chef'.
# 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
else
@command_spec.subcommands
end
@command_spec.subcommands
end

class OptionValidationError < ChefWorkstation::ErrorNoLogs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def install(r)
end
when :error
# Message may or may not be present. First arg if it is.
msg = data.length > 0 ? data[0] : Text.cli.aborted
msg = data.length > 0 ? data[0] : T.aborted
r.error(TS.install.failure(msg))
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def command_class

def make_usage
# TODO an OutputFormatter that understands "format_usage(command) might be better.
usage = ChefWorkstation::Text.cli.usage
usage = ChefWorkstation::Text.commands.base.usage
usage_text_split = text.usage.split("\n")
if usage_text_split.length == 1
usage << text.usage
Expand All @@ -118,7 +118,6 @@ def make_usage
end
end
usage

end

def make_banner
Expand Down Expand Up @@ -178,7 +177,7 @@ def have_command_or_alias?(name)
def command_names(with_hidden = false)
return command_specs.keys if with_hidden

command_specs.select {|k, v| !v.hidden}.keys
command_specs.select { |k, v| !v.hidden }.keys
end

private
Expand Down
8 changes: 0 additions & 8 deletions components/chef-workstation/spec/unit/command/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,5 @@
end
end
end
context "with version arguments" do
%w{--version -v}.each do |arg|
it "shows version when run with #{arg}" do
expect(subject).to receive(:show_version)
subject.run_with_default_options([arg])
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require "chef-workstation/command/target/converge"

RSpec.describe ChefWorkstation::Command::Target::Converge do
let(:cmd_spec) { ChefWorkstation::CommandsMap::CommandSpec.new }
let(:cmd_spec) { instance_double(ChefWorkstation::CommandsMap::CommandSpec) }
subject(:cmd) do
ChefWorkstation::Command::Target::Converge.new(cmd_spec)
end
Expand Down

0 comments on commit 645c4a9

Please sign in to comment.