Class: Central::Cli::Etcd::ListCommand

Inherits:
Clamp::Command
  • Object
show all
Includes:
Common, Common, StackOptions
Defined in:
lib/central/cli/etcd/list_command.rb

Instance Method Summary collapse

Methods included from Common

#validate_key

Methods included from StackOptions

included

Methods included from Common

#access_token=, #add_master, #api_url, #api_url=, #clear_current_stack, #client, #current_master, #current_master=, #current_master_index, #current_stack, #current_stack=, #ensure_custom_ssl_ca, #require_api_url, #require_current_stack, #require_token, #reset_client, #save_settings, #settings, #settings_filename

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/central/cli/etcd/list_command.rb', line 13

def execute
  require_api_url
  token = require_token
  validate_key

  opts = []
  opts << 'recursive=true' if recursive?
  response = client(token).get("etcd/#{current_stack}/#{key}?#{opts.join('&')}")
  if response['children']
    children = response['children'].map { |c| c['key'] }
    puts children.join("\n")
  elsif response['value']
    abort 'Not a directory'
  elsif response['error']
    abort response['error']
  end
end