hammer_cli 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/hammer +3 -1
- data/config/cli_config.template.yml +3 -0
- data/doc/creating_commands.md +1 -1
- data/doc/installation.md +3 -2
- data/doc/release_notes.md +17 -0
- data/doc/writing_a_plugin.md +1 -1
- data/lib/hammer_cli/abstract.rb +46 -9
- data/lib/hammer_cli/apipie/command.rb +10 -1
- data/lib/hammer_cli/apipie/option_builder.rb +29 -11
- data/lib/hammer_cli/apipie/option_definition.rb +18 -0
- data/lib/hammer_cli/apipie/resource.rb +4 -22
- data/lib/hammer_cli/exception_handler.rb +18 -6
- data/lib/hammer_cli/exceptions.rb +1 -0
- data/lib/hammer_cli/i18n.rb +4 -0
- data/lib/hammer_cli/main.rb +2 -0
- data/lib/hammer_cli/modules.rb +30 -2
- data/lib/hammer_cli/options/matcher.rb +48 -0
- data/lib/hammer_cli/output/adapter.rb +3 -1
- data/lib/hammer_cli/output/adapter/csv.rb +5 -2
- data/lib/hammer_cli/output/adapter/json.rb +17 -0
- data/lib/hammer_cli/output/adapter/table.rb +11 -17
- data/lib/hammer_cli/output/adapter/tree_structure.rb +74 -0
- data/lib/hammer_cli/output/adapter/wrapper_formatter.rb +20 -0
- data/lib/hammer_cli/output/adapter/yaml.rb +16 -0
- data/lib/hammer_cli/shell.rb +3 -8
- data/lib/hammer_cli/utils.rb +10 -0
- data/lib/hammer_cli/version.rb +1 -1
- data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/de/hammer-cli.po +296 -0
- data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/en/hammer-cli.po +1 -1
- data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/en_GB/hammer-cli.po +133 -133
- data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/es/hammer-cli.po +148 -147
- data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/fr/hammer-cli.po +142 -141
- data/locale/hammer-cli.pot +39 -32
- data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/it/hammer-cli.po +293 -0
- data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ja/hammer-cli.po +291 -0
- data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ko/hammer-cli.po +292 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/pt_BR/hammer-cli.po +294 -0
- data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ru/hammer-cli.po +293 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/zh_CN/hammer-cli.po +292 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/zh_TW/hammer-cli.po +292 -0
- data/test/unit/apipie/command_test.rb +22 -0
- data/test/unit/apipie/option_builder_test.rb +21 -7
- data/test/unit/apipie/option_definition_test.rb +26 -0
- data/test/unit/fixtures/apipie/documented.json +26 -0
- data/test/unit/modules_test.rb +13 -2
- data/test/unit/options/matcher_test.rb +61 -0
- data/test/unit/output/adapter/json_test.rb +214 -0
- data/test/unit/output/adapter/table_test.rb +66 -0
- data/test/unit/output/adapter/yaml_test.rb +213 -0
- data/test/unit/utils_test.rb +17 -0
- metadata +249 -205
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfc3de6a7599c2ab526183074b333b1c3ad55970
|
4
|
+
data.tar.gz: 0c5a264582fdd5dc5fcfcdbfe4f20cb1ccb8f3f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75df4210b14e233c11f681e06d2045518e9fb39233094b5283012ebd4ff59e341edc74a077f986c8da14770b5c507a0ed0e6d623098357a7e74ca70fae345594
|
7
|
+
data.tar.gz: 06045bbf7c133b0b826a6822faa9df3f215f19895b2d3b76f73e9bbaefe9f4d4b0a3e3a91c97ee7a7a59aae0a70728a7c10bc93dcd27af2762227dbdc0747524
|
data/bin/hammer
CHANGED
@@ -17,6 +17,7 @@ class PreParser < Clamp::Command
|
|
17
17
|
option ["-u", "--username"], "USERNAME", _("username to access the remote system")
|
18
18
|
option ["-p", "--password"], "PASSWORD", _("password to access the remote system")
|
19
19
|
option ["-s", "--server"], "SERVER", _("remote system address")
|
20
|
+
option ["-r", "--reload-cache"], :flag, _("force reload of Apipie cache")
|
20
21
|
option ["--interactive"], "INTERACTIVE", _("Explicitly turn interactive mode on/off") do |value|
|
21
22
|
bool_normalizer = HammerCLI::Options::Normalizers::Bool.new
|
22
23
|
bool_normalizer.format(value)
|
@@ -57,7 +58,8 @@ HammerCLI::Settings.load({
|
|
57
58
|
:password => preparser.password,
|
58
59
|
:host => preparser.server,
|
59
60
|
:interactive => preparser.interactive,
|
60
|
-
:verbose => preparser.verbose? || preparser.debug
|
61
|
+
:verbose => preparser.verbose? || preparser.debug?,
|
62
|
+
:reload_cache => preparser.reload_cache?
|
61
63
|
}})
|
62
64
|
|
63
65
|
if HammerCLI::Settings.get(:mark_translated)
|
@@ -11,6 +11,9 @@
|
|
11
11
|
# Enable/disable color output of logger in Clamp commands
|
12
12
|
:watch_plain: false
|
13
13
|
|
14
|
+
# Forece relaod of Apipie cache with every Hammer invocation
|
15
|
+
:reload_cache: false
|
16
|
+
|
14
17
|
# Directory where the logs are stored. The default is /var/log/hammer/ and the log file is named hammer.log
|
15
18
|
:log_dir: '~/.hammer/log'
|
16
19
|
|
data/doc/creating_commands.md
CHANGED
@@ -572,5 +572,5 @@ There are more ways where to place your config file for hammer.
|
|
572
572
|
The best practice is to place module's configuration into a separate file named by
|
573
573
|
the module. In this example it would be `~/.hammer/cli.modules.d/hello_world.yml`.
|
574
574
|
|
575
|
-
Read more in [the settings howto](
|
575
|
+
Read more about configuration locations in [the settings howto](installation.md#configuration).
|
576
576
|
|
data/doc/installation.md
CHANGED
@@ -29,10 +29,10 @@ Configuration is by default looked for in the following directories, loaded in t
|
|
29
29
|
- custom location (file or directory) specified on command line - ```-c CONF_FILE_PATH```
|
30
30
|
|
31
31
|
In each of these directories hammer is trying to load ```cli_config.yml``` and anything in
|
32
|
-
the ```cli.modules.d``` subdirectory which is place for specific configuration of hammer modules.
|
32
|
+
the ```cli.modules.d``` subdirectory which is place for specific configuration of hammer modules a.k.a. plugins.
|
33
33
|
|
34
34
|
Later directories and files have precedence if they redefine the same option. Files from ```cli.modules.d```
|
35
|
-
are loaded in alphabetical order.
|
35
|
+
are loaded in alphabetical order. The modules are loaded in alphabetical order which can be overriden with explicit requirement of dependences in the modules.
|
36
36
|
|
37
37
|
### Manual installation
|
38
38
|
The packaged version of hammer copies the template to `/etc/hammer` for you.
|
@@ -70,6 +70,7 @@ in ```~/.hammer/cli.modules.d/foreman.yml``` should look as follows:
|
|
70
70
|
:password: 'changeme'
|
71
71
|
```
|
72
72
|
|
73
|
+
|
73
74
|
Use the hammer
|
74
75
|
--------------
|
75
76
|
|
data/doc/release_notes.md
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
Release notes
|
2
2
|
=============
|
3
3
|
|
4
|
+
### 0.1.4 (2014-12-10)
|
5
|
+
* hammer-cli CSV formatter doesn't properly format values with custom formatters, moving to correct implementation ([#8569](http://projects.theforeman.org/issues/8569))
|
6
|
+
* added support for dependeces among modules ([#7566](http://projects.theforeman.org/issues/7566))
|
7
|
+
* Add option forcing apipie cache reload ([#8430](http://projects.theforeman.org/issues/8430))
|
8
|
+
* Missing search options error message ([#5556](http://projects.theforeman.org/issues/5556))
|
9
|
+
* Adds YAML and JSON output adapters (BZ1122650) ([#6754](http://projects.theforeman.org/issues/6754))
|
10
|
+
* Credentials interface definition moved to ApipieBindings ([#7408](http://projects.theforeman.org/issues/7408))
|
11
|
+
* Catching apipie-bindings' MissingArgumentsError ([#6820](http://projects.theforeman.org/issues/6820))
|
12
|
+
* Prints table headers when no data ([#7001](http://projects.theforeman.org/issues/7001))
|
13
|
+
* i18n - add zh_CN language
|
14
|
+
* i18n - add de, it, pt_BR, zh_TW, ru, ja, ko languages
|
15
|
+
* Readable help for long options ([#5417](http://projects.theforeman.org/issues/5417))
|
16
|
+
* Give usage information for boolean types ([#7284](http://projects.theforeman.org/issues/7284))
|
17
|
+
* Minor updates in devel docs ([#5052](http://projects.theforeman.org/issues/5052))
|
18
|
+
* Avoid locale domain name conflict ([#7262](http://projects.theforeman.org/issues/7262))
|
19
|
+
|
20
|
+
|
4
21
|
### 0.1.3
|
5
22
|
* Fixed detection of list type options ([#7144](http://projects.theforeman.org/issues/7144))
|
6
23
|
* Key-value normalizer accepts arrays ([#7133](http://projects.theforeman.org/issues/7133))
|
data/doc/writing_a_plugin.md
CHANGED
@@ -59,7 +59,7 @@ $ gem build ./hammer_cli_hello.gemspec
|
|
59
59
|
$ gem install hammer_cli_hello-0.0.1.gem
|
60
60
|
```
|
61
61
|
|
62
|
-
Place your module's config file into `~/.hammer/cli.modules.d
|
62
|
+
Place your module's config file into `~/.hammer/cli.modules.d/hello_world.yml`.
|
63
63
|
```yaml
|
64
64
|
:hello:
|
65
65
|
:enable_module: true
|
data/lib/hammer_cli/abstract.rb
CHANGED
@@ -3,6 +3,7 @@ require 'hammer_cli/logger_watch'
|
|
3
3
|
require 'hammer_cli/options/option_definition'
|
4
4
|
require 'hammer_cli/clamp'
|
5
5
|
require 'hammer_cli/subcommand'
|
6
|
+
require 'hammer_cli/options/matcher'
|
6
7
|
require 'logging'
|
7
8
|
|
8
9
|
module HammerCLI
|
@@ -63,11 +64,29 @@ module HammerCLI
|
|
63
64
|
end
|
64
65
|
|
65
66
|
class SortedBuilder < Clamp::Help::Builder
|
67
|
+
|
68
|
+
DEFAULT_LABEL_INDENT = 29
|
69
|
+
|
66
70
|
def add_list(heading, items)
|
67
71
|
items.sort! do |a, b|
|
68
72
|
a.help[0] <=> b.help[0]
|
69
73
|
end
|
70
|
-
|
74
|
+
|
75
|
+
puts "\n#{heading}:"
|
76
|
+
|
77
|
+
label_width = DEFAULT_LABEL_INDENT
|
78
|
+
items.each do |item|
|
79
|
+
label, description = item.help
|
80
|
+
label_width = label.size if label.size > label_width
|
81
|
+
end
|
82
|
+
|
83
|
+
items.each do |item|
|
84
|
+
label, description = item.help
|
85
|
+
description.each_line do |line|
|
86
|
+
puts " %-#{label_width}s %s" % [label, line]
|
87
|
+
label = ''
|
88
|
+
end
|
89
|
+
end
|
71
90
|
end
|
72
91
|
end
|
73
92
|
|
@@ -90,14 +109,6 @@ module HammerCLI
|
|
90
109
|
self.class.output_definition
|
91
110
|
end
|
92
111
|
|
93
|
-
def self.inherited_output_definition
|
94
|
-
od = nil
|
95
|
-
if superclass.respond_to? :output_definition
|
96
|
-
od_super = superclass.output_definition
|
97
|
-
od = od_super.dup unless od_super.nil?
|
98
|
-
end
|
99
|
-
od
|
100
|
-
end
|
101
112
|
|
102
113
|
def self.output_definition
|
103
114
|
@output_definition = @output_definition || inherited_output_definition || HammerCLI::Output::Definition.new
|
@@ -129,6 +140,20 @@ module HammerCLI
|
|
129
140
|
|
130
141
|
protected
|
131
142
|
|
143
|
+
def self.find_options(switch_filter, other_filters={})
|
144
|
+
filters = other_filters
|
145
|
+
if switch_filter.is_a? Hash
|
146
|
+
filters.merge!(switch_filter)
|
147
|
+
else
|
148
|
+
filters[:long_switch] = switch_filter
|
149
|
+
end
|
150
|
+
|
151
|
+
m = HammerCLI::Options::Matcher.new(filters)
|
152
|
+
recognised_options.find_all do |opt|
|
153
|
+
m.matches? opt
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
132
157
|
def self.create_option_builder
|
133
158
|
OptionBuilderContainer.new
|
134
159
|
end
|
@@ -217,5 +242,17 @@ module HammerCLI
|
|
217
242
|
def options
|
218
243
|
all_options.reject {|key, value| value.nil? }
|
219
244
|
end
|
245
|
+
|
246
|
+
private
|
247
|
+
|
248
|
+
def self.inherited_output_definition
|
249
|
+
od = nil
|
250
|
+
if superclass.respond_to? :output_definition
|
251
|
+
od_super = superclass.output_definition
|
252
|
+
od = od_super.dup unless od_super.nil?
|
253
|
+
end
|
254
|
+
od
|
255
|
+
end
|
256
|
+
|
220
257
|
end
|
221
258
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '../abstract')
|
2
2
|
require File.join(File.dirname(__FILE__), '../messages')
|
3
3
|
require File.join(File.dirname(__FILE__), 'options')
|
4
|
+
require File.join(File.dirname(__FILE__), 'option_definition')
|
4
5
|
require File.join(File.dirname(__FILE__), 'resource')
|
5
6
|
|
6
7
|
module HammerCLI::Apipie
|
@@ -20,7 +21,7 @@ module HammerCLI::Apipie
|
|
20
21
|
def self.create_option_builder
|
21
22
|
builder = super
|
22
23
|
builder.builders += [
|
23
|
-
OptionBuilder.new(resource.action(action), :require_options => false)
|
24
|
+
OptionBuilder.new(resource, resource.action(action), :require_options => false)
|
24
25
|
] if resource_defined?
|
25
26
|
builder
|
26
27
|
end
|
@@ -73,5 +74,13 @@ module HammerCLI::Apipie
|
|
73
74
|
)
|
74
75
|
end
|
75
76
|
|
77
|
+
def self.option(switches, type, description, opts = {}, &block)
|
78
|
+
HammerCLI::Apipie::OptionDefinition.new(switches, type, description, opts).tap do |option|
|
79
|
+
declared_options << option
|
80
|
+
block ||= option.default_conversion_block
|
81
|
+
define_accessors_for(option, &block)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
76
85
|
end
|
77
86
|
end
|
@@ -3,8 +3,9 @@ module HammerCLI::Apipie
|
|
3
3
|
|
4
4
|
class OptionBuilder < HammerCLI::AbstractOptionBuilder
|
5
5
|
|
6
|
-
def initialize(action, options={})
|
6
|
+
def initialize(resource, action, options={})
|
7
7
|
@action = action
|
8
|
+
@resource = resource
|
8
9
|
@require_options = options[:require_options].nil? ? true : options[:require_options]
|
9
10
|
end
|
10
11
|
|
@@ -22,6 +23,10 @@ module HammerCLI::Apipie
|
|
22
23
|
|
23
24
|
protected
|
24
25
|
|
26
|
+
def option(*args)
|
27
|
+
HammerCLI::Apipie::OptionDefinition.new(*args)
|
28
|
+
end
|
29
|
+
|
25
30
|
def options_for_params(params, filter, resource_name_map)
|
26
31
|
opts = []
|
27
32
|
params.each do |p|
|
@@ -45,11 +50,11 @@ module HammerCLI::Apipie
|
|
45
50
|
end
|
46
51
|
|
47
52
|
def option_switch(param, resource_name_map)
|
48
|
-
'--' + optionamize(aliased(param
|
53
|
+
'--' + optionamize(aliased(param, resource_name_map))
|
49
54
|
end
|
50
55
|
|
51
56
|
def option_type(param, resource_name_map)
|
52
|
-
aliased(param
|
57
|
+
aliased(param, resource_name_map).upcase.gsub('-', '_')
|
53
58
|
end
|
54
59
|
|
55
60
|
def option_desc(param)
|
@@ -61,20 +66,33 @@ module HammerCLI::Apipie
|
|
61
66
|
opts[:required] = true if (param.required? and require_options?)
|
62
67
|
if param.expected_type == :array || param.validator =~ /Array/i
|
63
68
|
opts[:format] = HammerCLI::Options::Normalizers::List.new
|
69
|
+
elsif param.expected_type == 'boolean' || param.validator =~ /Boolean/i
|
70
|
+
opts[:format] = HammerCLI::Options::Normalizers::Bool.new
|
64
71
|
end
|
65
72
|
opts[:attribute_name] = HammerCLI.option_accessor_name(param.name)
|
73
|
+
opts[:referenced_resource] = resource_name(param)
|
74
|
+
|
66
75
|
return opts
|
67
76
|
end
|
68
77
|
|
69
|
-
def aliased(
|
70
|
-
resource_name =
|
71
|
-
|
72
|
-
if
|
73
|
-
return
|
74
|
-
|
75
|
-
|
78
|
+
def aliased(param, resource_name_map)
|
79
|
+
resource_name = resource_name(param)
|
80
|
+
|
81
|
+
if resource_name.nil?
|
82
|
+
return param.name
|
83
|
+
else
|
84
|
+
aliased_name = resource_name_map[resource_name.to_s] || resource_name_map[resource_name.to_sym] || resource_name
|
85
|
+
return param.name.gsub(resource_name, aliased_name.to_s)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def resource_name(param)
|
90
|
+
if (param.name =~ /^id[s]?$/)
|
91
|
+
@resource.singular_name
|
92
|
+
elsif(param.name =~ /_id[s]?$/)
|
93
|
+
param.name.to_s.gsub(/_id[s]?$/, "")
|
76
94
|
else
|
77
|
-
|
95
|
+
nil
|
78
96
|
end
|
79
97
|
end
|
80
98
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'options')
|
2
|
+
|
3
|
+
module HammerCLI::Apipie
|
4
|
+
|
5
|
+
class OptionDefinition < HammerCLI::Options::OptionDefinition
|
6
|
+
|
7
|
+
attr_accessor :referenced_resource
|
8
|
+
|
9
|
+
def initialize(switches, type, description, options = {})
|
10
|
+
if options.has_key? :referenced_resource
|
11
|
+
self.referenced_resource = options.delete(:referenced_resource).to_s if options[:referenced_resource]
|
12
|
+
end
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -1,36 +1,18 @@
|
|
1
1
|
require 'apipie_bindings'
|
2
2
|
module HammerCLI::Apipie
|
3
3
|
|
4
|
-
class AbstractCredentials
|
5
|
-
|
6
|
-
def to_params
|
7
|
-
{}
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def ask_user(prompt, silent=false)
|
13
|
-
if silent
|
14
|
-
ask(prompt) {|q| q.echo = false}
|
15
|
-
else
|
16
|
-
ask(prompt)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
4
|
|
23
5
|
class ApipieConnector < HammerCLI::AbstractConnector
|
24
6
|
|
25
7
|
attr_reader :api
|
26
8
|
|
27
9
|
def initialize(params)
|
28
|
-
credentials = params.delete(:credentials)
|
29
|
-
params.merge!(credentials.to_params) if credentials
|
30
|
-
|
31
10
|
@api = ApipieBindings::API.new(params)
|
11
|
+
if HammerCLI::Settings.get(:_params, :reload_cache) || HammerCLI::Settings.get(:reload_cache)
|
12
|
+
@api.clean_cache
|
13
|
+
Logging.logger['Init'].debug 'Apipie cache was cleared'
|
14
|
+
end
|
32
15
|
end
|
33
|
-
|
34
16
|
end
|
35
17
|
|
36
18
|
|
@@ -17,6 +17,8 @@ module HammerCLI
|
|
17
17
|
[RestClient::ResourceNotFound, :handle_not_found],
|
18
18
|
[RestClient::Unauthorized, :handle_unauthorized],
|
19
19
|
[ApipieBindings::DocLoadingError, :handle_apipie_docloading_error],
|
20
|
+
[ApipieBindings::MissingArgumentsError, :handle_apipie_missing_arguments_error],
|
21
|
+
[HammerCLI::ModuleDisabledButRequired, :handle_generic_config_error]
|
20
22
|
]
|
21
23
|
end
|
22
24
|
|
@@ -48,10 +50,10 @@ module HammerCLI
|
|
48
50
|
output.print_message(msg)
|
49
51
|
end
|
50
52
|
|
51
|
-
def log_full_error(e)
|
53
|
+
def log_full_error(e, message = e.message)
|
52
54
|
backtrace = e.backtrace || []
|
53
|
-
error = "\n\n#{e.class} (#{
|
54
|
-
backtrace.join("\n ")
|
55
|
+
error = "\n\n#{e.class} (#{message}):\n " +
|
56
|
+
backtrace.join("\n ") +
|
55
57
|
"\n\n"
|
56
58
|
@logger.error error
|
57
59
|
end
|
@@ -95,8 +97,18 @@ module HammerCLI
|
|
95
97
|
HammerCLI::EX_CONFIG
|
96
98
|
end
|
97
99
|
|
98
|
-
|
99
|
-
|
100
|
-
|
100
|
+
def handle_apipie_missing_arguments_error(e)
|
101
|
+
message = _("Missing arguments for %s") % "'#{e.params.join("', '")}'"
|
102
|
+
print_error message
|
103
|
+
log_full_error e, message
|
104
|
+
HammerCLI::EX_USAGE
|
105
|
+
end
|
101
106
|
|
107
|
+
def handle_generic_config_error(e)
|
108
|
+
print_error e.message
|
109
|
+
log_full_error e
|
110
|
+
HammerCLI::EX_CONFIG
|
111
|
+
end
|
102
112
|
|
113
|
+
end
|
114
|
+
end
|
data/lib/hammer_cli/i18n.rb
CHANGED
data/lib/hammer_cli/main.rb
CHANGED
@@ -6,6 +6,8 @@ module HammerCLI
|
|
6
6
|
|
7
7
|
option ["-v", "--verbose"], :flag, _("be verbose"), :context_target => :verbose
|
8
8
|
option ["-d", "--debug"], :flag, _("show debugging output "), :context_target => :debug
|
9
|
+
option ["-r", "--reload-cache"], :flag, _("force reload of Apipie cache")
|
10
|
+
|
9
11
|
option ["-c", "--config"], "CFG_FILE", _("path to custom config file")
|
10
12
|
|
11
13
|
option ["-u", "--username"], "USERNAME", _("username to access the remote system"),
|
data/lib/hammer_cli/modules.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
-
|
2
1
|
module HammerCLI
|
3
2
|
|
4
3
|
class Modules
|
5
4
|
|
6
5
|
def self.names
|
6
|
+
enabled_modules.sort
|
7
|
+
end
|
7
8
|
|
9
|
+
def self.enabled_modules
|
8
10
|
# legacy modules config
|
9
11
|
modules = HammerCLI::Settings.get(:modules) || []
|
10
12
|
logger.warn _("Legacy configuration of modules detected. Check section about configuration in user manual") unless modules.empty?
|
11
13
|
|
12
14
|
HammerCLI::Settings.dump.inject(modules) do |names, (mod_name, mod_config)|
|
13
|
-
if
|
15
|
+
if is_module_config?(mod_config)
|
14
16
|
mod = ["hammer_cli_#{mod_name}"]
|
15
17
|
if mod_config[:enable_module]
|
16
18
|
names += mod
|
@@ -22,6 +24,22 @@ module HammerCLI
|
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
27
|
+
def self.disabled_modules
|
28
|
+
HammerCLI::Settings.dump.inject([]) do |names, (mod_name, mod_config)|
|
29
|
+
if is_module_config?(mod_config)
|
30
|
+
mod = "hammer_cli_#{mod_name}"
|
31
|
+
names << mod unless mod_config[:enable_module]
|
32
|
+
end
|
33
|
+
names
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.loaded_modules
|
38
|
+
Object.constants. \
|
39
|
+
select{ |c| c.to_s =~ /\AHammerCLI[A-Z]./ && Object.const_get(c).class == Module }. \
|
40
|
+
map{ |m| m.to_s.underscore }
|
41
|
+
end
|
42
|
+
|
25
43
|
def self.find_by_name(name)
|
26
44
|
possible_names = [
|
27
45
|
name.camelize,
|
@@ -64,9 +82,19 @@ module HammerCLI
|
|
64
82
|
HammerCLI::Modules.names.each do |m|
|
65
83
|
Modules.load(m)
|
66
84
|
end
|
85
|
+
loaded_for_deps = loaded_modules & disabled_modules
|
86
|
+
unless loaded_for_deps.empty?
|
87
|
+
message = _("Error: Some of the required modules are disabled in configuration: %s ") % loaded_for_deps.join(', ')
|
88
|
+
raise HammerCLI::ModuleDisabledButRequired.new(message)
|
89
|
+
end
|
67
90
|
end
|
68
91
|
|
69
92
|
protected
|
93
|
+
|
94
|
+
def self.is_module_config?(config)
|
95
|
+
config.kind_of?(Hash) && !config[:enable_module].nil?
|
96
|
+
end
|
97
|
+
|
70
98
|
def self.logger
|
71
99
|
Logging.logger['Modules']
|
72
100
|
end
|