Class: Bcome::System::Local

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/objects/system/local.rb

Instance Method Summary collapse

Instance Method Details

#command(raw_command) ⇒ Object



26
27
28
# File 'lib/objects/system/local.rb', line 26

def command(raw_command)
  ::Bcome::Command::Local.run(raw_command)
end

#execute_command(raw_command, print_out_command = false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/objects/system/local.rb', line 5

def execute_command(raw_command, print_out_command = false)
  puts "\n> #{raw_command}".bc_blue + "\n" if print_out_command

  local_command = command(raw_command)
  if local_command.failed? && !in_console_session?
    # we fail fast if we're not in a console session
    raise Bcome::Exception::FailedToRunLocalCommand, "#{raw_command}. Error: " + local_command.stderr
  end
  local_command
end

#in_console_session?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/objects/system/local.rb', line 16

def in_console_session?
  ::Bcome::Workspace.instance.console_set?
end

#local_userObject



20
21
22
23
24
# File 'lib/objects/system/local.rb', line 20

def local_user
  result = command('whoami')
  result.stdout =~ /(.+)\n/
  Regexp.last_match(1)
end