From 7d011dad60cee369cf3492bf93ebe66f68e512ac Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sat, 18 Apr 2015 17:08:18 +0000 Subject: [PATCH] Improve CLI usage output * Move -h option at tail; * Add separator between standard and tail options. --- features/steps/output_steps.rb | 3 ++- lib/uh/wm/cli.rb | 15 +++++---------- spec/uh/wm/cli_spec.rb | 28 ++++++++++++++-------------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/features/steps/output_steps.rb b/features/steps/output_steps.rb index 81a46b6..b3e6bbc 100644 --- a/features/steps/output_steps.rb +++ b/features/steps/output_steps.rb @@ -3,13 +3,14 @@ Then /^the output must contain exactly the usage$/ do Usage: uhwm [options] options: - -h, --help print this message -v, --verbose enable verbose mode -d, --debug enable debug mode -f, --run-control PATH specify alternate run control file -r, --require PATH require ruby feature -l, --layout LAYOUT specify layout -w, --worker WORKER specify worker + + -h, --help print this message -V, --version print version eoh end diff --git a/lib/uh/wm/cli.rb b/lib/uh/wm/cli.rb index 1c057bd..e91732e 100644 --- a/lib/uh/wm/cli.rb +++ b/lib/uh/wm/cli.rb @@ -49,40 +49,35 @@ module Uh opts.separator '' opts.separator 'options:' - opts.on '-h', '--help', 'print this message' do - @env.print opts - exit - end - opts.on '-v', '--verbose', 'enable verbose mode' do @env.verbose = true @env.log_logger_level end - opts.on '-d', '--debug', 'enable debug mode' do @env.debug = true @env.log_logger_level end - opts.on '-f', '--run-control PATH', 'specify alternate run control file' do |e| @env.rc_path = e end - opts.on '-r', '--require PATH', 'require ruby feature' do |feature| require feature @env.log "Loaded `#{feature}' ruby feature" end - opts.on '-l', '--layout LAYOUT', 'specify layout' do |layout| @env.layout_class = self.class.const_get layout.to_sym end - opts.on '-w', Workers.types, '--worker WORKER', 'specify worker' do |worker| @env.worker = worker.to_sym end + opts.separator '' + opts.on_tail '-h', '--help', 'print this message' do + @env.print opts + exit + end opts.on_tail '-V', '--version', 'print version' do @env.puts VERSION exit diff --git a/spec/uh/wm/cli_spec.rb b/spec/uh/wm/cli_spec.rb index 3214741..47021bc 100644 --- a/spec/uh/wm/cli_spec.rb +++ b/spec/uh/wm/cli_spec.rb @@ -106,20 +106,6 @@ module Uh end describe '#parse_arguments!' do - context 'with help option' do - let(:arguments) { %w[-h] } - - it 'prints the usage banner on standard output' do - trap_exit { cli.parse_arguments! } - expect(stdout.string).to match /\AUsage: .+/ - end - - it 'prints options usage on standard output' do - trap_exit { cli.parse_arguments! } - expect(stdout.string).to match /\n^options:\n\s+-/ - end - end - context 'with verbose option' do let(:arguments) { %w[-v] } @@ -185,6 +171,20 @@ module Uh end end + context 'with help option' do + let(:arguments) { %w[-h] } + + it 'prints the usage banner on standard output' do + trap_exit { cli.parse_arguments! } + expect(stdout.string).to match /\AUsage: .+/ + end + + it 'prints options usage on standard output' do + trap_exit { cli.parse_arguments! } + expect(stdout.string).to match /\n^options:\n\s+-/ + end + end + context 'with version option' do let(:arguments) { %w[-V] }