Module: VMCExtensions

Included in:
Object
Defined in:
lib/cli/core_ext.rb

Instance Method Summary collapse

Instance Method Details



13
14
15
16
# File 'lib/cli/core_ext.rb', line 13

def banner(message)
  say "\n"
  say message
end

#blank?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/cli/core_ext.rb', line 49

def blank?
  self.to_s.blank?
end

#clear(size = 80) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/cli/core_ext.rb', line 29

def clear(size=80)
  return unless VMC::Cli::Config.output
  VMC::Cli::Config.output.print("\r")
  VMC::Cli::Config.output.print(" " * size)
  VMC::Cli::Config.output.print("\r")
  #VMC::Cli::Config.output.flush
end

#display(message, nl = true) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/cli/core_ext.rb', line 18

def display(message, nl=true)
  if nl
    say message
  else
    if VMC::Cli::Config.output
      VMC::Cli::Config.output.print(message)
      VMC::Cli::Config.output.flush
    end
  end
end

#err(message, prefix = 'Error: ') ⇒ Object

Raises:



37
38
39
# File 'lib/cli/core_ext.rb', line 37

def err(message, prefix='Error: ')
  raise VMC::Cli::CliExit, "#{prefix}#{message}"
end

#header(message, filler = '-') ⇒ Object



7
8
9
10
11
# File 'lib/cli/core_ext.rb', line 7

def header(message, filler = '-')
  say "\n"
  say message
  say filler.to_s * message.size
end

#pretty_size(size, prec = 1) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/cli/core_ext.rb', line 64

def pretty_size(size, prec=1)
  return 'NA' unless size
  return "#{size}B" if size < 1024
  return sprintf("%.#{prec}fK", size/1024.0) if size < (1024*1024)
  return sprintf("%.#{prec}fM", size/(1024.0*1024.0)) if size < (1024*1024*1024)
  return sprintf("%.#{prec}fG", size/(1024.0*1024.0*1024.0))
end

#quit(message = nil) ⇒ Object



45
46
47
# File 'lib/cli/core_ext.rb', line 45

def quit(message = nil)
  raise VMC::Cli::GracefulExit, message
end

#say(message) ⇒ Object



3
4
5
# File 'lib/cli/core_ext.rb', line 3

def say(message)
  VMC::Cli::Config.output.puts(message) if VMC::Cli::Config.output
end

#uptime_string(delta) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/cli/core_ext.rb', line 53

def uptime_string(delta)
  num_seconds = delta.to_i
  days = num_seconds / (60 * 60 * 24);
  num_seconds -= days * (60 * 60 * 24);
  hours = num_seconds / (60 * 60);
  num_seconds -= hours * (60 * 60);
  minutes = num_seconds / 60;
  num_seconds -= minutes * 60;
  "#{days}d:#{hours}h:#{minutes}m:#{num_seconds}s"
end

#warn(msg) ⇒ Object



41
42
43
# File 'lib/cli/core_ext.rb', line 41

def warn(msg)
  say "#{"[WARNING]".yellow} #{msg}"
end