Class: Vixen::CommandLine::Base
- Inherits:
-
Object
- Object
- Vixen::CommandLine::Base
show all
- Defined in:
- lib/vixen/command_line/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(context) ⇒ Base
Returns a new instance of Base.
4
5
6
7
|
# File 'lib/vixen/command_line/base.rb', line 4
def initialize(context)
@start = Time.now
@context = context
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
2
3
4
|
# File 'lib/vixen/command_line/base.rb', line 2
def context
@context
end
|
#start ⇒ Object
Returns the value of attribute start.
2
3
4
|
# File 'lib/vixen/command_line/base.rb', line 2
def start
@start
end
|
Instance Method Details
#elapsed_time ⇒ Object
9
10
11
|
# File 'lib/vixen/command_line/base.rb', line 9
def elapsed_time
"[%s]" % (Time.at(Time.now - start).utc.strftime '%T')
end
|
#host ⇒ Object
29
30
31
32
|
# File 'lib/vixen/command_line/base.rb', line 29
def host
return @host unless @host.nil?
@host = context[:host] || Vixen.local_connect
end
|
#new_line_after ⇒ Object
13
14
15
16
17
|
# File 'lib/vixen/command_line/base.rb', line 13
def new_line_after
val = yield if block_given?
$stdout.puts
val
end
|
#print(message, *args) ⇒ Object
19
20
21
22
23
|
# File 'lib/vixen/command_line/base.rb', line 19
def print(message, *args)
timed_message = "\r \r#{elapsed_time} " + message.to_s
$stdout.print timed_message, args
$stdout.flush
end
|
#puts(message, *args) ⇒ Object
25
26
27
|
# File 'lib/vixen/command_line/base.rb', line 25
def puts(message, *args)
new_line_after { print(message, args) }
end
|
#vms ⇒ Object
34
35
36
37
38
|
# File 'lib/vixen/command_line/base.rb', line 34
def vms
return @vms unless @vms.nil?
context[:vms] ||= host.running_vms
@vms = context[:vms]
end
|