]> git.saurik.com Git - redis.git/blobdiff - utils/generate-command-help.rb
Redis cluster stuff removed from 2.6 redis.conf file.
[redis.git] / utils / generate-command-help.rb
index 4b2f25a15ba0999461d74580a377b39838b0c828..96cccc2bfbc1a8e0be5cb4379c48c434068a1fde 100755 (executable)
@@ -1,5 +1,24 @@
 #!/usr/bin/env ruby
 
 #!/usr/bin/env ruby
 
+GROUPS = [
+  "generic",
+  "string",
+  "list",
+  "set",
+  "sorted_set",
+  "hash",
+  "pubsub",
+  "transactions",
+  "connection",
+  "server"
+].freeze
+
+GROUPS_BY_NAME = Hash[*
+  GROUPS.each_with_index.map do |n,i|
+    [n,i]
+  end.flatten
+].freeze
+
 def argument arg
   name = arg["name"].is_a?(Array) ? arg["name"].join(" ") : arg["name"]
   name = arg["enum"].join "|" if "enum" == arg["type"]
 def argument arg
   name = arg["name"].is_a?(Array) ? arg["name"].join(" ") : arg["name"]
   name = arg["enum"].join "|" if "enum" == arg["type"]
@@ -23,6 +42,7 @@ end
 def commands
   return @commands if @commands
 
 def commands
   return @commands if @commands
 
+  require "rubygems"
   require "net/http"
   require "net/https"
   require "json"
   require "net/http"
   require "net/https"
   require "json"
@@ -39,21 +59,54 @@ def commands
   end
 end
 
   end
 end
 
+def generate_groups
+  GROUPS.map do |n|
+    "\"#{n}\""
+  end.join(",\n    ");
+end
+
 def generate_commands
   commands.to_a.sort do |x,y|
     x[0] <=> y[0]
   end.map do |key, command|
 def generate_commands
   commands.to_a.sort do |x,y|
     x[0] <=> y[0]
   end.map do |key, command|
-    <<-SPEC
+    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
 { "#{key}",
     "#{arguments(command)}",
     "#{command["summary"]}",
 { "#{key}",
     "#{arguments(command)}",
     "#{command["summary"]}",
-    COMMAND_GROUP_#{command["group"].upcase},
+    #{group},
     "#{command["since"]}" }
     SPEC
     "#{command["since"]}" }
     SPEC
-  end.join(",  ")
+    ret.strip
+  end.join(",\n    ")
 end
 
 # Write to stdout
 end
 
 # Write to stdout
-tmpl = File.read "./utils/help.h"
-puts "\n// Auto-generated, do not edit.\n" + tmpl.sub("__COMMANDS__", generate_commands)
+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