Module: Bixby::ScriptUtil

Includes:
UseBundle
Included in:
Command, Object
Defined in:
lib/bixby-client/script_util.rb

Defined Under Namespace

Modules: UseBundle

Instance Method Summary collapse

Methods included from UseBundle

#use_bundle

Instance Method Details

#get_json_inputObject

Reads JSON data from STDIN

Returns:

  • (Object)

    data found on STDIN (can be Hash, Array, String, etc)



32
33
34
35
36
# File 'lib/bixby-client/script_util.rb', line 32

def get_json_input
  input = read_stdin()
  input.strip! if input
  (input.nil? or input.empty?) ? {} : MultiJson.load(input)
end

#read_stdinString

Read all available data on STDIN without blocking (i.e., if no data is available, none will be returned)

Returns:

  • (String)

    data



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bixby-client/script_util.rb', line 42

def read_stdin
  buff = []
  while true do
    begin
      buff << STDIN.read_nonblock(64000)
    rescue
      break
    end
  end
  return buff.join('')
end

#systemu(*args) ⇒ Mixlib::ShellOut

Simple wrapper around Mixlib::ShellOut

Parameters:

  • args (Array)

Returns:



59
60
61
62
63
# File 'lib/bixby-client/script_util.rb', line 59

def systemu(*args)
  cmd = Mixlib::ShellOut.new(*args)
  cmd.run_command
  cmd
end