mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
help command should sort output.
This commit is contained in:
parent
81b8dad51a
commit
99026e5c4d
2 changed files with 36 additions and 3 deletions
|
@ -227,11 +227,11 @@ class Pry
|
|||
output.puts
|
||||
help_text = heading("Command List: ") + "\n"
|
||||
|
||||
commands.each do |key, command|
|
||||
help_text << commands.map do |key, command|
|
||||
if command.description && !command.description.empty?
|
||||
help_text << "#{command.options[:listing]}".ljust(18) + command.description + "\n"
|
||||
end
|
||||
"#{command.options[:listing]}".ljust(18) + command.description
|
||||
end
|
||||
end.compact.sort.join("\n")
|
||||
|
||||
stagger_output(help_text)
|
||||
else
|
||||
|
|
|
@ -187,4 +187,37 @@ describe Pry::CommandSet do
|
|||
@set.command 'foo', "", :listing => 'bar' do;end
|
||||
@set.commands['foo'].options[:listing].should == 'bar'
|
||||
end
|
||||
|
||||
it "should provide a 'help' command" do
|
||||
context = Pry::CommandContext.new
|
||||
context.command_set = @set
|
||||
context.output = StringIO.new
|
||||
|
||||
lambda {
|
||||
@set.run_command(context, 'help')
|
||||
}.should.not.raise
|
||||
end
|
||||
|
||||
it "should sort the output of the 'help' command" do
|
||||
@set.command 'foo', "Fooerizes" do; end
|
||||
@set.command 'goo', "Gooerizes" do; end
|
||||
@set.command 'moo', "Mooerizes" do; end
|
||||
@set.command 'boo', "Booerizes" do; end
|
||||
|
||||
context = Pry::CommandContext.new
|
||||
context.command_set = @set
|
||||
context.output = StringIO.new
|
||||
|
||||
@set.run_command(context, 'help')
|
||||
|
||||
doc = context.output.string
|
||||
|
||||
order = [doc.index("boo"),
|
||||
doc.index("foo"),
|
||||
doc.index("goo"),
|
||||
doc.index("help"),
|
||||
doc.index("moo")]
|
||||
|
||||
order.should == order.sort
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue