提交 50d0e82d 编写于 作者: P Pieter Noordhuis

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

上级 2612e052
此差异已折叠。
#!/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
def commands
return @commands if @commands
require "net/http"
require "net/https"
require "json"
require "uri"
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
response = client.get url.path
if response.is_a?(Net::HTTPSuccess)
@commands = JSON.parse(response.body)
else
response.error!
end
end end
case res def generate_commands
when Net::HTTPSuccess commands.to_a.sort do |x,y|
first = true x[0] <=> y[0]
commands = JSON.parse(res.body) end.map do |key, command|
c = commands.map do |key, command| <<-SPEC
buf = if first { "#{key}",
first = false "#{arguments(command)}",
' ' "#{command["summary"]}",
else COMMAND_GROUP_#{command["group"].upcase},
"\n ," "#{command["since"]}" }
end SPEC
buf += " { \"#{key}\"\n" + end.join(", ")
" , \"#{arguments(command)}\"\n" + end
" , \"#{command['summary']}\"\n" +
" , COMMAND_GROUP_#{command['group'].upcase}\n" + # Write to stdout
" , \"#{command['since']}\" }" tmpl = File.read "./utils/help.h"
end.join("\n") puts "\n// Auto-generated, do not edit.\n" + tmpl.sub("__COMMANDS__", generate_commands)
puts "\n// Auto-generated, do not edit.\n" + tmpl.sub('__COMMANDS__', c)
else
res.error!
end
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册