Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge "Generate right help for 'run' command."

  • Loading branch information...
commit 459d12dc88273b572feff7fc57343b21067f4f68 2 parents e61801f + b3c2bf4
@kowshik kowshik authored Gerrit Code Review committed
Showing with 139 additions and 89 deletions.
  1. +23 −1 warden/lib/warden/repl_v2.rb
  2. +116 −88 warden/spec/repl_v2_spec.rb
View
24 warden/lib/warden/repl_v2.rb
@@ -72,6 +72,11 @@ def describe_commands(command_list_width = 0)
end
command_descriptions.each_pair do |command, description|
+ # TODO: Need to eliminate special case for run command.
+ if command == "run"
+ description = self.class.run_command_description
+ end
+
text << "\t%-#{command_list_width}s%s\n" % [command, description]
end
@@ -105,6 +110,7 @@ def process_command(command_args)
STDERR.write(response.data) if stream_name == "stderr"
end
+ # TODO: Need to eliminate special case for run command.
command = to_stream_command(command) if type == :run
response = @client.stream(command, &process_stream)
command_info[:exit_status] = response.exit_status if type == :run
@@ -133,8 +139,17 @@ def describe_response(serialized_response)
def describe_command(command_info)
cmd_name = command_info.keys[0]
cmd_help = command_info[cmd_name]
+
usage = "command: #{cmd_name}\n"
- usage << "description: #{cmd_help[:description]}\n"
+ usage << "description: "
+ # TODO: Need to eliminate special case for run command.
+ if cmd_name == :run
+ usage << self.class.run_command_description
+ else
+ usage << "#{cmd_help[:description]}"
+ end
+ usage << "\n"
+
options = describe_options(cmd_help, 1)
if options && !options.empty?
@@ -184,5 +199,12 @@ def restore_history
history.map {|line| Readline::HISTORY.push line}
end
end
+
+ def self.run_command_description
+ description = "Short hand for spawn(stream(cmd))"
+ description << " i.e. spawns a command, streams the result."
+
+ description
+ end
end
end
View
204 warden/spec/repl_v2_spec.rb
@@ -161,129 +161,157 @@
before :each do
@client = mock("warden client")
Warden::Client.should_receive(:new).once.with("/tmp/warden.sock")
- .and_return(@client)
- Warden::Protocol::Type.should_receive(:generate_klass_map)
- .with("Request").and_return(test_klass_map)
+ .and_return(@client)
end
- it "should add command trace to output" do
- request = response = SimpleTest.new
- request.field = "field"
+ context "handle run command" do
+ before :each do
+ Warden::Protocol::Type.should_receive(:generate_klass_map)
+ .with("Request").and_return({1 => Warden::Protocol::RunRequest})
+ end
- @client.should_receive(:connected?).once.and_return(true)
- @client.should_receive(:call).once.with(request).and_return(response)
+ it "should convert run command to spawn and stream commands" do
+ run_request = Warden::Protocol::RunRequest.new
+ run_request.handle = "handle"
+ run_request.script = "script"
- repl = described_class.new(:trace => true)
+ spawn_request = Warden::Protocol::SpawnRequest.new
+ spawn_request.handle = run_request.handle
+ spawn_request.script = run_request.script
- command_info = repl.process_line("simple_test --field field")
- expected = "+ simple_test --field field\nfield : field\n"
- command_info.keys.should == [:result]
- command_info[:result].should =~ /^\+ simple_test --field field\n.*/
- end
+ spawn_response = Warden::Protocol::SpawnResponse.new
+ spawn_response.job_id = 10
- it "should serialize response from warden server" do
- request = response = SimpleTest.new
- request.field = "field"
+ stream_request = Warden::Protocol::StreamRequest.new
+ stream_request.handle = run_request.handle
+ stream_request.job_id = spawn_response.job_id
- @client.should_receive(:connected?).once.and_return(true)
- @client.should_receive(:call).once.with(request).and_return(response)
+ stream_data = Warden::Protocol::StreamResponse.new
+ stream_data.name = "stdout"
+ stream_data.data = "stdout"
- repl = described_class.new
+ stream_exit = Warden::Protocol::StreamResponse.new
+ stream_exit.exit_status = 1
- command_info = repl.process_line("simple_test --field field")
- expected = "+ simple_test --field field\nfield : field\n"
- command_info.should == {:result => "field : field\n"}
- end
+ @client.should_receive(:connected?).once.and_return(true)
+ @client.should_receive(:call).once.with(spawn_request)
+ .and_return(spawn_response)
+ @client.should_receive(:stream).once.with(stream_request)
+ .and_yield(stream_data).and_return(stream_exit)
- it "should convert run command to spawn and stream commands" do
- run_request = Warden::Protocol::RunRequest.new
- run_request.handle = "handle"
- run_request.script = "script"
+ STDOUT.should_receive(:write).once.with("stdout")
- spawn_request = Warden::Protocol::SpawnRequest.new
- spawn_request.handle = run_request.handle
- spawn_request.script = run_request.script
+ repl = described_class.new
+ command_info = repl.process_line("run --handle handle --script script")
+ end
- spawn_response = Warden::Protocol::SpawnResponse.new
- spawn_response.job_id = 10
+ it "should generate right description for run command in global help" do
+ repl = described_class.new
+ command_info = repl.process_line("--help")
- stream_request = Warden::Protocol::StreamRequest.new
- stream_request.handle = run_request.handle
- stream_request.job_id = spawn_response.job_id
+ width = Warden::Protocol::RunRequest.type_underscored.size + 2
+ expected = "\n"
+ expected << "\trun #{described_class.run_command_description}\n"
+ expected << "\thelp Show help.\n"
+ expected << "\n"
+ expected << "Use --help with each command for more information."
+ expected << "\n"
- stream_data = Warden::Protocol::StreamResponse.new
- stream_data.name = "stdout"
- stream_data.data = "stdout"
+ command_info[:result].should == expected
+ end
- stream_exit = Warden::Protocol::StreamResponse.new
- stream_exit.exit_status = 1
+ it "should generate right description for run command help" do
+ repl = described_class.new
+ command_info = repl.process_line("run --help")
+ command_info[:result]
+ .index("description: #{described_class.run_command_description}").
+ should be > 0
+ end
+ end
- @client.should_receive(:connected?).once.and_return(true)
- @client.should_receive(:call).once.with(spawn_request)
- .and_return(spawn_response)
- @client.should_receive(:stream).once.with(stream_request)
- .and_yield(stream_data).and_return(stream_exit)
+ context "handle other commands" do
+ before :each do
+ Warden::Protocol::Type.should_receive(:generate_klass_map)
+ .with("Request").and_return(test_klass_map)
+ end
+ it "should add command trace to output" do
+ request = response = SimpleTest.new
+ request.field = "field"
- repl = described_class.new
+ @client.should_receive(:connected?).once.and_return(true)
+ @client.should_receive(:call).once.with(request).and_return(response)
- repl.should_receive(:deserialize).once.with(["run",
- "--handle", "handle",
- "--script", "script"])
- .and_return(run_request)
+ repl = described_class.new(:trace => true)
- STDOUT.should_receive(:write).once.with("stdout")
+ command_info = repl.process_line("simple_test --field field")
+ expected = "+ simple_test --field field\nfield : field\n"
+ command_info.keys.should == [:result]
+ command_info[:result].should =~ /^\+ simple_test --field field\n.*/
+ end
- command_info = repl.process_line("run --handle handle --script script")
- end
+ it "should serialize response from warden server" do
+ request = response = SimpleTest.new
+ request.field = "field"
- it "should generate prettified global help" do
- repl = described_class.new
+ @client.should_receive(:connected?).once.and_return(true)
+ @client.should_receive(:call).once.with(request).and_return(response)
- command_info = repl.process_line("--help")
+ repl = described_class.new
- width = NestedFieldsHelpTest.type_underscored.size + 2
- expected = "\n"
- test_desc_map.each_pair do |command, description|
- expected << "\t%-#{width}s%s\n" % [command, description]
+ command_info = repl.process_line("simple_test --field field")
+ expected = "+ simple_test --field field\nfield : field\n"
+ command_info.should == {:result => "field : field\n"}
end
- expected << "\t%-#{width}s%s\n" % ["help", "Show help."]
- expected << "\n"
- expected << "Use --help with each command for more information."
- expected << "\n"
+ it "should generate prettified global help" do
+ repl = described_class.new
- command_info[:result].should == expected
- end
+ command_info = repl.process_line("--help")
- it "should generate prettified command help for simple command" do
- repl = described_class.new
+ width = NestedFieldsHelpTest.type_underscored.size + 2
+ expected = "\n"
+ test_desc_map.each_pair do |command, description|
+ expected << "\t%-#{width}s%s\n" % [command, description]
+ end
- command_info = repl.process_line("simple_test --help")
+ expected << "\t%-#{width}s%s\n" % ["help", "Show help."]
+ expected << "\n"
+ expected << "Use --help with each command for more information."
+ expected << "\n"
- expected = "command: #{SimpleTest.type_underscored}\n"
- expected << "description: #{SimpleTest.description}\n"
- expected << "usage: #{SimpleTest.type_underscored} [options]\n\n"
- expected << "[options] can be one of the following:\n\n"
- expected << "\t--field <field> (string) # required\n"
+ command_info[:result].should == expected
+ end
- command_info[:result].should == expected
- end
+ it "should generate prettified command help for simple command" do
+ repl = described_class.new
+
+ command_info = repl.process_line("simple_test --help")
- it "should generate prettified command help for complex command" do
- repl = described_class.new
+ expected = "command: #{SimpleTest.type_underscored}\n"
+ expected << "description: #{SimpleTest.description}\n"
+ expected << "usage: #{SimpleTest.type_underscored} [options]\n\n"
+ expected << "[options] can be one of the following:\n\n"
+ expected << "\t--field <field> (string) # required\n"
- command_info = repl.process_line("mixed_test --help")
+ command_info[:result].should == expected
+ end
- expected = "command: #{MixedTest.type_underscored}\n"
- expected << "description: #{MixedTest.description}\n"
- expected << "usage: #{MixedTest.type_underscored} [options]\n\n"
- expected << "[options] can be one of the following:\n\n"
- expected << "\t--bool_field # required\n"
- expected << "\t--complex_field[index] # array\n"
- expected << "\t\t.field <field> (string) # required\n"
+ it "should generate prettified command help for complex command" do
+ repl = described_class.new
- command_info[:result].should == expected
+ command_info = repl.process_line("mixed_test --help")
+
+ expected = "command: #{MixedTest.type_underscored}\n"
+ expected << "description: #{MixedTest.description}\n"
+ expected << "usage: #{MixedTest.type_underscored} [options]\n\n"
+ expected << "[options] can be one of the following:\n\n"
+ expected << "\t--bool_field # required\n"
+ expected << "\t--complex_field[index] # array\n"
+ expected << "\t\t.field <field> (string) # required\n"
+
+ command_info[:result].should == expected
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.