idcfcloud 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.codeclimate.yml +21 -0
- data/.gitignore +56 -0
- data/.rubocop.yml +26 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +91 -0
- data/Rakefile +8 -0
- data/bin/idcfcloud +17 -0
- data/config/config_sample.ini +16 -0
- data/exe/idcfcloud +4 -0
- data/idcfcloud.gemspec +43 -0
- data/lib/idcf/cli/conf/conf.yml +10 -0
- data/lib/idcf/cli/conf/const.rb +37 -0
- data/lib/idcf/cli/conf/service/.gitkeep +0 -0
- data/lib/idcf/cli/controller/base.rb +151 -0
- data/lib/idcf/cli/controller/extend/command.rb +48 -0
- data/lib/idcf/cli/controller/extend/init.rb +17 -0
- data/lib/idcf/cli/controller/extend/override.rb +21 -0
- data/lib/idcf/cli/controller/extend/search_module.rb +54 -0
- data/lib/idcf/cli/controller/ilb.rb +62 -0
- data/lib/idcf/cli/controller/include/command.rb +106 -0
- data/lib/idcf/cli/controller/include/init.rb +21 -0
- data/lib/idcf/cli/controller/include/override.rb +30 -0
- data/lib/idcf/cli/controller/include/sdk.rb +83 -0
- data/lib/idcf/cli/controller/include/util.rb +101 -0
- data/lib/idcf/cli/controller/include/validate.rb +79 -0
- data/lib/idcf/cli/controller/your.rb +57 -0
- data/lib/idcf/cli/error/cli_error.rb +11 -0
- data/lib/idcf/cli/extend/configure.rb +71 -0
- data/lib/idcf/cli/extend/init.rb +13 -0
- data/lib/idcf/cli/extend/update.rb +109 -0
- data/lib/idcf/cli/extend/update_file.rb +53 -0
- data/lib/idcf/cli/gem_ext/thor/init_util.rb +92 -0
- data/lib/idcf/cli/index.rb +71 -0
- data/lib/idcf/cli/lib/convert/formatter/base.rb +21 -0
- data/lib/idcf/cli/lib/convert/formatter/csv_format.rb +115 -0
- data/lib/idcf/cli/lib/convert/formatter/json_format.rb +19 -0
- data/lib/idcf/cli/lib/convert/formatter/table_format.rb +19 -0
- data/lib/idcf/cli/lib/convert/formatter/xml_format.rb +21 -0
- data/lib/idcf/cli/lib/convert/helper.rb +28 -0
- data/lib/idcf/cli/lib/util/ini_conf.rb +67 -0
- data/lib/idcf/cli/lib/util/template.rb +29 -0
- data/lib/idcf/cli/lib/util/yml_conf.rb +37 -0
- data/lib/idcf/cli/service/base.rb +56 -0
- data/lib/idcf/cli/service/ilb/add_server_for_protocol.rb +20 -0
- data/lib/idcf/cli/service/ilb/base_server_for_protocol.rb +111 -0
- data/lib/idcf/cli/service/ilb/delete_server_for_protocol.rb +29 -0
- data/lib/idcf/cli/templates/bash/complement.erb +37 -0
- data/lib/idcf/cli/templates/zsh/complement.erb +46 -0
- data/lib/idcf/cli/validate/custom/init.rb +14 -0
- data/lib/idcf/cli/validate/custom/month_check_validator.rb +39 -0
- data/lib/idcf/cli/validate/custom/require_relation_validator.rb +50 -0
- data/lib/idcf/cli/validate/define/base.rb +36 -0
- data/lib/idcf/cli/validate/define/ilb/base.rb +27 -0
- data/lib/idcf/cli/version.rb +5 -0
- metadata +317 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative './base'
|
2
|
+
require 'idcf/ilb'
|
3
|
+
|
4
|
+
module Idcf
|
5
|
+
module Cli
|
6
|
+
module Controller
|
7
|
+
# ILB
|
8
|
+
class Ilb < Base
|
9
|
+
default_command :help
|
10
|
+
|
11
|
+
class_option :region,
|
12
|
+
type: :string,
|
13
|
+
aliases: '-r',
|
14
|
+
require: true,
|
15
|
+
desc: "region: #{Idcf::Cli::Conf::Const::REGIONS.join('/')}"
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def description
|
19
|
+
'ILB Service'
|
20
|
+
end
|
21
|
+
|
22
|
+
def make_blank_client
|
23
|
+
Idcf::Ilb::Client.new(
|
24
|
+
api_key: '',
|
25
|
+
secret_key: ''
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def resource_classes
|
33
|
+
[
|
34
|
+
Idcf::Ilb::Response,
|
35
|
+
Idcf::Ilb::Resources::Base
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
def responce_classes
|
40
|
+
[
|
41
|
+
Idcf::Ilb::Response
|
42
|
+
]
|
43
|
+
end
|
44
|
+
|
45
|
+
# Create a new client
|
46
|
+
# @param o [Hash] other options
|
47
|
+
# @return [Response] Idcf::Ilb::Client
|
48
|
+
def make_client(o)
|
49
|
+
region = get_region(o)
|
50
|
+
option = {
|
51
|
+
host: get_code_conf("ilb.v1.host.#{region}", o),
|
52
|
+
ssl: o.key?(:no_ssl) ? false : true,
|
53
|
+
verify_ssl: o.key?(:no_vssl) ? false : true
|
54
|
+
}
|
55
|
+
option.merge!(base_options(o))
|
56
|
+
|
57
|
+
Idcf::Ilb::Client.new(option)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'idcf/cli/conf/const'
|
2
|
+
module Idcf
|
3
|
+
module Cli
|
4
|
+
module Controller
|
5
|
+
module Include
|
6
|
+
# command
|
7
|
+
module Command
|
8
|
+
include Comparable
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def convert_arg_json(*args)
|
13
|
+
result = []
|
14
|
+
args.each do |v|
|
15
|
+
begin
|
16
|
+
result << JSON.parse(v, symbolize_names: true)
|
17
|
+
rescue
|
18
|
+
result << v
|
19
|
+
end
|
20
|
+
end
|
21
|
+
result
|
22
|
+
end
|
23
|
+
|
24
|
+
# check params
|
25
|
+
#
|
26
|
+
# @param mcs [Array] module classes
|
27
|
+
# @option mcs [Object] not namespace class name => model class object
|
28
|
+
# @param command [String]
|
29
|
+
# @param *args [Array]
|
30
|
+
# @raise
|
31
|
+
def check_params(mcs, command, *args)
|
32
|
+
m_class = nil
|
33
|
+
mcs.each do |k, v|
|
34
|
+
m_class = v if k == command.to_s
|
35
|
+
end
|
36
|
+
if m_class.nil?
|
37
|
+
settings = load_command_setting(command)
|
38
|
+
between_param?(settings[:params], args.size)
|
39
|
+
else
|
40
|
+
between_param?(m_class.params, args.size)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_command_setting(command)
|
45
|
+
fn = self.class.to_s.underscore.split('/').pop
|
46
|
+
cm = command.to_sym
|
47
|
+
dir = Idcf::Cli::Conf::Const::CMD_FILE_DIR
|
48
|
+
ext = Idcf::Cli::Conf::Const::CMD_FILE_EXT
|
49
|
+
path = "#{dir}/#{fn}.#{ext}"
|
50
|
+
Idcf::Cli::Lib::Util::YmlConf.new(path).find(cm)
|
51
|
+
end
|
52
|
+
|
53
|
+
# between params
|
54
|
+
#
|
55
|
+
# @param params [Array]
|
56
|
+
# @param arg_size [int]
|
57
|
+
# @raise
|
58
|
+
def between_param?(params, arg_size)
|
59
|
+
p_cnt = params.nil? ? 0 : params.size
|
60
|
+
return true if method_rest?(params)
|
61
|
+
opt_cnt = method_option_cnt(params)
|
62
|
+
|
63
|
+
min = p_cnt - opt_cnt
|
64
|
+
msg = format('Argument: %s', self.class.make_param_s(params))
|
65
|
+
|
66
|
+
return if arg_size.between?(min, p_cnt)
|
67
|
+
raise Idcf::Cli::CliError, msg
|
68
|
+
end
|
69
|
+
|
70
|
+
# is rest
|
71
|
+
#
|
72
|
+
# @param params [Array]
|
73
|
+
# @return Boolean
|
74
|
+
def method_rest?(params)
|
75
|
+
unless params.nil?
|
76
|
+
params.each do |param|
|
77
|
+
case param[:arg_type]
|
78
|
+
when 'rest'
|
79
|
+
return true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
false
|
84
|
+
end
|
85
|
+
|
86
|
+
# option count
|
87
|
+
#
|
88
|
+
# @param params [Array]
|
89
|
+
# @return int
|
90
|
+
def method_option_cnt(params)
|
91
|
+
result = 0
|
92
|
+
unless params.nil?
|
93
|
+
params.each do |param|
|
94
|
+
case param[:arg_type]
|
95
|
+
when 'opt'
|
96
|
+
result += 1
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
result
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative './override'
|
2
|
+
require_relative './validate'
|
3
|
+
require_relative './command'
|
4
|
+
require_relative './util'
|
5
|
+
require_relative './sdk'
|
6
|
+
module Idcf
|
7
|
+
module Cli
|
8
|
+
module Controller
|
9
|
+
module Include
|
10
|
+
# init load
|
11
|
+
module Init
|
12
|
+
include Override
|
13
|
+
include Validate
|
14
|
+
include Command
|
15
|
+
include Util
|
16
|
+
include Sdk
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Idcf
|
2
|
+
module Cli
|
3
|
+
module Controller
|
4
|
+
module Include
|
5
|
+
# override methods
|
6
|
+
module Override
|
7
|
+
protected
|
8
|
+
|
9
|
+
# Create a new client
|
10
|
+
#
|
11
|
+
# @param _o [Hash] other options
|
12
|
+
# @return [Response] Mixed
|
13
|
+
def make_client(_o)
|
14
|
+
raise Idcf::Cli::CliError, 'Required override'
|
15
|
+
end
|
16
|
+
|
17
|
+
# sdk do
|
18
|
+
#
|
19
|
+
# @param _command [String]
|
20
|
+
# @param *_args [Array]
|
21
|
+
# @param o [Hash] options
|
22
|
+
# @return String
|
23
|
+
def do_sdk(_command, *_args, _o)
|
24
|
+
raise Idcf::Cli::CliError, 'Requre override'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Idcf
|
2
|
+
module Cli
|
3
|
+
module Controller
|
4
|
+
module Include
|
5
|
+
# sdk
|
6
|
+
module Sdk
|
7
|
+
protected
|
8
|
+
|
9
|
+
def do_sdk(client, command, *args, _o)
|
10
|
+
result = client_send(client, command, *args)
|
11
|
+
return result if result.is_a?(Hash)
|
12
|
+
|
13
|
+
if result.class == Array
|
14
|
+
result_arr = []
|
15
|
+
result.each do |v|
|
16
|
+
result_arr << resource_ext(v)
|
17
|
+
end
|
18
|
+
|
19
|
+
return result_arr
|
20
|
+
end
|
21
|
+
|
22
|
+
resource_ext(result)
|
23
|
+
end
|
24
|
+
|
25
|
+
def client_send(client, command, *args)
|
26
|
+
arg = set_headers(client.public_method(command.to_sym), *args.dup)
|
27
|
+
|
28
|
+
client.__send__(command.to_sym, *arg)
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_headers(method, *args)
|
32
|
+
method.parameters.each do |k, v|
|
33
|
+
case v[1].to_s
|
34
|
+
when 'attributes'
|
35
|
+
args[k] = {} unless args[k].class == Hash
|
36
|
+
when 'headers'
|
37
|
+
args[k] = {} unless args[k].class == Hash
|
38
|
+
args[k].merge!(Idcf::Cli::Conf::Const::HEADERS)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
args
|
42
|
+
end
|
43
|
+
|
44
|
+
def resource_ext(val)
|
45
|
+
return val unless classes?(val, resource_classes)
|
46
|
+
return val.body if classes?(val, responce_classes)
|
47
|
+
result = {}
|
48
|
+
val.instance_variables.each do |pn_sym|
|
49
|
+
pn = pn_sym.to_s
|
50
|
+
next if pn == '@client'
|
51
|
+
result[pn.gsub(/\A@+/, '')] = val.instance_variable_get(pn)
|
52
|
+
end
|
53
|
+
result
|
54
|
+
end
|
55
|
+
|
56
|
+
def classes?(val, classes)
|
57
|
+
classes.each do |cl|
|
58
|
+
return true if val.is_a?(cl)
|
59
|
+
end
|
60
|
+
false
|
61
|
+
end
|
62
|
+
|
63
|
+
def resource_classes
|
64
|
+
[]
|
65
|
+
end
|
66
|
+
|
67
|
+
def responce_classes
|
68
|
+
[]
|
69
|
+
end
|
70
|
+
|
71
|
+
def base_options(o)
|
72
|
+
{}.tap do |result|
|
73
|
+
sec = get_profile(o)
|
74
|
+
[:api_key, :secret_key].each do |v|
|
75
|
+
result[v] = o.key?(v) ? o[v] : get_user_conf(v.to_s, sec)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Idcf
|
2
|
+
module Cli
|
3
|
+
module Controller
|
4
|
+
module Include
|
5
|
+
# util
|
6
|
+
module Util
|
7
|
+
protected
|
8
|
+
|
9
|
+
# get user config value
|
10
|
+
#
|
11
|
+
# @param name [String]
|
12
|
+
# @param profile [String]
|
13
|
+
# @return String or Hash
|
14
|
+
# @raise
|
15
|
+
def get_user_conf(name, profile = 'default')
|
16
|
+
return @config.find(name, profile) if @config
|
17
|
+
@config = make_user_conf
|
18
|
+
msg = 'Run the command `configure`'
|
19
|
+
raise Idcf::Cli::CliError, msg unless @config
|
20
|
+
|
21
|
+
@config.find(name, profile)
|
22
|
+
end
|
23
|
+
|
24
|
+
def make_user_conf
|
25
|
+
[
|
26
|
+
Idcf::Cli::Conf::Const::USER_CONF_PATH,
|
27
|
+
Idcf::Cli::Conf::Const::USER_CONF_GLOBAL
|
28
|
+
].each do |v|
|
29
|
+
result = Idcf::Cli::Lib::Util::IniConf.new(v)
|
30
|
+
return result unless result.load_error?
|
31
|
+
end
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
# get code setting value
|
36
|
+
#
|
37
|
+
# @param path [String]
|
38
|
+
# @return String or Hash
|
39
|
+
# @raise
|
40
|
+
def get_code_conf(path, o)
|
41
|
+
profile = get_profile(o)
|
42
|
+
|
43
|
+
return get_user_conf(path, profile)
|
44
|
+
rescue
|
45
|
+
return @code_conf.find(path) if @code_conf
|
46
|
+
f_path = Idcf::Cli::Conf::Const::CODE_CONF_PATH
|
47
|
+
@code_conf = Idcf::Cli::Lib::Util::YmlConf.new(f_path)
|
48
|
+
@code_conf.find(path)
|
49
|
+
end
|
50
|
+
|
51
|
+
# get profile
|
52
|
+
#
|
53
|
+
# @param o [Hash] options
|
54
|
+
# @return String
|
55
|
+
def get_profile(o)
|
56
|
+
o[:profile] || 'default'
|
57
|
+
end
|
58
|
+
|
59
|
+
# get region
|
60
|
+
#
|
61
|
+
# @param o [Hash] options
|
62
|
+
# @return String
|
63
|
+
def get_region(o)
|
64
|
+
return o[:region] if o[:region]
|
65
|
+
region = get_user_conf('region')
|
66
|
+
region.empty? ? 'default' : region
|
67
|
+
rescue
|
68
|
+
'default'
|
69
|
+
end
|
70
|
+
|
71
|
+
# make result string
|
72
|
+
#
|
73
|
+
# @param data [Hash]
|
74
|
+
# @param err_f [Boolean]
|
75
|
+
# @param o [Hash]
|
76
|
+
# @return Stirng
|
77
|
+
def make_result_str(data, err_f, o)
|
78
|
+
message = data.class == Hash ? data[:message] : {}
|
79
|
+
f = output_format(o, message)
|
80
|
+
Idcf::Cli::Lib::Convert::Helper.new.format(data, err_f, f)
|
81
|
+
end
|
82
|
+
|
83
|
+
# output format
|
84
|
+
#
|
85
|
+
# @param o [Hash] options
|
86
|
+
# @param message [Hash] Validate Hash
|
87
|
+
# @return String
|
88
|
+
def output_format(o, message)
|
89
|
+
default_output = get_code_conf('output', o)
|
90
|
+
if message.class == Hash && !message[:output].nil?
|
91
|
+
return default_output
|
92
|
+
end
|
93
|
+
|
94
|
+
f = o[:output]
|
95
|
+
f.nil? ? default_output : f
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
require 'idcf/cli/conf/const'
|
4
|
+
|
5
|
+
module Idcf
|
6
|
+
module Cli
|
7
|
+
module Controller
|
8
|
+
module Include
|
9
|
+
# validate methods
|
10
|
+
module Validate
|
11
|
+
protected
|
12
|
+
|
13
|
+
# validate do
|
14
|
+
#
|
15
|
+
# @param o [Hahs]
|
16
|
+
# @return Hash or nil
|
17
|
+
def do_validate(o)
|
18
|
+
err = first_validate(o)
|
19
|
+
return nil if err.empty?
|
20
|
+
make_validation_error(err)
|
21
|
+
end
|
22
|
+
|
23
|
+
# first validate
|
24
|
+
#
|
25
|
+
# @param o [Hash] options
|
26
|
+
# @return Hash or nil
|
27
|
+
def first_validate(o)
|
28
|
+
validator = make_validate(o, @cmd)
|
29
|
+
validator.valid? ? [] : validator.errors.messages
|
30
|
+
end
|
31
|
+
|
32
|
+
# make validate
|
33
|
+
#
|
34
|
+
# @paeram o [Hash] options
|
35
|
+
# @param command [String]
|
36
|
+
# @return ActiveModel
|
37
|
+
def make_validate(o, command)
|
38
|
+
service = self.class.to_s.underscore.split('/').pop
|
39
|
+
path = Idcf::Cli::Conf::Const::VALIDATOR_DIR_PATH
|
40
|
+
paths = [
|
41
|
+
"#{path}/#{service}/#{command}",
|
42
|
+
"#{path}/#{service}/base",
|
43
|
+
"#{path}/base"
|
44
|
+
]
|
45
|
+
load_validate(paths, o)
|
46
|
+
end
|
47
|
+
|
48
|
+
def load_validate(paths, o)
|
49
|
+
paths.each do |path|
|
50
|
+
begin
|
51
|
+
require path
|
52
|
+
return path.classify.constantize.new(o)
|
53
|
+
rescue LoadError
|
54
|
+
next
|
55
|
+
end
|
56
|
+
end
|
57
|
+
raise Idcf::Cli::CliError, 'Validate load error'
|
58
|
+
end
|
59
|
+
|
60
|
+
# make validation error
|
61
|
+
#
|
62
|
+
# @override
|
63
|
+
# @param errors [Hash]
|
64
|
+
# @return Hash
|
65
|
+
def make_validation_error(errors)
|
66
|
+
err = {}
|
67
|
+
errors.each do |k, v|
|
68
|
+
err[k] = "#{Idcf::Cli::Conf::Const::LOCAL_ERROR_PREFIX}#{v}"
|
69
|
+
end
|
70
|
+
result = make_base_response
|
71
|
+
result[:status] = 400
|
72
|
+
result[:message] = err
|
73
|
+
result
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative './base'
|
2
|
+
require 'idcf/your'
|
3
|
+
|
4
|
+
module Idcf
|
5
|
+
module Cli
|
6
|
+
module Controller
|
7
|
+
# Your
|
8
|
+
class Your < Base
|
9
|
+
default_command :help
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def description
|
13
|
+
'Your Service'
|
14
|
+
end
|
15
|
+
|
16
|
+
def make_blank_client
|
17
|
+
Idcf::Your::Client.new(
|
18
|
+
api_key: '',
|
19
|
+
secret_key: ''
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def make_table_data(data)
|
27
|
+
data['data']
|
28
|
+
end
|
29
|
+
|
30
|
+
def resource_classes
|
31
|
+
[
|
32
|
+
Idcf::Your::Response
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
36
|
+
def responce_classes
|
37
|
+
[
|
38
|
+
Idcf::Your::Response
|
39
|
+
]
|
40
|
+
end
|
41
|
+
|
42
|
+
# Create a new client
|
43
|
+
# @param o [Hash] other options
|
44
|
+
# @return [Response] Idcf::Ilb::Client
|
45
|
+
def make_client(o)
|
46
|
+
option = {
|
47
|
+
host: get_code_conf('your.v1.host', o),
|
48
|
+
verify_ssl: o.key?(:no_vssl) ? false : true
|
49
|
+
}
|
50
|
+
option.merge!(base_options(o))
|
51
|
+
|
52
|
+
Idcf::Your::Client.new(option)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'idcf/cli/conf/const'
|
2
|
+
require 'idcf/cli/lib/util/ini_conf'
|
3
|
+
|
4
|
+
module Idcf
|
5
|
+
module Cli
|
6
|
+
module Extend
|
7
|
+
# configure settings
|
8
|
+
module Configure
|
9
|
+
protected
|
10
|
+
|
11
|
+
def do_configure(o)
|
12
|
+
path = configure_path(o)
|
13
|
+
config = Idcf::Cli::Lib::Util::IniConf.new(path)
|
14
|
+
profiles = []
|
15
|
+
if o[:profile] != 'default' && !check_profile?(config, 'default')
|
16
|
+
profiles << 'default'
|
17
|
+
end
|
18
|
+
profiles << o[:profile]
|
19
|
+
config = configure_input(config, profiles)
|
20
|
+
config.write(path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure_path(o)
|
24
|
+
cls = Idcf::Cli::Conf::Const
|
25
|
+
result = o[:global] ? cls::USER_CONF_GLOBAL : cls::USER_CONF_PATH
|
26
|
+
File.expand_path(result)
|
27
|
+
end
|
28
|
+
|
29
|
+
def check_profile?(config, name)
|
30
|
+
conf = config[name]
|
31
|
+
return false if conf.nil?
|
32
|
+
Idcf::Cli::Conf::Const::USER_CONF_ITEMS.each do |k, _v|
|
33
|
+
return false if conf[k.to_s].strip.empty?
|
34
|
+
end
|
35
|
+
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
def configure_input(config, profiles)
|
40
|
+
profiles.each do |profile|
|
41
|
+
dt = config[profile] || {}
|
42
|
+
Idcf::Cli::Conf::Const::USER_CONF_ITEMS.each do |k, v|
|
43
|
+
nd = dt[k.to_s].nil? ? '' : dt[k.to_s]
|
44
|
+
msg = "#{profile}:#{k}[#{nd.empty? ? 'NONE' : nd}] : "
|
45
|
+
dt[k.to_s] = configure_qa_dialog(msg, nd, v)
|
46
|
+
end
|
47
|
+
config[profile] = dt
|
48
|
+
end
|
49
|
+
config
|
50
|
+
end
|
51
|
+
|
52
|
+
def configure_qa_dialog(msg, nd, setting)
|
53
|
+
loop do
|
54
|
+
puts msg
|
55
|
+
res = STDIN.gets.strip
|
56
|
+
next unless !res.empty? || !nd.empty?
|
57
|
+
result = res.empty? ? nd : res
|
58
|
+
return result if confirmation_at_qa_preference?(result, setting)
|
59
|
+
puts "from this [#{setting.join('/')}]"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def confirmation_at_qa_preference?(val, setting)
|
64
|
+
return true if setting.nil?
|
65
|
+
return true if Regexp.new("\\A(#{setting.join('|')})\\Z") =~ val
|
66
|
+
false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|