From 71caf160be8eda3442fcb4d5293a30f6eab6f45f Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sat, 18 Apr 2015 17:03:25 +0000 Subject: [PATCH] Add version CLI option --- features/cli/version.feature | 6 ++++++ features/steps/output_steps.rb | 6 ++++++ lib/uh/wm/cli.rb | 5 +++++ spec/uh/wm/cli_spec.rb | 15 +++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 features/cli/version.feature diff --git a/features/cli/version.feature b/features/cli/version.feature new file mode 100644 index 0000000..5aa1420 --- /dev/null +++ b/features/cli/version.feature @@ -0,0 +1,6 @@ +Feature: version CLI option + + Scenario: prints the current version on standard output + When I run uhwm with option --version + Then uhwm must terminate successfully + And the output must contain exactly the version diff --git a/features/steps/output_steps.rb b/features/steps/output_steps.rb index 78fbc5d..81a46b6 100644 --- a/features/steps/output_steps.rb +++ b/features/steps/output_steps.rb @@ -10,9 +10,15 @@ options: -r, --require PATH require ruby feature -l, --layout LAYOUT specify layout -w, --worker WORKER specify worker + -V, --version print version eoh end +Then /^the output must contain exactly the version$/ do + #require File.expand_path('../lib/uh/wm/version', __FILE__) + assert_exact_output "%s\n" % Uh::WM::VERSION, all_output +end + Then /^the output must match \/([^\/]+)\/([a-z]*)$/ do |pattern, options| uhwm_wait_output Regexp.new(pattern, options) end diff --git a/lib/uh/wm/cli.rb b/lib/uh/wm/cli.rb index 3b07358..1c057bd 100644 --- a/lib/uh/wm/cli.rb +++ b/lib/uh/wm/cli.rb @@ -82,6 +82,11 @@ module Uh 'specify worker' do |worker| @env.worker = worker.to_sym end + + opts.on_tail '-V', '--version', 'print version' do + @env.puts VERSION + exit + end end end end diff --git a/spec/uh/wm/cli_spec.rb b/spec/uh/wm/cli_spec.rb index 027546c..3214741 100644 --- a/spec/uh/wm/cli_spec.rb +++ b/spec/uh/wm/cli_spec.rb @@ -185,6 +185,21 @@ module Uh end end + context 'with version option' do + let(:arguments) { %w[-V] } + + it 'prints the version on standard output' do + trap_exit { cli.parse_arguments! } + expect(stdout.string).to eq "#{::Uh::WM::VERSION}\n" + end + + it 'exits with a return status of 0' do + expect { cli.parse_arguments! }.to raise_error(SystemExit) do |e| + expect(e.status).to eq 0 + end + end + end + context 'with invalid option' do let(:arguments) { %w[--unknown-option] }