Module: Blockspring::CLI::Helpers
- Included in:
- Auth, Command::Base
- Defined in:
- lib/blockspring/cli/helpers.rb
Class Method Summary collapse
Instance Method Summary collapse
- #display(msg = "", new_line = true) ⇒ Object
- #error(message) ⇒ Object
- #format_with_bang(message) ⇒ Object
- #home_directory ⇒ Object
- #longest(items) ⇒ Object
- #output_with_bang(message = "", new_line = true) ⇒ Object
- #running_on_a_mac? ⇒ Boolean
- #running_on_windows? ⇒ Boolean
Class Method Details
.error_with_failure ⇒ Object
49 50 51 |
# File 'lib/blockspring/cli/helpers.rb', line 49 def self.error_with_failure @@error_with_failure ||= false end |
.error_with_failure=(new_error_with_failure) ⇒ Object
53 54 55 |
# File 'lib/blockspring/cli/helpers.rb', line 53 def self.error_with_failure=(new_error_with_failure) @@error_with_failure = new_error_with_failure end |
Instance Method Details
#display(msg = "", new_line = true) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/blockspring/cli/helpers.rb', line 17 def display(msg="", new_line=true) if new_line puts(msg) else print(msg) end $stdout.flush end |
#error(message) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/blockspring/cli/helpers.rb', line 40 def error() if Blockspring::CLI::Helpers.error_with_failure display("failed") Blockspring::CLI::Helpers.error_with_failure = false end $stderr.puts(format_with_bang()) exit(1) end |
#format_with_bang(message) ⇒ Object
30 31 32 33 |
# File 'lib/blockspring/cli/helpers.rb', line 30 def format_with_bang() return '' if .to_s.strip == "" " ! " + .split("\n").join("\n ! ") end |
#home_directory ⇒ Object
5 6 7 |
# File 'lib/blockspring/cli/helpers.rb', line 5 def home_directory running_on_windows? ? ENV['USERPROFILE'].gsub("\\","/") : ENV['HOME'] end |
#longest(items) ⇒ Object
26 27 28 |
# File 'lib/blockspring/cli/helpers.rb', line 26 def longest(items) items.map { |i| i.to_s.length }.sort.last end |
#output_with_bang(message = "", new_line = true) ⇒ Object
35 36 37 38 |
# File 'lib/blockspring/cli/helpers.rb', line 35 def output_with_bang(="", new_line=true) return if .to_s.strip == "" display(format_with_bang(), new_line) end |
#running_on_a_mac? ⇒ Boolean
13 14 15 |
# File 'lib/blockspring/cli/helpers.rb', line 13 def running_on_a_mac? RUBY_PLATFORM =~ /-darwin\d/ end |
#running_on_windows? ⇒ Boolean
9 10 11 |
# File 'lib/blockspring/cli/helpers.rb', line 9 def running_on_windows? RUBY_PLATFORM =~ /mswin32|mingw32/ end |