Module: ParamsHelper

Includes:
SolanoConstant
Included in:
Solano::SolanoCli
Defined in:
lib/solano/cli/params_helper.rb

Overview

Copyright © 2014 Solano Labs All Rights Reserved

Instance Method Summary collapse

Instance Method Details

#default_host(params) ⇒ Object



6
7
8
# File 'lib/solano/cli/params_helper.rb', line 6

def default_host params
  params['host'] || ENV['SOLANO_CLIENT_HOST'] || ENV['TDDIUM_CLIENT_HOST'] || 'ci.predix.io'
end

#default_insecure(params) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/solano/cli/params_helper.rb', line 26

def default_insecure params
  if params.key?('insecure')
    params['insecure']
  elsif ENV['SOLANO_CLIENT_INSECURE'] || ENV['TDDIUM_CLIENT_INSECURE']
    true
  else
    false
  end
end

#default_port(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/solano/cli/params_helper.rb', line 10

def default_port params
  if params['port']
    params['port']
  elsif ENV['SOLANO_CLIENT_PORT']
    ENV['SOLANO_CLIENT_PORT'].to_i
  elsif ENV['TDDIUM_CLIENT_PORT']
    ENV['TDDIUM_CLIENT_PORT'].to_i
  else
    nil
  end
end

#default_proto(params) ⇒ Object



22
23
24
# File 'lib/solano/cli/params_helper.rb', line 22

def default_proto params
  params['proto'] || ENV['SOLANO_CLIENT_PROTO'] || ENV['TDDIUM_CLIENT_PROTO'] || 'https'
end

#displayObject



59
60
61
62
63
64
65
# File 'lib/solano/cli/params_helper.rb', line 59

def display
  store_params = load_params(false)
  say 'Options:'
  store_params.each do |k, v|
    say "   #{k.capitalize}:\t#{v}"
  end
end

#load_params(defaults = true) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/solano/cli/params_helper.rb', line 36

def load_params(defaults=true)
  params = {}
  if File.exists?(Default::PARAMS_PATH) then
    File.open(Default::PARAMS_PATH, 'r') do |file|
      params = JSON.parse file.read
    end
  elsif !defaults then
    abort Text::Process::NOT_SAVED_OPTIONS
  end
  return params
end

#write_params(options) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/solano/cli/params_helper.rb', line 48

def write_params options
  begin
    File.open(Default::PARAMS_PATH, File::CREAT|File::TRUNC|File::RDWR, 0600) do |file|
      file.write options.to_json
    end
    say Text::Process::OPTIONS_SAVED
  rescue Exception => e
    say Text::Error::OPTIONS_NOT_SAVED
  end
end