Class: Niman::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/niman/shell.rb

Instance Method Summary collapse

Constructor Details

#initializeShell

Returns a new instance of Shell.



5
6
7
# File 'lib/niman/shell.rb', line 5

def initialize
  @platform = Niman::Platform.new(RUBY_PLATFORM)
end

Instance Method Details

#create_file(path, content) ⇒ Object



36
37
38
39
40
# File 'lib/niman/shell.rb', line 36

def create_file(path, content)
  File.open(File.expand_path(path), 'w') do |handle|
    handle.write(content)
  end
end

#exec(command, use_sudo = false) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/niman/shell.rb', line 19

def exec(command, use_sudo=false)
  if use_sudo
    `sudo #{command}`
  else
    `#{command}`
  end
end

#osObject



9
10
11
12
13
14
15
16
17
# File 'lib/niman/shell.rb', line 9

def os
  if @platform.linux?
    variant = @platform.linux_variant(-> (fn){ File.exists?(fn)}, 
                            -> (fn){ File.read(fn)})
    variant[:family]
  else
    raise Niman::UnsupportedOSError
  end
end


27
28
29
30
31
32
33
34
# File 'lib/niman/shell.rb', line 27

def print(message, type)
  case type
  when :error
    STDERR.puts message
  else
    STDOUT.puts message
  end
end