Update help.h generator script to output man-style argument list

This commit is contained in:
Pieter Noordhuis 2010-11-28 17:45:58 +01:00
parent 2612e0521f
commit 50d0e82d54
2 changed files with 628 additions and 739 deletions

1274
src/help.h

File diff suppressed because it is too large Load Diff

View File

@ -1,56 +1,59 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'net/http'
require 'net/https'
require 'json'
require 'uri'
dest = ARGV[0]
tmpl = File.read './utils/help.h'
url = URI.parse 'https://github.com/antirez/redis-doc/raw/master/commands.json'
client = Net::HTTP.new url.host, url.port
client.use_ssl = true
res = client.get url.path
def argument arg def argument arg
name = arg['name'].is_a?(Array) ? arg['name'].join(' ') : arg['name'] name = arg["name"].is_a?(Array) ? arg["name"].join(" ") : arg["name"]
name = arg['enum'].join '|' if 'enum' == arg['type'] name = arg["enum"].join "|" if "enum" == arg["type"]
name = arg['command'] + ' ' + name if arg['command'] name = arg["command"] + " " + name if arg["command"]
if arg['multiple'] if arg["multiple"]
name = "(#{name})" name = "#{name} [#{name} ...]"
name += arg['optional'] ? '*' : '+' end
elsif arg['optional'] if arg["optional"]
name = "(#{name})?" name = "[#{name}]"
end end
name name
end end
def arguments command def arguments command
return '-' unless command['arguments'] return "-" unless command["arguments"]
command['arguments'].map do |arg| command["arguments"].map do |arg|
argument arg argument arg
end.join ' ' end.join " "
end end
case res def commands
when Net::HTTPSuccess return @commands if @commands
first = true
commands = JSON.parse(res.body) require "net/http"
c = commands.map do |key, command| require "net/https"
buf = if first require "json"
first = false require "uri"
' '
else url = URI.parse "https://github.com/antirez/redis-doc/raw/master/commands.json"
"\n ," client = Net::HTTP.new url.host, url.port
end client.use_ssl = true
buf += " { \"#{key}\"\n" + response = client.get url.path
" , \"#{arguments(command)}\"\n" + if response.is_a?(Net::HTTPSuccess)
" , \"#{command['summary']}\"\n" + @commands = JSON.parse(response.body)
" , COMMAND_GROUP_#{command['group'].upcase}\n" + else
" , \"#{command['since']}\" }" response.error!
end.join("\n") end
puts "\n// Auto-generated, do not edit.\n" + tmpl.sub('__COMMANDS__', c) end
else
res.error! def generate_commands
end commands.to_a.sort do |x,y|
x[0] <=> y[0]
end.map do |key, command|
<<-SPEC
{ "#{key}",
"#{arguments(command)}",
"#{command["summary"]}",
COMMAND_GROUP_#{command["group"].upcase},
"#{command["since"]}" }
SPEC
end.join(", ")
end
# Write to stdout
tmpl = File.read "./utils/help.h"
puts "\n// Auto-generated, do not edit.\n" + tmpl.sub("__COMMANDS__", generate_commands)