hammer_cli 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +13 -5
- data/config/cli_config.template.yml +12 -3
- data/doc/creating_apipie_commands.md +53 -56
- data/doc/creating_commands.md +25 -19
- data/doc/developer_docs.md +3 -2
- data/doc/development_tips.md +3 -3
- data/doc/i18n.md +3 -3
- data/doc/installation.md +24 -207
- data/doc/installation_deb.md +48 -0
- data/doc/installation_gem.md +30 -0
- data/doc/installation_rpm.md +53 -0
- data/doc/installation_source.md +31 -0
- data/doc/option_builders.md +77 -0
- data/doc/option_normalizers.md +5 -5
- data/doc/writing_a_plugin.md +9 -9
- data/lib/hammer_cli.rb +1 -0
- data/lib/hammer_cli/abstract.rb +21 -8
- data/lib/hammer_cli/apipie.rb +1 -2
- data/lib/hammer_cli/apipie/command.rb +37 -64
- data/lib/hammer_cli/apipie/option_builder.rb +69 -0
- data/lib/hammer_cli/apipie/options.rb +1 -61
- data/lib/hammer_cli/clamp.rb +15 -0
- data/lib/hammer_cli/i18n.rb +14 -2
- data/lib/hammer_cli/logger.rb +1 -1
- data/lib/hammer_cli/option_builder.rb +43 -0
- data/lib/hammer_cli/options/option_definition.rb +6 -0
- data/lib/hammer_cli/output/adapter/abstract.rb +2 -2
- data/lib/hammer_cli/output/adapter/base.rb +6 -3
- data/lib/hammer_cli/output/adapter/table.rb +19 -2
- data/lib/hammer_cli/output/definition.rb +4 -0
- data/lib/hammer_cli/output/fields.rb +9 -0
- data/lib/hammer_cli/output/formatters.rb +20 -8
- data/lib/hammer_cli/utils.rb +1 -1
- data/lib/hammer_cli/version.rb +1 -1
- data/locale/hammer-cli.pot +103 -79
- data/test/unit/abstract_test.rb +62 -0
- data/test/unit/apipie/command_test.rb +12 -197
- data/test/unit/apipie/option_builder_test.rb +110 -0
- data/test/unit/i18n_test.rb +50 -0
- data/test/unit/option_builder_test.rb +33 -0
- data/test/unit/output/adapter/abstract_test.rb +26 -3
- data/test/unit/output/adapter/base_test.rb +20 -3
- data/test/unit/output/adapter/csv_test.rb +2 -2
- data/test/unit/output/adapter/table_test.rb +24 -1
- data/test/unit/output/definition_test.rb +13 -0
- data/test/unit/output/formatters_test.rb +17 -1
- data/test/unit/utils_test.rb +1 -1
- metadata +101 -88
- data/lib/hammer_cli/apipie/read_command.rb +0 -41
- data/lib/hammer_cli/apipie/write_command.rb +0 -49
- data/test/unit/apipie/read_command_test.rb +0 -37
- data/test/unit/apipie/write_command_test.rb +0 -41
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'hammer_cli/output/dsl'
|
2
|
-
|
3
|
-
module HammerCLI::Apipie
|
4
|
-
|
5
|
-
class ReadCommand < Command
|
6
|
-
|
7
|
-
def execute
|
8
|
-
d = retrieve_data
|
9
|
-
logger.debug "Retrieved data: " + d.ai(:raw => true) if HammerCLI::Settings.get(:log_api_calls)
|
10
|
-
print_data d
|
11
|
-
return HammerCLI::EX_OK
|
12
|
-
end
|
13
|
-
|
14
|
-
protected
|
15
|
-
def retrieve_data
|
16
|
-
raise "resource or action not defined" unless self.class.resource_defined?
|
17
|
-
logger.debug request_params.ai
|
18
|
-
if resource && resource.has_action?(action)
|
19
|
-
resource.call(action, request_params, request_headers)
|
20
|
-
else
|
21
|
-
raise HammerCLI::OperationNotSupportedError, "The server does not support such operation."
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def print_data(records)
|
26
|
-
print_collection(output_definition, records)
|
27
|
-
end
|
28
|
-
|
29
|
-
def request_headers
|
30
|
-
{}
|
31
|
-
end
|
32
|
-
|
33
|
-
def request_params
|
34
|
-
method_options
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'hammer_cli/messages'
|
2
|
-
|
3
|
-
module HammerCLI::Apipie
|
4
|
-
|
5
|
-
class WriteCommand < Command
|
6
|
-
|
7
|
-
include HammerCLI::Messages
|
8
|
-
|
9
|
-
def execute
|
10
|
-
print_success_message(send_request)
|
11
|
-
return HammerCLI::EX_OK
|
12
|
-
end
|
13
|
-
|
14
|
-
protected
|
15
|
-
|
16
|
-
def success_message_params(response)
|
17
|
-
response
|
18
|
-
end
|
19
|
-
|
20
|
-
def print_success_message(response)
|
21
|
-
if success_message
|
22
|
-
print_message(
|
23
|
-
success_message,
|
24
|
-
success_message_params(response)
|
25
|
-
)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def send_request
|
30
|
-
if resource && resource.has_action?(action)
|
31
|
-
resource.call(action, request_params, request_headers)
|
32
|
-
else
|
33
|
-
raise HammerCLI::OperationNotSupportedError, "The server does not support such operation."
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def request_headers
|
38
|
-
{}
|
39
|
-
end
|
40
|
-
|
41
|
-
def request_params
|
42
|
-
method_options
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../test_helper')
|
2
|
-
|
3
|
-
|
4
|
-
describe HammerCLI::Apipie::ReadCommand do
|
5
|
-
|
6
|
-
class TestReadCommand < HammerCLI::Apipie::ReadCommand
|
7
|
-
def self.resource_config
|
8
|
-
{ :apidoc_cache_dir => 'test/unit/fixtures/apipie', :apidoc_cache_name => 'architectures' }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:cmd_class) { TestReadCommand.dup }
|
13
|
-
let(:cmd) { cmd_class.new("", { :adapter => :silent, :interactive => false }) }
|
14
|
-
let(:cmd_run) { cmd.run([]) }
|
15
|
-
|
16
|
-
it "should raise exception when no action is defined" do
|
17
|
-
cmd.stubs(:handle_exception).returns(HammerCLI::EX_SOFTWARE)
|
18
|
-
cmd_run.must_equal HammerCLI::EX_SOFTWARE
|
19
|
-
end
|
20
|
-
|
21
|
-
context "resource defined" do
|
22
|
-
|
23
|
-
before :each do
|
24
|
-
HammerCLI::Connection.drop_all
|
25
|
-
ApipieBindings::API.any_instance.stubs(:call).returns([])
|
26
|
-
cmd_class.resource :architectures, :index
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should perform a call to api when resource is defined" do
|
30
|
-
cmd_run.must_equal 0
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../test_helper')
|
2
|
-
|
3
|
-
describe HammerCLI::Apipie::WriteCommand do
|
4
|
-
|
5
|
-
class TestWriteCommand < HammerCLI::Apipie::WriteCommand
|
6
|
-
def self.resource_config
|
7
|
-
{ :apidoc_cache_dir => 'test/unit/fixtures/apipie', :apidoc_cache_name => 'architectures' }
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:cmd) { TestWriteCommand.new("") }
|
12
|
-
let(:cmd_run) { cmd.run([]) }
|
13
|
-
|
14
|
-
it "should raise exception when no action is defined" do
|
15
|
-
cmd.stubs(:handle_exception).returns(HammerCLI::EX_SOFTWARE)
|
16
|
-
cmd_run.must_equal HammerCLI::EX_SOFTWARE
|
17
|
-
end
|
18
|
-
|
19
|
-
context "resource defined" do
|
20
|
-
|
21
|
-
before :each do
|
22
|
-
HammerCLI::Connection.drop_all
|
23
|
-
ApipieBindings::API.any_instance.stubs(:call).returns([])
|
24
|
-
cmd.class.resource :architectures, :index
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should perform a call to api when resource is defined" do
|
28
|
-
cmd_run.must_equal 0
|
29
|
-
end
|
30
|
-
|
31
|
-
context "output" do
|
32
|
-
it "should print success message" do
|
33
|
-
cmd.class.success_message "XXX"
|
34
|
-
proc { cmd_run }.must_output /.*XXX.*/
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|