Skip to content
This repository

Prevent wizard from always running on new commands #232

Merged
merged 5 commits into from over 1 year ago

3 participants

Fotios Lindiakos Clayton Coleman OpenShift Bot
Fotios Lindiakos

Iff the wizard has not been run and is required, then a warning will be printed to the user advising them to run the wizard.

Also added a post_install message that advises the user to run the wizard. Note: this message is suppressed if installing the package via bundle (like if it's included in a Gemfile).

lib/rhc/helpers.rb
@@ -131,21 +131,30 @@ def deprecated(msg,short = false)
131 131 end
132 132 end
133 133
134   - def say(msg)
135   - super
  134 + def say(msg, *args)
  135 + old_terminal = $terminal
  136 + $terminal = HighLine.new(nil,$stderr) if Hash[*args][:stderr]
1
Clayton Coleman Owner

Doing terminal replacement like this is sketchy - also the new HighLine instance has no access to any of the same variables (page_at, wrap_at, use_color) that the core Highline instance has. Just call puts $stderr for now instead of super.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/rhc/helpers.rb
((16 lines not shown))
138 144 def success(msg, *args)
139   - say color(msg, :green)
  145 + say color(msg,:green), *args
1
Clayton Coleman Owner

Inconsistent whitespacing here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/rhc/commands.rb
@@ -71,7 +71,13 @@ def self.needs_configuration!(cmd, options, config)
71 71 options.help or
72 72 config.has_local_config? or
73 73 config.has_opts_config?)
74   - RHC::Wizard.new(config).run
  74 +
  75 + RHC::Helpers.warn(
  76 + [
1
Clayton Coleman Owner

join("\n") is not what we're using in other places - we're just doing "Sentence.\nSentence."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Clayton Coleman

As per hiro's comment in IRC, change the message to:

You have not yet configured the OpenShift client tools.  Please run 'rhc setup'.
Clayton Coleman

'rhc' doesn't open the wizard - we can spawn this as a separate defect.

Fotios Lindi... added some commits
OpenShift Bot openshift-bot merged commit 73e0ddd into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 5 unique commits by 1 author.

Nov 20, 2012
Fotios Lindiakos Made wizard not run by default, but show a message instead dbc414e
Fotios Lindiakos Created STDERR helper to match new error messages 3d57d13
Fotios Lindiakos Fixes for clayton's comments ba1ccad
Nov 21, 2012
Fotios Lindiakos Modified warning as per Hiro's comments 841bcfc
Fotios Lindiakos Fixing spec test 73e0ddd
This page is out of date. Refresh to see the latest.
5 lib/rhc/commands.rb
@@ -71,7 +71,10 @@ def self.needs_configuration!(cmd, options, config)
71 71 options.help or
72 72 config.has_local_config? or
73 73 config.has_opts_config?)
74   - RHC::Wizard.new(config).run
  74 +
  75 + RHC::Helpers.warn(
  76 + "You have not yet configured the OpenShift client tools.\nPlease run 'rhc setup'.",
  77 + :stderr => true)
75 78 end
76 79 end
77 80
20 lib/rhc/helpers.rb
@@ -131,21 +131,29 @@ def deprecated(msg,short = false)
131 131 end
132 132 end
133 133
134   - def say(msg)
135   - super
  134 + def say(msg, *args)
  135 + if Hash[*args][:stderr]
  136 + $stderr.puts msg
  137 + else
  138 + super(msg)
  139 + end
136 140 msg
137 141 end
  142 +
138 143 def success(msg, *args)
139   - say color(msg, :green)
  144 + say color(msg, :green), *args
140 145 end
  146 +
141 147 def info(msg, *args)
142   - say color(msg, :cyan)
  148 + say color(msg, :cyan), *args
143 149 end
  150 +
144 151 def warn(msg, *args)
145   - say color(msg, :yellow)
  152 + say color(msg, :yellow), *args
146 153 end
  154 +
147 155 def error(msg, *args)
148   - say color(msg, :red)
  156 + say color(msg, :red), *args
149 157 end
150 158
151 159 def color(s, color)
12 rhc.gemspec
@@ -18,6 +18,18 @@ Gem::Specification.new do |s|
18 18 s.executables = Dir['bin/*'].map{ |f| File.basename(f) }
19 19 s.require_path = 'lib'
20 20
  21 + s.post_install_message = %q{If this is your first time installing the RHC tools, please run 'rhc setup'}
  22 +
  23 + # Format the post install message with some nice separators
  24 + sep = "=" * s.post_install_message.lines.to_a.map(&:chomp).map(&:length).max
  25 + s.post_install_message = [
  26 + sep,
  27 + nil,
  28 + s.post_install_message,
  29 + nil,
  30 + sep
  31 + ].join("\n")
  32 +
21 33 s.add_dependency 'net-ssh', '>= 2.0.11'
22 34 s.add_dependency 'archive-tar-minitar'
23 35 s.add_dependency 'test-unit' # used by rhc domain status in ruby 1.9
9 spec/rhc/command_spec.rb
@@ -55,7 +55,9 @@ module Nested; class StaticRootClass < RHC::Commands::Base; def run; 1; end; end
55 55 end
56 56
57 57 expects_running('test').should call(:run).on(instance).with(no_args)
58   - wizard_run.should be_true
  58 + wizard_run.should be_false
  59 +
  60 + stderr.should match("You have not yet configured the OpenShift client tools")
59 61 end
60 62 end
61 63 end
@@ -151,10 +153,7 @@ def raise_exception
151 153 context 'and when deprecated alias is called' do
152 154 it do
153 155 expects_running('static', 'exe', "arg").should call(:execute).on(instance).with('arg')
154   - $stderr.seek(0)
155   - # some systems might redirect warnings to stderr
156   - output = "#{$stderr.read} #{$terminal.read}"
157   - output.should match("Warning: This command is deprecated. Please use 'rhc static execute' instead.")
  156 + stderr.should match("Warning: This command is deprecated. Please use 'rhc static execute' instead.")
158 157 end
159 158 end
160 159
7 spec/rhc/rest_client_spec.rb
@@ -441,8 +441,8 @@ module Rest
441 441 capture do
442 442 @client = MockClient.new(mock_href, mock_user, mock_pass, true)
443 443 @client.send logout_method.to_sym
444   - $stderr.rewind
445   - $stderr.read.should =~ /Logout\/Close client$/
  444 +
  445 + stderr.should match(/Logout\/Close client$/)
446 446 end
447 447 end
448 448 end
@@ -451,8 +451,7 @@ module Rest
451 451 capture do
452 452 @client = MockClient.new(mock_href, mock_user, mock_pass, false)
453 453 @client.send logout_method.to_sym
454   - $stderr.rewind
455   - $stderr.read.should == ''
  454 + stderr.should be_empty
456 455 end
457 456 end
458 457 end
6 spec/spec_helper.rb
@@ -25,6 +25,12 @@ def self.executable?(path)
25 25
26 26 include WebMock::API
27 27
  28 +def stderr
  29 + $stderr.rewind
  30 + # some systems might redirect warnings to stderr
  31 + [$stderr,$terminal].map(&:read).delete_if{|x| x.strip.empty?}.join(' ')
  32 +end
  33 +
28 34 module Commander::UI
29 35 alias :enable_paging_old :enable_paging
30 36 def enable_paging

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.