Improve CLI usage output

* Move -h option at tail;
* Add separator between standard and tail options.
This commit is contained in:
Thibault Jouan 2015-04-18 17:08:18 +00:00
parent 0f2d658986
commit 7d011dad60
3 changed files with 21 additions and 25 deletions

View File

@ -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

View File

@ -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

View File

@ -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] }