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,109 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
require 'idcf/cli/conf/const'
|
4
|
+
require 'idcf/cli/lib/util/template'
|
5
|
+
require_relative 'update_file'
|
6
|
+
module Idcf
|
7
|
+
module Cli
|
8
|
+
module Extend
|
9
|
+
# update settings
|
10
|
+
module Update
|
11
|
+
protected
|
12
|
+
|
13
|
+
include UpdateFile
|
14
|
+
|
15
|
+
COMP_N = 'complement'.freeze
|
16
|
+
|
17
|
+
def do_update(_o)
|
18
|
+
clients = make_clients
|
19
|
+
writable_setting_file clients.keys
|
20
|
+
infos = {}
|
21
|
+
|
22
|
+
clients.each do |s_name, client|
|
23
|
+
info = make_module_info(client)
|
24
|
+
output_yaml(s_name, info)
|
25
|
+
infos[s_name] = info
|
26
|
+
end
|
27
|
+
output_complement
|
28
|
+
end
|
29
|
+
|
30
|
+
def make_clients
|
31
|
+
{}.tap do |result|
|
32
|
+
self.class.subcommand_classes.each do |k, v|
|
33
|
+
next unless v.ancestors.include?(Idcf::Cli::Controller::Base)
|
34
|
+
client = v.make_blank_client
|
35
|
+
result[k] = client unless client.nil?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def make_module_info(client)
|
41
|
+
{}.tap do |result|
|
42
|
+
module_methods = []
|
43
|
+
client.class.included_modules.each do |m|
|
44
|
+
next unless m.to_s =~ /\AIdcf::.*::ClientExtensions/
|
45
|
+
module_methods.concat(m.instance_methods)
|
46
|
+
end
|
47
|
+
module_methods.each do |method|
|
48
|
+
result[method] = make_method_info(client, method)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def make_method_info(client, method_sym)
|
54
|
+
params = []
|
55
|
+
client.method(method_sym).parameters.each do |param|
|
56
|
+
next if param[0] == :block
|
57
|
+
params << {
|
58
|
+
name: param[1].to_s,
|
59
|
+
arg_type: param[0].to_s
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
{ desc: '', params: params }
|
64
|
+
end
|
65
|
+
|
66
|
+
def output_complement
|
67
|
+
view = Idcf::Cli::Lib::Util::Template.new
|
68
|
+
view.set('variables', make_script_variables)
|
69
|
+
paths = []
|
70
|
+
%w(bash zsh).each do |e|
|
71
|
+
str = view.fetch("#{e}/#{COMP_N}.erb")
|
72
|
+
path = "#{Idcf::Cli::Conf::Const::OUT_DIR}/#{COMP_N}.#{e}"
|
73
|
+
paths << File.expand_path(path)
|
74
|
+
output_complement_file(str, paths.last)
|
75
|
+
end
|
76
|
+
output_notification(paths)
|
77
|
+
end
|
78
|
+
|
79
|
+
def output_notification(paths)
|
80
|
+
notification = Idcf::Cli::Conf::Const::COMP_NOTIFICATION
|
81
|
+
puts format(notification, *paths)
|
82
|
+
end
|
83
|
+
|
84
|
+
def make_script_variables
|
85
|
+
self.class.init
|
86
|
+
make_flat_variables(self.class.subcommand_structure)
|
87
|
+
end
|
88
|
+
|
89
|
+
# bash 3.x
|
90
|
+
#
|
91
|
+
# @param list [Hash]
|
92
|
+
# @param names [Array]
|
93
|
+
# @return Hash
|
94
|
+
def make_flat_variables(list, names = [])
|
95
|
+
{}.tap do |result|
|
96
|
+
name = names.empty? ? 'top' : names.join('_')
|
97
|
+
result[name] = list.keys
|
98
|
+
list.each do |k, v|
|
99
|
+
next unless v.class == Hash
|
100
|
+
names << k
|
101
|
+
result.merge!(make_flat_variables(v, names))
|
102
|
+
names.pop
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'idcf/cli/conf/const'
|
3
|
+
|
4
|
+
module Idcf
|
5
|
+
module Cli
|
6
|
+
module Extend
|
7
|
+
# update file
|
8
|
+
module UpdateFile
|
9
|
+
protected
|
10
|
+
|
11
|
+
def writable_setting_file(services)
|
12
|
+
b_dir = File.expand_path(Idcf::Cli::Conf::Const::CMD_FILE_DIR)
|
13
|
+
FileUtils.mkdir_p(b_dir) unless Dir.exist?(b_dir)
|
14
|
+
writable?(File.dirname(b_dir))
|
15
|
+
|
16
|
+
services.each do |v|
|
17
|
+
path = "#{b_dir}/#{v}.#{Idcf::Cli::Conf::Const::CMD_FILE_EXT}"
|
18
|
+
writable?(File.dirname(path)) if File.exist?(path)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def output_yaml(s_name, data)
|
23
|
+
dir = Idcf::Cli::Conf::Const::CMD_FILE_DIR
|
24
|
+
ext = Idcf::Cli::Conf::Const::CMD_FILE_EXT
|
25
|
+
path = "#{File.expand_path(dir)}/#{s_name}.#{ext}"
|
26
|
+
write_file(path, data.to_yaml)
|
27
|
+
end
|
28
|
+
|
29
|
+
def output_complement_file(str, outpath)
|
30
|
+
dir_path = File.dirname(outpath)
|
31
|
+
unless Dir.exist?(dir_path)
|
32
|
+
writable?(File.dirname(dir_path))
|
33
|
+
Dir.mkdir(dir_path)
|
34
|
+
end
|
35
|
+
writable?(dir_path)
|
36
|
+
|
37
|
+
write_file(outpath, str)
|
38
|
+
end
|
39
|
+
|
40
|
+
def write_file(path, str)
|
41
|
+
File.open(path, 'w') do |f|
|
42
|
+
f.puts(str)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def writable?(path)
|
47
|
+
msg = "Permission error (#{path})"
|
48
|
+
raise Idcf::Cli::CliError, msg unless File.writable?(path)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# Thor extention
|
2
|
+
class Thor
|
3
|
+
class << self
|
4
|
+
# Thor 0.19.4 ( https://github.com/erikhuda/thor/issues/244 )
|
5
|
+
def exit_on_failure?
|
6
|
+
true
|
7
|
+
end
|
8
|
+
|
9
|
+
# initialize settings
|
10
|
+
def init
|
11
|
+
# When initialization is needed, override.
|
12
|
+
end
|
13
|
+
|
14
|
+
# command description
|
15
|
+
#
|
16
|
+
# @return String
|
17
|
+
def description
|
18
|
+
raise Idcf::Cli::CliError, 'Required Override'
|
19
|
+
end
|
20
|
+
|
21
|
+
# register sub command
|
22
|
+
#
|
23
|
+
# @param dir [String] underlayer path
|
24
|
+
# @param parent_dir_path [Stirng]
|
25
|
+
# @return nil
|
26
|
+
def sub_command_regist(under_path, parent_dir_path = '')
|
27
|
+
b_path = module_path
|
28
|
+
Dir.glob(parent_dir_path + "/#{under_path}/*.rb").each do |f|
|
29
|
+
file_name = File.basename(f, '.*')
|
30
|
+
next if file_name == 'base'
|
31
|
+
|
32
|
+
command_regist file_name, "#{b_path}/#{under_path}/#{file_name}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# command regist
|
37
|
+
#
|
38
|
+
# @param command [String]
|
39
|
+
# @param require_path [String]
|
40
|
+
def command_regist(command, require_path)
|
41
|
+
require require_path
|
42
|
+
|
43
|
+
class_const = require_path.classify.constantize
|
44
|
+
class_const.init
|
45
|
+
register class_const,
|
46
|
+
command,
|
47
|
+
"#{command_help_string(command)} [OPTION]",
|
48
|
+
class_const.description
|
49
|
+
end
|
50
|
+
|
51
|
+
def command_help_string(command)
|
52
|
+
result = [command]
|
53
|
+
map.each do |k, v|
|
54
|
+
result << k if v.to_s == command.to_s
|
55
|
+
end
|
56
|
+
result.join('/')
|
57
|
+
end
|
58
|
+
|
59
|
+
# module path
|
60
|
+
#
|
61
|
+
# @return String
|
62
|
+
def module_path
|
63
|
+
class_names = to_s.underscore.split('/')
|
64
|
+
class_names.pop
|
65
|
+
class_names.join('/')
|
66
|
+
end
|
67
|
+
|
68
|
+
def subcommand_structure
|
69
|
+
{}.tap do |result|
|
70
|
+
commands.each do |k, _v|
|
71
|
+
result[k.to_s] = nil
|
72
|
+
end
|
73
|
+
result = subcommand_class_structure(result)
|
74
|
+
|
75
|
+
map.each do |k, v|
|
76
|
+
result[k.to_s] = result[v.to_s] unless result[v.to_s].nil?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
protected
|
82
|
+
|
83
|
+
def subcommand_class_structure(result)
|
84
|
+
subcommand_classes.each do |k, v|
|
85
|
+
commands = v.subcommand_structure
|
86
|
+
result[k.to_s] = nil
|
87
|
+
result[k.to_s] = commands unless commands.empty?
|
88
|
+
end
|
89
|
+
result
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
require 'idcf/cli/conf/const'
|
5
|
+
require 'idcf/cli/error/cli_error'
|
6
|
+
require_relative './version'
|
7
|
+
require_relative './validate/custom/init'
|
8
|
+
require_relative './gem_ext/thor/init_util'
|
9
|
+
require_relative './extend/init'
|
10
|
+
|
11
|
+
module Idcf
|
12
|
+
module Cli
|
13
|
+
# Index
|
14
|
+
class Index < Thor
|
15
|
+
@variables = nil
|
16
|
+
# command alias [alias] => [command]
|
17
|
+
COMMAND_MAPS = {}.freeze
|
18
|
+
|
19
|
+
include Idcf::Cli::Extend::Init
|
20
|
+
|
21
|
+
class << self
|
22
|
+
def init
|
23
|
+
map COMMAND_MAPS
|
24
|
+
sub_command_regist('controller', File.dirname(__FILE__))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(*args)
|
29
|
+
@variables = {}
|
30
|
+
super(*args)
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'init', 'initialize'
|
34
|
+
options global: true,
|
35
|
+
profile: 'default'
|
36
|
+
|
37
|
+
def init
|
38
|
+
configure
|
39
|
+
update
|
40
|
+
rescue => e
|
41
|
+
puts e.message
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'update', 'list update'
|
45
|
+
|
46
|
+
def update
|
47
|
+
do_update(options)
|
48
|
+
rescue => e
|
49
|
+
puts e.message
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'configure', 'create configure'
|
53
|
+
options global: true,
|
54
|
+
profile: 'default'
|
55
|
+
|
56
|
+
def configure
|
57
|
+
do_configure(options)
|
58
|
+
rescue => e
|
59
|
+
puts e.message
|
60
|
+
end
|
61
|
+
|
62
|
+
desc 'version', 'version string'
|
63
|
+
|
64
|
+
def version
|
65
|
+
puts "idcfcloud version #{Idcf::Cli::VERSION}"
|
66
|
+
rescue => e
|
67
|
+
puts e.message
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Idcf
|
2
|
+
module Cli
|
3
|
+
module Lib
|
4
|
+
module Convert
|
5
|
+
module Formatter
|
6
|
+
# formatter base
|
7
|
+
class Base
|
8
|
+
# format
|
9
|
+
#
|
10
|
+
# @param _data [Hash]
|
11
|
+
# @param _err_f [Boolean]
|
12
|
+
# @return String
|
13
|
+
def format(_data, _err_f)
|
14
|
+
raise Idcf::Cli::CliError, 'override'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require_relative './base'
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
module Idcf
|
5
|
+
module Cli
|
6
|
+
module Lib
|
7
|
+
module Convert
|
8
|
+
module Formatter
|
9
|
+
# csv formatter
|
10
|
+
class CsvFormat < Base
|
11
|
+
def format(data, err_f)
|
12
|
+
result = CSV.generate do |csv|
|
13
|
+
scrape_line(data, err_f).each do |v|
|
14
|
+
csv << v
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
result.strip
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def scrape_line(data, err_f)
|
24
|
+
list = scrape(data, err_f)
|
25
|
+
return [] if list.size.zero?
|
26
|
+
|
27
|
+
result = []
|
28
|
+
headers = make_header(list.first)
|
29
|
+
result << headers
|
30
|
+
push_list(list, headers, result)
|
31
|
+
end
|
32
|
+
|
33
|
+
def make_header(first_list)
|
34
|
+
result = []
|
35
|
+
if first_list.class == Hash
|
36
|
+
first_list.each do |k, _v|
|
37
|
+
result << k
|
38
|
+
end
|
39
|
+
else
|
40
|
+
result = [*(0..(first_list.size - 1))]
|
41
|
+
end
|
42
|
+
result
|
43
|
+
end
|
44
|
+
|
45
|
+
def push_list(list, headers, result)
|
46
|
+
list.each do |v|
|
47
|
+
col = []
|
48
|
+
headers.each do |h|
|
49
|
+
col << v[h]
|
50
|
+
end
|
51
|
+
result << col
|
52
|
+
end
|
53
|
+
|
54
|
+
result
|
55
|
+
end
|
56
|
+
|
57
|
+
# scrape
|
58
|
+
# @param data [Hash]
|
59
|
+
# @param err_f [Boolean]
|
60
|
+
# @return Array in Hash
|
61
|
+
def scrape(data, err_f)
|
62
|
+
return [flat_hash(data)] if err_f
|
63
|
+
return [flat_hash(data)] if data.class == Hash
|
64
|
+
return [[data]] unless data.class == Array
|
65
|
+
|
66
|
+
two_dimensional(data)
|
67
|
+
end
|
68
|
+
|
69
|
+
# two dimensional
|
70
|
+
# @param list [Array] One-dimensional [array or Hash List]
|
71
|
+
# @return Array
|
72
|
+
def two_dimensional(list)
|
73
|
+
[].tap do |result|
|
74
|
+
list.each do |v|
|
75
|
+
next if v.class == Array
|
76
|
+
unless v.class == Hash
|
77
|
+
result << [v]
|
78
|
+
next
|
79
|
+
end
|
80
|
+
result << flat_hash(v)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def flat_hash(data)
|
86
|
+
{}.tap do |result|
|
87
|
+
return {} unless data.class == Hash
|
88
|
+
data.each do |k, v|
|
89
|
+
value = v
|
90
|
+
arr_f = v.class == Array || v.class == Hash
|
91
|
+
next if k != :message && arr_f
|
92
|
+
value = flat(value) if arr_f
|
93
|
+
result[k.to_sym] = value
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def flat(list)
|
99
|
+
result = []
|
100
|
+
list.each do |k, v|
|
101
|
+
if list.class == Hash
|
102
|
+
result << "#{k}:#{v.join('/')}"
|
103
|
+
next
|
104
|
+
end
|
105
|
+
result << (v.nil? ? k : v)
|
106
|
+
end
|
107
|
+
|
108
|
+
result.join("\n")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative './base'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Idcf
|
5
|
+
module Cli
|
6
|
+
module Lib
|
7
|
+
module Convert
|
8
|
+
module Formatter
|
9
|
+
# json formatter
|
10
|
+
class JsonFormat < Base
|
11
|
+
def format(data, _err_f)
|
12
|
+
JSON.pretty_generate(data)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative './csv_format'
|
2
|
+
|
3
|
+
module Idcf
|
4
|
+
module Cli
|
5
|
+
module Lib
|
6
|
+
module Convert
|
7
|
+
module Formatter
|
8
|
+
# table formatter
|
9
|
+
class TableFormat < CsvFormat
|
10
|
+
def format(data, err_f)
|
11
|
+
require 'kosi'
|
12
|
+
Kosi::Table.new.render(scrape_line(data, err_f))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative './base'
|
2
|
+
require 'builder/xmlmarkup'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext'
|
5
|
+
|
6
|
+
module Idcf
|
7
|
+
module Cli
|
8
|
+
module Lib
|
9
|
+
module Convert
|
10
|
+
module Formatter
|
11
|
+
# xml formatter
|
12
|
+
class XmlFormat < Base
|
13
|
+
def format(data, _err_f)
|
14
|
+
data.to_xml
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
2
|
+
require 'idcf/cli/lib/convert/formatter/xml_format'
|
3
|
+
require 'idcf/cli/lib/convert/formatter/json_format'
|
4
|
+
require 'idcf/cli/lib/convert/formatter/csv_format'
|
5
|
+
require 'idcf/cli/lib/convert/formatter/table_format'
|
6
|
+
|
7
|
+
module Idcf
|
8
|
+
module Cli
|
9
|
+
module Lib
|
10
|
+
module Convert
|
11
|
+
# format helper
|
12
|
+
class Helper
|
13
|
+
# data convert
|
14
|
+
#
|
15
|
+
# @param data [Hash]
|
16
|
+
# @param err_f [Boolean]
|
17
|
+
# @param f [String] format
|
18
|
+
# @return String
|
19
|
+
def format(data, err_f, f)
|
20
|
+
base_name = 'Idcf::Cli::Lib::Convert::Formatter'
|
21
|
+
cl = "#{base_name}::#{f.capitalize}Format"
|
22
|
+
cl.constantize.new.format(data, err_f)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'inifile'
|
2
|
+
require 'fileutils'
|
3
|
+
module Idcf
|
4
|
+
module Cli
|
5
|
+
module Lib
|
6
|
+
module Util
|
7
|
+
# ini conf
|
8
|
+
class IniConf
|
9
|
+
attr_reader :load_data, :tmp_data
|
10
|
+
|
11
|
+
# initialize
|
12
|
+
#
|
13
|
+
# @param path [String] ini file path
|
14
|
+
def initialize(*path)
|
15
|
+
@tmp_data = {}
|
16
|
+
@load_data = IniFile.load(path[0])
|
17
|
+
end
|
18
|
+
|
19
|
+
def load_error?
|
20
|
+
@load_data.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](profile)
|
24
|
+
return nil if load_error?
|
25
|
+
@load_data[profile.to_s]
|
26
|
+
end
|
27
|
+
|
28
|
+
def []=(profile, value)
|
29
|
+
data = load_error? ? @tmp_data : @load_data
|
30
|
+
data[profile.to_s] = value
|
31
|
+
end
|
32
|
+
|
33
|
+
# get config value
|
34
|
+
#
|
35
|
+
# @param name [String]
|
36
|
+
# @param profile [String]
|
37
|
+
# @return String or Hash
|
38
|
+
# @raise
|
39
|
+
def find(name, profile)
|
40
|
+
begin
|
41
|
+
@load_data[profile].fetch(name)
|
42
|
+
rescue
|
43
|
+
@load_data['default'].fetch(name)
|
44
|
+
end
|
45
|
+
rescue
|
46
|
+
msg = "Error: could not read #{profile}:#{name}"
|
47
|
+
raise Idcf::Cli::CliError, msg
|
48
|
+
end
|
49
|
+
|
50
|
+
def write(path)
|
51
|
+
unless File.exist?(path)
|
52
|
+
dir_path = File.dirname(path)
|
53
|
+
FileUtils.mkdir_p(dir_path) unless Dir.exist?(dir_path)
|
54
|
+
File.open(path, 'w').close
|
55
|
+
@load_data = IniFile.load(path)
|
56
|
+
end
|
57
|
+
|
58
|
+
@tmp_data.each do |k, v|
|
59
|
+
@load_data[k] = v
|
60
|
+
end
|
61
|
+
@load_data.write(filename: path)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'idcf/cli/conf/const'
|
2
|
+
require 'erb'
|
3
|
+
module Idcf
|
4
|
+
module Cli
|
5
|
+
module Lib
|
6
|
+
module Util
|
7
|
+
# template
|
8
|
+
class Template
|
9
|
+
def set(name, value)
|
10
|
+
instance_variable_set("@#{name}", value)
|
11
|
+
end
|
12
|
+
|
13
|
+
# return string
|
14
|
+
#
|
15
|
+
# @param path [String]
|
16
|
+
# @param attr
|
17
|
+
def fetch(path, attr = {})
|
18
|
+
tmp_path = "#{Idcf::Cli::Conf::Const::TEMPLATE_DIR}/#{path}"
|
19
|
+
attr.each do |k, v|
|
20
|
+
set(k, v)
|
21
|
+
end
|
22
|
+
f_content = File.open(File.expand_path(tmp_path)).read
|
23
|
+
ERB.new(f_content).result(binding)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
module Idcf
|
3
|
+
module Cli
|
4
|
+
module Lib
|
5
|
+
module Util
|
6
|
+
# yml conf
|
7
|
+
class YmlConf
|
8
|
+
@load_data = nil
|
9
|
+
|
10
|
+
# initialize
|
11
|
+
#
|
12
|
+
# @param path [String] yml file path
|
13
|
+
def initialize(*path)
|
14
|
+
@load_data = YAML.load_file(path[0])
|
15
|
+
end
|
16
|
+
|
17
|
+
# get config value
|
18
|
+
#
|
19
|
+
# @param path [String]
|
20
|
+
# @return String or Hash
|
21
|
+
# @raise
|
22
|
+
def find(path)
|
23
|
+
result = @load_data
|
24
|
+
return result[path] if path.class == Symbol
|
25
|
+
path.split('.').each do |name|
|
26
|
+
result = result.fetch(name)
|
27
|
+
end
|
28
|
+
|
29
|
+
result
|
30
|
+
rescue
|
31
|
+
raise Idcf::Cli::CliError, "Error: could not read '#{path}'"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|