class UwsgiItClient::CLI

Public Instance Methods

containers(id = nil) click to toggle source
# File lib/uwsgi_it_client/cli.rb, line 82
def containers id = nil
  client = UwsgiItClient.new login_params
  result = id && client.container(id) || client.containers
  manage_action_result result
end
current_dir_settings() click to toggle source
# File lib/uwsgi_it_client/cli.rb, line 29
def current_dir_settings
  load_settings File.join Dir.pwd, '.uwsgi_it_client.yml'
end
distros() click to toggle source
# File lib/uwsgi_it_client/cli.rb, line 95
def distros
  client = UwsgiItClient.new login_params
  manage_action_result client.distros
end
domains() click to toggle source
# File lib/uwsgi_it_client/cli.rb, line 107
def domains
  client = UwsgiItClient.new login_params
  manage_action_result client.domains
end
home_settings() click to toggle source
# File lib/uwsgi_it_client/cli.rb, line 25
def home_settings
  load_settings File.expand_path('~/.uwsgi_it_client.yml')
end
load_settings(file) click to toggle source
# File lib/uwsgi_it_client/cli.rb, line 33
def load_settings(file)
  if File.file? file
    hash = YAML.load_file file
    ActiveSupport::HashWithIndifferentAccess.new hash
  end
end
login_params() click to toggle source
# File lib/uwsgi_it_client/cli.rb, line 13
def login_params
  {
    username: options[:username] || settings[:username],
    password: options[:password] || settings[:password],
    url:      options[:api]      || settings[:api]
  }
end
manage_action_result(result) { |response| ... } click to toggle source
# File lib/uwsgi_it_client/cli.rb, line 48
def manage_action_result result
  if result.response.code.to_i != 200
    print "Cannot execute the desired action. The server responded with:"
    print status: result.response.code.to_i, description: result.response.message
  else
    response = result.parsed_response.try(:symbolize_keys) || result.parsed_response.map(&:symbolize_keys)
    if block_given?
      yield response
    else
      print response
    end
  end
end
me() click to toggle source
# File lib/uwsgi_it_client/cli.rb, line 70
def me
  client = UwsgiItClient.new login_params
  manage_action_result client.me
end
print(object) click to toggle source
settings() click to toggle source
# File lib/uwsgi_it_client/cli.rb, line 21
def settings
  current_dir_settings or home_settings or ErrorHash.new
end