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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: be0ca7ba05fc04b552bfce556e6a1da26d6e2a1b
|
4
|
+
data.tar.gz: b2683c9799d48cc98e6381d6b857b035b4da4920
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f45c4186da2c87c295f0538c34305f1c55239ee57d1b169c5a4f79bfe48ecbbda6dc04c63eea5761259088cb291bff1629c8d5b5947d921ea7fb973d5bf71411
|
7
|
+
data.tar.gz: fcb4b65abdf03db3e6d2cb7e42dcc8c5a7df5edab3d7cdf03d69e8e85c48445772c726b674e096c9df353df22a5175384736fc7019894b0cbca65702f2673898
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
engines:
|
3
|
+
duplication:
|
4
|
+
enabled: true
|
5
|
+
config:
|
6
|
+
languages:
|
7
|
+
- ruby
|
8
|
+
exclude_paths:
|
9
|
+
- 'test/**/*'
|
10
|
+
fixme:
|
11
|
+
enabled: true
|
12
|
+
rubocop:
|
13
|
+
enabled: true
|
14
|
+
ratings:
|
15
|
+
paths:
|
16
|
+
- "**.rb"
|
17
|
+
exclude_paths:
|
18
|
+
- vendor/bundle
|
19
|
+
- .idea
|
20
|
+
- bin
|
21
|
+
- doc
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
/output/
|
13
|
+
/config/config.ini
|
14
|
+
/lib/idcf/cli/conf/service/*.yml
|
15
|
+
|
16
|
+
.idea/*
|
17
|
+
*.iml
|
18
|
+
|
19
|
+
# Used by dotenv library to load environment variables.
|
20
|
+
# .env
|
21
|
+
|
22
|
+
## Specific to RubyMotion:
|
23
|
+
.dat*
|
24
|
+
.repl_history
|
25
|
+
build/
|
26
|
+
*.bridgesupport
|
27
|
+
build-iPhoneOS/
|
28
|
+
build-iPhoneSimulator/
|
29
|
+
|
30
|
+
## Specific to RubyMotion (use of CocoaPods):
|
31
|
+
#
|
32
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
33
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
34
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
35
|
+
#
|
36
|
+
# vendor/Pods/
|
37
|
+
|
38
|
+
## Documentation cache and generated files:
|
39
|
+
/.yardoc/
|
40
|
+
/_yardoc/
|
41
|
+
/doc/
|
42
|
+
/rdoc/
|
43
|
+
|
44
|
+
## Environment normalization:
|
45
|
+
/.bundle/
|
46
|
+
/vendor/bundle
|
47
|
+
/lib/bundler/man/
|
48
|
+
|
49
|
+
# for a library or gem, you might want to ignore these files since the code is
|
50
|
+
# intended to run in multiple environments; otherwise, check them in:
|
51
|
+
# Gemfile.lock
|
52
|
+
# .ruby-version
|
53
|
+
# .ruby-gemset
|
54
|
+
|
55
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
56
|
+
.rvmrc
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.2
|
3
|
+
Metrics/BlockLength:
|
4
|
+
Exclude:
|
5
|
+
- '*.gemspec'
|
6
|
+
- 'test/**/*'
|
7
|
+
Metrics/LineLength:
|
8
|
+
Exclude:
|
9
|
+
- 'test/**/*'
|
10
|
+
Metrics/MethodLength:
|
11
|
+
Exclude:
|
12
|
+
- 'test/**/*'
|
13
|
+
Metrics/ClassLength:
|
14
|
+
Exclude:
|
15
|
+
- 'test/**/*'
|
16
|
+
Style/IdenticalConditionalBranches:
|
17
|
+
Exclude:
|
18
|
+
- 'test/**/*'
|
19
|
+
Metrics/PerceivedComplexity:
|
20
|
+
Exclude:
|
21
|
+
- 'test/**/*'
|
22
|
+
Metrics/AbcSize:
|
23
|
+
Exclude:
|
24
|
+
- 'test/**/*'
|
25
|
+
LineLength:
|
26
|
+
Max: 100
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 IDC Frontier Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# idcfcloud-cli
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Note: requires Ruby 2.2.7 or higher.
|
6
|
+
|
7
|
+
Carry out the next command to initialize.
|
8
|
+
|
9
|
+
```
|
10
|
+
bin/idcfcloud init
|
11
|
+
```
|
12
|
+
|
13
|
+
If you want each user to have their own configuration file, use the "--no-global" option and have the file created in the following:
|
14
|
+
|
15
|
+
```
|
16
|
+
~/.idcfcloud/config.ini
|
17
|
+
```
|
18
|
+
|
19
|
+
Install idcfcloud-cli by using the following command:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ gem install idcfcloud
|
23
|
+
```
|
24
|
+
or
|
25
|
+
```
|
26
|
+
$ git clone [idcfcloud]
|
27
|
+
$ bundle install --path vendor/bundle
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
```
|
33
|
+
$ bin/idcfcloud <serviceName> <command> [attributes] [option]
|
34
|
+
```
|
35
|
+
|
36
|
+
If you want to set more than one attribute, use the json form.
|
37
|
+
|
38
|
+
```ex)
|
39
|
+
'{"ipaddress": "0.0.0.0", "port": 80}'
|
40
|
+
```
|
41
|
+
|
42
|
+
## ServiceName
|
43
|
+
[ILB](#ilb)
|
44
|
+
|
45
|
+
[Your](#your)
|
46
|
+
|
47
|
+
#### <a name="ilb"></a>ILB
|
48
|
+
|
49
|
+
https://github.com/idcf/idcf-ilb-ruby
|
50
|
+
|
51
|
+
##### ILB Extend Commands
|
52
|
+
|
53
|
+
add server
|
54
|
+
|
55
|
+
``` code
|
56
|
+
bin/idcfcloud ilb add_server_for_protocol <lb_id> <protocol> <protocol_port> <data> [option]
|
57
|
+
```
|
58
|
+
|
59
|
+
| data | type | example | note |
|
60
|
+
|:---|:---|:---|:---|
|
61
|
+
| ipaddress | String | 0.0.0.0 | no cidr |
|
62
|
+
| port | Numeric | 80 | |
|
63
|
+
|
64
|
+
delete server
|
65
|
+
|
66
|
+
``` code
|
67
|
+
bin/idcfcloud ilb delete_server_for_protocol <lb_id> <protocol> <protocol_port> <data> [option]
|
68
|
+
```
|
69
|
+
|
70
|
+
#### <a name="your"></a>Your
|
71
|
+
|
72
|
+
http://docs.idcf.jp/cloud/billing/
|
73
|
+
|
74
|
+
|
75
|
+
## Development
|
76
|
+
|
77
|
+
Running the following test code is possible, but not recommended nor supported. Run only a code of a target.
|
78
|
+
|
79
|
+
```code
|
80
|
+
bundle exec ruby test/run_test.rb idcf/cli/controller/test_billing.rb
|
81
|
+
```
|
82
|
+
|
83
|
+
In order to avoid collapsed setting in ILB, make sure you understand how things work before running a code.
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
1. Fork it ( https://github.com/idcf/idcfcloud-cli/fork )
|
88
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
89
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
90
|
+
4. Push the branch (git push origin my-new-feature)
|
91
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/idcfcloud
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'idcfcloud' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("idcfcloud", "idcfcloud")
|
@@ -0,0 +1,16 @@
|
|
1
|
+
[default]
|
2
|
+
api_key = [key]
|
3
|
+
secret_key = [secret_key]
|
4
|
+
obst_api_key = [key]
|
5
|
+
obst_secret_key = [secret_key]
|
6
|
+
|
7
|
+
;override default output
|
8
|
+
;output = xml
|
9
|
+
;override host
|
10
|
+
;ilb.v1.host.jp-east = [domain]
|
11
|
+
|
12
|
+
;It's possible to add a section and overwrite partially from default.
|
13
|
+
[test]
|
14
|
+
api_key = [key]
|
15
|
+
secret_key = [secret_key]
|
16
|
+
|
data/exe/idcfcloud
ADDED
data/idcfcloud.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'idcf/cli/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'idcfcloud'
|
8
|
+
spec.version = Idcf::Cli::VERSION
|
9
|
+
spec.authors = ['IDC Frontier Inc.']
|
10
|
+
spec.email = []
|
11
|
+
|
12
|
+
spec.summary = 'IDCF Cli tools'
|
13
|
+
spec.description = 'IDCF Cli'
|
14
|
+
spec.homepage = 'https://www.idcfcloud.jp'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.post_install_message = 'Please carry out \'init\' command.'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.bindir = 'exe'
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
|
30
|
+
spec.add_dependency 'test-unit', '~> 3.2', '>= 3.2.5'
|
31
|
+
spec.add_dependency 'test-unit-notify', '~> 1.0', '>= 1.0.4'
|
32
|
+
|
33
|
+
spec.add_dependency 'activerecord', '~> 4.2', '>= 4.2.3'
|
34
|
+
spec.add_dependency 'activesupport', '~> 4.2', '>= 4.2.3'
|
35
|
+
spec.add_dependency 'inifile', '~> 3.0', '>= 3.0.0'
|
36
|
+
spec.add_dependency 'thor', '~> 0.19.4'
|
37
|
+
spec.add_dependency 'builder', '~> 3.1'
|
38
|
+
spec.add_dependency 'kosi', '~> 1.0', '>= 1.0.0'
|
39
|
+
|
40
|
+
spec.add_runtime_dependency 'idcf-your'
|
41
|
+
spec.add_runtime_dependency 'idcf-faraday_middleware'
|
42
|
+
spec.add_runtime_dependency 'idcf-ilb'
|
43
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Idcf
|
2
|
+
module Cli
|
3
|
+
module Conf
|
4
|
+
# const
|
5
|
+
class Const
|
6
|
+
dir_path = File.dirname(__FILE__)
|
7
|
+
BASE_PATH = File.expand_path("#{dir_path}/../../../")
|
8
|
+
LOCAL_ERROR_PREFIX = '[idcfcli]'.freeze
|
9
|
+
HEADERS = {
|
10
|
+
'User-Agent': "IDCF CLI v#{Idcf::Cli::VERSION}"
|
11
|
+
}.freeze
|
12
|
+
VALIDATOR_DIR_PATH = 'idcf/cli/validate/define'.freeze
|
13
|
+
CODE_CONF_PATH = "#{BASE_PATH}/idcf/cli/conf/conf.yml".freeze
|
14
|
+
USER_CONF_PATH = '~/.idcfcloud/config.ini'.freeze
|
15
|
+
USER_CONF_GLOBAL = "#{BASE_PATH}/../config/config.ini".freeze
|
16
|
+
REGIONS = %w(jp-east jp-east-2 jp-west).freeze
|
17
|
+
USER_CONF_ITEMS = {
|
18
|
+
api_key: nil,
|
19
|
+
secret_key: nil,
|
20
|
+
region: REGIONS
|
21
|
+
}.freeze
|
22
|
+
CMD_FILE_DIR = "#{BASE_PATH}/idcf/cli/conf/service".freeze
|
23
|
+
CMD_FILE_EXT = 'yml'.freeze
|
24
|
+
SERVICE_PATH = 'idcf/cli/service'.freeze
|
25
|
+
TEMPLATE_DIR = "#{BASE_PATH}/idcf/cli/templates".freeze
|
26
|
+
OUT_DIR = "#{BASE_PATH}/../output".freeze
|
27
|
+
COMP_NOTIFICATION = <<EOT.freeze
|
28
|
+
please write in
|
29
|
+
~/.bash_profile
|
30
|
+
source %s
|
31
|
+
~/.zprofile
|
32
|
+
source %s
|
33
|
+
EOT
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
File without changes
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'json'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext'
|
5
|
+
require 'idcf/cli/conf/const'
|
6
|
+
require 'idcf/cli/lib/util/ini_conf'
|
7
|
+
require 'idcf/cli/lib/util/yml_conf'
|
8
|
+
require 'active_record'
|
9
|
+
require 'idcf/cli/lib/convert/helper'
|
10
|
+
require_relative './extend/init'
|
11
|
+
require_relative './include/init'
|
12
|
+
|
13
|
+
module Idcf
|
14
|
+
module Cli
|
15
|
+
module Controller
|
16
|
+
# Controller Base
|
17
|
+
class Base < Thor
|
18
|
+
class_option :output,
|
19
|
+
type: :string,
|
20
|
+
aliases: '-o',
|
21
|
+
desc: 'output type: table/json/xml/csv'
|
22
|
+
class_option :profile,
|
23
|
+
type: :string,
|
24
|
+
desc: 'use profile'
|
25
|
+
class_option :api_key,
|
26
|
+
type: :string,
|
27
|
+
desc: 'api key'
|
28
|
+
class_option :secret_key,
|
29
|
+
type: :string,
|
30
|
+
desc: 'secret key'
|
31
|
+
class_option :no_ssl,
|
32
|
+
desc: 'not use ssl'
|
33
|
+
class_option :no_vssl,
|
34
|
+
desc: 'not use verify ssl'
|
35
|
+
|
36
|
+
attr_reader :config, :code_conf, :cmd, :m_classes
|
37
|
+
|
38
|
+
extend Idcf::Cli::Controller::Extend::Init
|
39
|
+
include Idcf::Cli::Controller::Include::Init
|
40
|
+
|
41
|
+
class << self
|
42
|
+
def init
|
43
|
+
fn = to_s.underscore.split('/').pop
|
44
|
+
dir = Idcf::Cli::Conf::Const::CMD_FILE_DIR
|
45
|
+
ext = Idcf::Cli::Conf::Const::CMD_FILE_EXT
|
46
|
+
path = "#{dir}/#{fn}.#{ext}"
|
47
|
+
|
48
|
+
if File.exist?(path)
|
49
|
+
cf = Idcf::Cli::Lib::Util::YmlConf.new(path)
|
50
|
+
register_sdk_method! cf.find('')
|
51
|
+
end
|
52
|
+
|
53
|
+
register_service_method!
|
54
|
+
end
|
55
|
+
|
56
|
+
# regist method
|
57
|
+
#
|
58
|
+
# @param methods [Hash]
|
59
|
+
def register_sdk_method!(methods)
|
60
|
+
return unless methods
|
61
|
+
methods.each do |command, s|
|
62
|
+
register_method!(command, s[:params], s[:options])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# regist service method
|
67
|
+
def register_service_method!
|
68
|
+
make_module_classes.each do |cn, c|
|
69
|
+
register_method!(cn, c.params, c.options)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
protected
|
75
|
+
|
76
|
+
def execute(cmd, *args)
|
77
|
+
data = run(cmd, args)
|
78
|
+
puts make_result_str(data, false, options)
|
79
|
+
rescue => e
|
80
|
+
STDERR.puts e.message
|
81
|
+
exit 1
|
82
|
+
end
|
83
|
+
|
84
|
+
def run(cmd, args)
|
85
|
+
@cmd = cmd
|
86
|
+
check_params(self.class.make_module_classes, cmd, *args)
|
87
|
+
o = options
|
88
|
+
data = do_validate(o)
|
89
|
+
if data
|
90
|
+
STDERR.puts data[:message].flatten
|
91
|
+
exit 1
|
92
|
+
end
|
93
|
+
data = make_result_data(do_command(cmd, *args, o), o)
|
94
|
+
data
|
95
|
+
end
|
96
|
+
|
97
|
+
def do_command(cmd, *args, o)
|
98
|
+
m_class = self.class.search_module_class(cmd)
|
99
|
+
|
100
|
+
arg = convert_arg_json(*args)
|
101
|
+
client = make_client(o)
|
102
|
+
return m_class.new.do(client, *arg, o) unless m_class.nil?
|
103
|
+
do_sdk(client, cmd, *arg, o)
|
104
|
+
end
|
105
|
+
|
106
|
+
# make response base data
|
107
|
+
#
|
108
|
+
# @return Hash
|
109
|
+
def make_base_response
|
110
|
+
{
|
111
|
+
status: 200,
|
112
|
+
message: '',
|
113
|
+
data: []
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
# make error result
|
118
|
+
#
|
119
|
+
# @param error [Exception]
|
120
|
+
# @return Hash
|
121
|
+
def make_error(error)
|
122
|
+
error.to_s =~ /status code: ?(\d+)/
|
123
|
+
match = Regexp.last_match(1)
|
124
|
+
result = make_base_response
|
125
|
+
result[:status] = match ? match.to_i : 400
|
126
|
+
result[:message] = error.message
|
127
|
+
result
|
128
|
+
end
|
129
|
+
|
130
|
+
def make_result_data(data, o)
|
131
|
+
result = data
|
132
|
+
format = output_format(o, '')
|
133
|
+
if format == 'csv' || format == 'table'
|
134
|
+
result = make_table_data(data)
|
135
|
+
else
|
136
|
+
result = make_base_response
|
137
|
+
result[:data] = data
|
138
|
+
end
|
139
|
+
result
|
140
|
+
end
|
141
|
+
|
142
|
+
# table data
|
143
|
+
# @param data [Hash]
|
144
|
+
# @return Hash
|
145
|
+
def make_table_data(data)
|
146
|
+
data
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'idcf/cli/conf/const'
|
2
|
+
module Idcf
|
3
|
+
module Cli
|
4
|
+
module Controller
|
5
|
+
module Extend
|
6
|
+
# command
|
7
|
+
module Command
|
8
|
+
def register_method!(name, params, options)
|
9
|
+
register_method_option! options
|
10
|
+
cp = make_param_s params
|
11
|
+
desc "#{name} #{cp}", ''
|
12
|
+
define_method name.to_sym do |*args|
|
13
|
+
execute(__method__, *args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# make param string
|
18
|
+
#
|
19
|
+
# @param params[Array]
|
20
|
+
# @return String
|
21
|
+
def make_param_s(params)
|
22
|
+
cp = []
|
23
|
+
return '' if params.nil?
|
24
|
+
params.each do |param|
|
25
|
+
f = param[:arg_type].to_s == 'req' ? '<%s>' : '[%s]'
|
26
|
+
cp << format(f, param[:name])
|
27
|
+
end
|
28
|
+
cp.join(' ')
|
29
|
+
end
|
30
|
+
|
31
|
+
# regist method option
|
32
|
+
#
|
33
|
+
# @param values [Hash] name => desc
|
34
|
+
def register_method_option!(values)
|
35
|
+
return if values.nil?
|
36
|
+
values.each do |opn, op|
|
37
|
+
option = {}
|
38
|
+
op.each do |ok, ov|
|
39
|
+
option[ok.to_sym] = ov
|
40
|
+
end
|
41
|
+
method_option opn, option
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative './override'
|
2
|
+
require_relative './search_module'
|
3
|
+
require_relative './command'
|
4
|
+
module Idcf
|
5
|
+
module Cli
|
6
|
+
module Controller
|
7
|
+
module Extend
|
8
|
+
# init load
|
9
|
+
module Init
|
10
|
+
include Override
|
11
|
+
include SearchModule
|
12
|
+
include Command
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Idcf
|
2
|
+
module Cli
|
3
|
+
module Controller
|
4
|
+
module Extend
|
5
|
+
# override methods
|
6
|
+
module Override
|
7
|
+
def description
|
8
|
+
raise Idcf::Cli::CliError, 'Require override'
|
9
|
+
end
|
10
|
+
|
11
|
+
# blank client
|
12
|
+
#
|
13
|
+
# @return Mixed
|
14
|
+
def make_blank_client
|
15
|
+
# blank client
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'idcf/cli/conf/const'
|
2
|
+
module Idcf
|
3
|
+
module Cli
|
4
|
+
module Controller
|
5
|
+
module Extend
|
6
|
+
# model class search
|
7
|
+
module SearchModule
|
8
|
+
# search module class
|
9
|
+
#
|
10
|
+
# @param class_mame [String]
|
11
|
+
# @return Mixed
|
12
|
+
def search_module_class(module_name)
|
13
|
+
make_module_classes.each do |k, v|
|
14
|
+
return v if module_name.to_s == k
|
15
|
+
end
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
|
19
|
+
# make module require and class list
|
20
|
+
#
|
21
|
+
# @return Hash
|
22
|
+
def make_module_classes
|
23
|
+
return @m_classes if @m_classes
|
24
|
+
result = {}
|
25
|
+
make_service_paths.each do |fn, path|
|
26
|
+
require path
|
27
|
+
result[fn] = path.classify.constantize
|
28
|
+
end
|
29
|
+
|
30
|
+
@m_classes = result
|
31
|
+
end
|
32
|
+
|
33
|
+
def make_service_paths
|
34
|
+
s_name = make_model_name
|
35
|
+
base_path = Idcf::Cli::Conf::Const::BASE_PATH
|
36
|
+
s_path = "#{Idcf::Cli::Conf::Const::SERVICE_PATH}/#{s_name}"
|
37
|
+
{}.tap do |result|
|
38
|
+
Dir.glob("#{base_path}/#{s_path}/*.rb").each do |f|
|
39
|
+
fn = File.basename(f, '.rb')
|
40
|
+
result[fn] = "#{s_path}/#{fn}" unless fn =~ /^base_*/
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def make_model_name
|
46
|
+
list = to_s.split('::')
|
47
|
+
list.shift(3)
|
48
|
+
list.join('/').underscore
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|