2010-11-16 13:50:26 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2010-11-28 20:37:19 +00:00
|
|
|
GROUPS = [
|
|
|
|
"generic",
|
|
|
|
"string",
|
|
|
|
"list",
|
|
|
|
"set",
|
|
|
|
"sorted_set",
|
|
|
|
"hash",
|
|
|
|
"pubsub",
|
|
|
|
"transactions",
|
|
|
|
"connection",
|
2012-04-03 13:29:47 +00:00
|
|
|
"server",
|
2014-04-22 14:13:58 +00:00
|
|
|
"scripting",
|
2015-11-17 14:38:34 +00:00
|
|
|
"hyperloglog",
|
|
|
|
"cluster",
|
|
|
|
"geo"
|
2010-11-28 20:37:19 +00:00
|
|
|
].freeze
|
|
|
|
|
|
|
|
GROUPS_BY_NAME = Hash[*
|
|
|
|
GROUPS.each_with_index.map do |n,i|
|
|
|
|
[n,i]
|
|
|
|
end.flatten
|
|
|
|
].freeze
|
|
|
|
|
2010-11-16 13:50:26 +00:00
|
|
|
def argument arg
|
2010-11-28 16:45:58 +00:00
|
|
|
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}]"
|
2010-11-16 13:50:26 +00:00
|
|
|
end
|
|
|
|
name
|
|
|
|
end
|
|
|
|
|
|
|
|
def arguments command
|
2010-11-28 16:45:58 +00:00
|
|
|
return "-" unless command["arguments"]
|
|
|
|
command["arguments"].map do |arg|
|
2010-11-16 13:50:26 +00:00
|
|
|
argument arg
|
2010-11-28 16:45:58 +00:00
|
|
|
end.join " "
|
|
|
|
end
|
|
|
|
|
|
|
|
def commands
|
|
|
|
return @commands if @commands
|
|
|
|
|
2010-12-15 16:39:40 +00:00
|
|
|
require "rubygems"
|
2010-11-28 16:45:58 +00:00
|
|
|
require "net/http"
|
|
|
|
require "net/https"
|
|
|
|
require "json"
|
|
|
|
require "uri"
|
|
|
|
|
2014-08-05 07:12:40 +00:00
|
|
|
url = URI.parse "https://raw.githubusercontent.com/antirez/redis-doc/master/commands.json"
|
2010-11-28 16:45:58 +00:00
|
|
|
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
|
2010-11-16 13:50:26 +00:00
|
|
|
end
|
|
|
|
|
2010-11-28 20:37:19 +00:00
|
|
|
def generate_groups
|
|
|
|
GROUPS.map do |n|
|
|
|
|
"\"#{n}\""
|
|
|
|
end.join(",\n ");
|
|
|
|
end
|
|
|
|
|
2010-11-28 16:45:58 +00:00
|
|
|
def generate_commands
|
|
|
|
commands.to_a.sort do |x,y|
|
|
|
|
x[0] <=> y[0]
|
|
|
|
end.map do |key, command|
|
2010-11-28 20:37:19 +00:00
|
|
|
group = GROUPS_BY_NAME[command["group"]]
|
|
|
|
if group.nil?
|
|
|
|
STDERR.puts "Please update groups array in #{__FILE__}"
|
|
|
|
raise "Unknown group #{command["group"]}"
|
|
|
|
end
|
|
|
|
|
|
|
|
ret = <<-SPEC
|
2010-11-28 16:45:58 +00:00
|
|
|
{ "#{key}",
|
|
|
|
"#{arguments(command)}",
|
|
|
|
"#{command["summary"]}",
|
2010-11-28 20:37:19 +00:00
|
|
|
#{group},
|
2010-11-28 16:45:58 +00:00
|
|
|
"#{command["since"]}" }
|
|
|
|
SPEC
|
2010-11-28 20:37:19 +00:00
|
|
|
ret.strip
|
|
|
|
end.join(",\n ")
|
2010-11-28 16:45:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Write to stdout
|
2010-11-28 20:37:19 +00:00
|
|
|
puts <<-HELP_H
|
|
|
|
/* Automatically generated by #{__FILE__}, do not edit. */
|
|
|
|
|
|
|
|
#ifndef __REDIS_HELP_H
|
|
|
|
#define __REDIS_HELP_H
|
|
|
|
|
|
|
|
static char *commandGroups[] = {
|
|
|
|
#{generate_groups}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct commandHelp {
|
|
|
|
char *name;
|
|
|
|
char *params;
|
|
|
|
char *summary;
|
|
|
|
int group;
|
|
|
|
char *since;
|
|
|
|
} commandHelp[] = {
|
|
|
|
#{generate_commands}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
HELP_H
|
2010-11-28 16:45:58 +00:00
|
|
|
|