Skip to content

Commit

Permalink
F #4943: alphabetical order cmds, opts and format (#42)
Browse files Browse the repository at this point in the history
(cherry picked from commit 32d8b9b)
  • Loading branch information
Alejandro Huertas Herrero authored and rsmontero committed Apr 13, 2021
1 parent 7e7d6e4 commit ac1fec1
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/cli/command_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ def command(name, desc, *args_format, &block)
cmd[:arity]+=1 unless args.include?(nil)
cmd[:args_format] << args
elsif args.instance_of?(Hash) && args[:options]
if args[:options].is_a? Array
args[:options].flatten!
args[:options] = args[:options].sort_by {|o| o[:name] }
end

cmd[:options] << args[:options]
else
cmd[:arity]+=1
Expand Down Expand Up @@ -679,7 +684,9 @@ def print_command_help(name)
def print_options
puts "## OPTIONS"
shown_opts = Array.new
shown_opts = []
options = []
@command_list.each do |key|
value = @commands[key]
Expand All @@ -688,14 +695,17 @@ def print_options
next
else
shown_opts << o[:name]
print_option(o)
options << o
end
end
end
@available_options.each do |o|
print_option o
options << @available_options
options.flatten!
options = options.sort_by {|o| o[:name] }
options.each do |o|
print_option(o)
end
end
Expand Down Expand Up @@ -724,6 +734,8 @@ def print_commands
else
puts "## COMMANDS"
@command_list.sort! if @command_list
@command_list.each do |key|
value = @commands[key]
printf cmd_format5, "* #{key} "
Expand Down Expand Up @@ -766,6 +778,9 @@ def print_formatters
cmd_format5 = "#{' '*3}%s"
cmd_format10 = "#{' '*8}%s"
@formats = @formats.sort_by {|key, _| key } if @formats
@formats.each{ |key,value|
printf cmd_format5, "* #{key}"
puts
Expand Down

0 comments on commit ac1fec1

Please sign in to comment.