Back to home page

Redis cross reference

 
 

    


0001 #!/usr/bin/env ruby
0002 
0003 GROUPS = [
0004   "generic",
0005   "string",
0006   "list",
0007   "set",
0008   "sorted_set",
0009   "hash",
0010   "pubsub",
0011   "transactions",
0012   "connection",
0013   "server",
0014   "scripting"
0015 ].freeze
0016 
0017 GROUPS_BY_NAME = Hash[*
0018   GROUPS.each_with_index.map do |n,i|
0019     [n,i]
0020   end.flatten
0021 ].freeze
0022 
0023 def argument arg
0024   name = arg["name"].is_a?(Array) ? arg["name"].join(" ") : arg["name"]
0025   name = arg["enum"].join "|" if "enum" == arg["type"]
0026   name = arg["command"] + " " + name if arg["command"]
0027   if arg["multiple"]
0028     name = "#{name} [#{name} ...]"
0029   end
0030   if arg["optional"]
0031     name = "[#{name}]"
0032   end
0033   name
0034 end
0035 
0036 def arguments command
0037   return "-" unless command["arguments"]
0038   command["arguments"].map do |arg|
0039     argument arg
0040   end.join " "
0041 end
0042 
0043 def commands
0044   return @commands if @commands
0045 
0046   require
0047   require
0048   require
0049   require
0050   require
0051 
0052   url = URI.parse "https://raw.github.com/antirez/redis-doc/master/commands.json"
0053   client = Net::HTTP.new url.host, url.port
0054   client.use_ssl = true
0055   response = client.get url.path
0056   if response.is_a?(Net::HTTPSuccess)
0057     @commands = JSON.parse(response.body)
0058   else
0059     response.error!
0060   end
0061 end
0062 
0063 def generate_groups
0064   GROUPS.map do |n|
0065     "\"#{n}\""
0066   end.join(",\n    ");
0067 end
0068 
0069 def generate_commands
0070   commands.to_a.sort do |x,y|
0071     x[0] <=> y[0]
0072   end.map do |key, command|
0073     group = GROUPS_BY_NAME[command["group"]]
0074     if group.nil?
0075       STDERR.puts "Please update groups array in #{__FILE__}"
0076       raise "Unknown group #{command["group"]}"
0077     end
0078 
0079     ret = <<-SPEC
0080 { "#{key}",
0081     "#{arguments(command)}",
0082     "#{command["summary"]}",
0083     #{group},
0084     "#{command["since"]}" }
0085     SPEC
0086     ret.strip
0087   end.join(",\n    ")
0088 end
0089 
0090 # Write to stdout
0091 puts <<-HELP_H
0092 /* Automatically generated by #{__FILE__}, do not edit. */
0093 
0094 #ifndef __REDIS_HELP_H
0095 #define __REDIS_HELP_H
0096 
0097 static char *commandGroups[] = {
0098     #{generate_groups}
0099 };
0100 
0101 struct commandHelp {
0102   char *name;
0103   char *params;
0104   char *summary;
0105   int group;
0106   char *since;
0107 } commandHelp[] = {
0108     #{generate_commands}
0109 };
0110 
0111 #endif
0112 HELP_H
0113