summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2010-11-28 17:45:58 +0100
committerPieter Noordhuis <pcnoordhuis@gmail.com>2010-11-28 17:45:58 +0100
commit50d0e82d54d9fcc7f42443a9cde51d812934b3c1 (patch)
tree5b614911e7fdaa5e86677d2dbbed419e8f39ace1 /utils
parent2612e0521fde55db2c720092d4ad02a8f015f46e (diff)
downloadredis-50d0e82d54d9fcc7f42443a9cde51d812934b3c1.tar.gz
Update help.h generator script to output man-style argument list
Diffstat (limited to 'utils')
-rwxr-xr-xutils/generate-command-help.rb93
1 files changed, 48 insertions, 45 deletions
diff --git a/utils/generate-command-help.rb b/utils/generate-command-help.rb
index 250a2159e..4b2f25a15 100755
--- a/utils/generate-command-help.rb
+++ b/utils/generate-command-help.rb
@@ -1,56 +1,59 @@
#!/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
- name = arg['name'].is_a?(Array) ? arg['name'].join(' ') : arg['name']
- name = arg['enum'].join '|' if 'enum' == arg['type']
- name = arg['command'] + ' ' + name if arg['command']
- if arg['multiple']
- name = "(#{name})"
- name += arg['optional'] ? '*' : '+'
- elsif arg['optional']
- name = "(#{name})?"
+ name = arg["name"].is_a?(Array) ? arg["name"].join(" ") : arg["name"]
+ name = arg["enum"].join "|" if "enum" == arg["type"]
+ name = arg["command"] + " " + name if arg["command"]
+ if arg["multiple"]
+ name = "#{name} [#{name} ...]"
+ end
+ if arg["optional"]
+ name = "[#{name}]"
end
name
end
def arguments command
- return '-' unless command['arguments']
- command['arguments'].map do |arg|
+ return "-" unless command["arguments"]
+ command["arguments"].map do |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
-case res
-when Net::HTTPSuccess
- first = true
- commands = JSON.parse(res.body)
- c = commands.map do |key, command|
- buf = if first
- first = false
- ' '
- else
- "\n ,"
- end
- buf += " { \"#{key}\"\n" +
- " , \"#{arguments(command)}\"\n" +
- " , \"#{command['summary']}\"\n" +
- " , COMMAND_GROUP_#{command['group'].upcase}\n" +
- " , \"#{command['since']}\" }"
- end.join("\n")
- puts "\n// Auto-generated, do not edit.\n" + tmpl.sub('__COMMANDS__', c)
-else
- res.error!
-end \ No newline at end of file
+def generate_commands
+ 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)
+