Method: CLISplash::Commands#execute

Defined in:
lib/splash/cli/commands.rb

#execute(name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/splash/cli/commands.rb', line 33

def execute(name)
  log = get_logger
  log.level = :fatal if options[:quiet]
  if is_root? then
    if options[:hostname] then
      options[:hostname] = Socket.gethostname if options[:hostname] == 'hostname'
      splash_exit({ :case => :options_incompatibility, :more => '--hostname forbidden with delagate commands'}) if get_config.commands[name.to_sym][:delegate_to]
      log.info "Remote Splash configured commands on #{options[:hostname]}:"
      log.info "ctrl+c for interrupt"
      begin
        transport = get_default_client
        if transport.class == Hash  and transport.include? :case then
          splash_exit transport
        else
          if options[:ack] then
            res = transport.execute({ :verb => :ack_command,
                                  payload: {:name => name},
                                  :return_to => "splash.#{Socket.gethostname}.returncli",
                                  :queue => "splash.#{options[:hostname]}.input" })
            res[:more] = "Remote command : :ack_command OK"
            splash_exit res
          else
            res = transport.execute({ :verb => :execute_command,
                                payload: {:name => name},
                                :return_to => "splash.#{Socket.gethostname}.returncli",
                                :queue => "splash.#{options[:hostname]}.input" })
          end
        end
      rescue Interrupt
        splash_exit case: :interrupt, more: "Remote command exection"
      end
      log.receive "Command execute confirmation"
      res[:more] = "Remote command : :execute_command Scheduled"
      splash_exit res
    else
      command =  CommandWrapper::new(name)
      if options[:ack] then
        splash_exit command.ack
      end
      acase = command.call_and_notify trace: options[:trace], notify: options[:notify], callback: options[:callback]
      splash_exit acase
    end
  else
    splash_exit case: :not_root, :more => "Command execution"
  end
end