Module: Agentd::CLIHelpers

Instance Method Summary collapse

Instance Method Details

#build_agent(opts) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/agentd/cli.rb', line 16

def build_agent(opts)
  key = opts[:api_key] || Agentd.api_key
  if key.nil?
    say "Error: --api-key, AGENTD_API_KEY env var, or ~/.agentd/config.json required", :red
    exit 1
  end
  Agent.new(api_key: key, endpoint: opts[:endpoint] || Agentd.endpoint)
end

#build_client(opts, api_key_required: true) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/agentd/cli.rb', line 7

def build_client(opts, api_key_required: true)
  key = opts[:api_key] || Agentd.api_key
  if api_key_required && key.nil?
    say "Error: --api-key, AGENTD_API_KEY env var, or ~/.agentd/config.json required", :red
    exit 1
  end
  Client.new(api_key: key, endpoint: opts[:endpoint] || Agentd.endpoint)
end

#format_json(obj) ⇒ Object



25
26
27
# File 'lib/agentd/cli.rb', line 25

def format_json(obj)
  JSON.pretty_generate(obj)
end

#status_color(status) ⇒ Object



29
30
31
# File 'lib/agentd/cli.rb', line 29

def status_color(status)
  { "done" => :green, "failed" => :red, "running" => :yellow }.fetch(status, :white)
end