Module: Blockspring::CLI::Helpers

Included in:
Auth, Command::Base
Defined in:
lib/blockspring/cli/helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.error_with_failureObject



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(message)
  if Blockspring::CLI::Helpers.error_with_failure
    display("failed")
    Blockspring::CLI::Helpers.error_with_failure = false
  end
  $stderr.puts(format_with_bang(message))
  exit(1)
end

#format_with_bang(message) ⇒ Object



30
31
32
33
# File 'lib/blockspring/cli/helpers.rb', line 30

def format_with_bang(message)
  return '' if message.to_s.strip == ""
  " !    " + message.split("\n").join("\n !    ")
end

#home_directoryObject



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(message="", new_line=true)
  return if message.to_s.strip == ""
  display(format_with_bang(message), 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