| 
									
										
										
										
											2010-11-16 21:50:26 +08:00
										 |  |  | #!/usr/bin/env ruby | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-29 04:37:19 +08:00
										 |  |  | GROUPS = [ | 
					
						
							|  |  |  |   "generic", | 
					
						
							|  |  |  |   "string", | 
					
						
							|  |  |  |   "list", | 
					
						
							|  |  |  |   "set", | 
					
						
							|  |  |  |   "sorted_set", | 
					
						
							|  |  |  |   "hash", | 
					
						
							|  |  |  |   "pubsub", | 
					
						
							|  |  |  |   "transactions", | 
					
						
							|  |  |  |   "connection", | 
					
						
							| 
									
										
										
										
											2012-04-03 21:29:47 +08:00
										 |  |  |   "server", | 
					
						
							| 
									
										
										
										
											2014-04-22 22:13:58 +08:00
										 |  |  |   "scripting", | 
					
						
							| 
									
										
										
										
											2015-11-17 22:38:34 +08:00
										 |  |  |   "hyperloglog", | 
					
						
							|  |  |  |   "cluster", | 
					
						
							| 
									
										
										
										
											2018-06-08 00:52:01 +08:00
										 |  |  |   "geo", | 
					
						
							|  |  |  |   "stream" | 
					
						
							| 
									
										
										
										
											2010-11-29 04:37:19 +08:00
										 |  |  | ].freeze | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GROUPS_BY_NAME = Hash[* | 
					
						
							|  |  |  |   GROUPS.each_with_index.map do |n,i| | 
					
						
							|  |  |  |     [n,i] | 
					
						
							|  |  |  |   end.flatten | 
					
						
							|  |  |  | ].freeze | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-16 21:50:26 +08:00
										 |  |  | def argument arg | 
					
						
							| 
									
										
										
										
											2020-11-30 21:00:16 +08:00
										 |  |  |   if "block" == arg["type"] | 
					
						
							|  |  |  |     name = arg["block"].map do |entry| | 
					
						
							|  |  |  |       argument entry | 
					
						
							|  |  |  |     end.join " " | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     name = arg["name"].is_a?(Array) ? arg["name"].join(" ") : arg["name"] | 
					
						
							|  |  |  |     name = arg["enum"].join "|" if "enum" == arg["type"] | 
					
						
							|  |  |  |     name = arg["command"] + (name ? " " + name : "") if arg["command"] | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-11-29 00:45:58 +08:00
										 |  |  |   if arg["multiple"] | 
					
						
							|  |  |  |     name = "#{name} [#{name} ...]" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |   if arg["optional"] | 
					
						
							|  |  |  |     name = "[#{name}]" | 
					
						
							| 
									
										
										
										
											2010-11-16 21:50:26 +08:00
										 |  |  |   end | 
					
						
							|  |  |  |   name | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def arguments command | 
					
						
							| 
									
										
										
										
											2010-11-29 00:45:58 +08:00
										 |  |  |   return "-" unless command["arguments"] | 
					
						
							|  |  |  |   command["arguments"].map do |arg| | 
					
						
							| 
									
										
										
										
											2010-11-16 21:50:26 +08:00
										 |  |  |     argument arg | 
					
						
							| 
									
										
										
										
											2010-11-29 00:45:58 +08:00
										 |  |  |   end.join " " | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def commands | 
					
						
							|  |  |  |   return @commands if @commands | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-16 00:39:40 +08:00
										 |  |  |   require "rubygems" | 
					
						
							| 
									
										
										
										
											2010-11-29 00:45:58 +08:00
										 |  |  |   require "net/http" | 
					
						
							|  |  |  |   require "net/https" | 
					
						
							|  |  |  |   require "json" | 
					
						
							|  |  |  |   require "uri" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-10 13:25:26 +08:00
										 |  |  |   url = URI.parse "https://raw.githubusercontent.com/redis/redis-doc/master/commands.json" | 
					
						
							| 
									
										
										
										
											2010-11-29 00:45:58 +08: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 21:50:26 +08:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-29 04:37:19 +08:00
										 |  |  | def generate_groups | 
					
						
							|  |  |  |   GROUPS.map do |n| | 
					
						
							|  |  |  |     "\"#{n}\"" | 
					
						
							|  |  |  |   end.join(",\n    "); | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-29 00:45:58 +08:00
										 |  |  | def generate_commands | 
					
						
							|  |  |  |   commands.to_a.sort do |x,y| | 
					
						
							|  |  |  |     x[0] <=> y[0] | 
					
						
							|  |  |  |   end.map do |key, command| | 
					
						
							| 
									
										
										
										
											2010-11-29 04:37:19 +08: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-29 00:45:58 +08:00
										 |  |  | { "#{key}", | 
					
						
							|  |  |  |     "#{arguments(command)}", | 
					
						
							|  |  |  |     "#{command["summary"]}", | 
					
						
							| 
									
										
										
										
											2010-11-29 04:37:19 +08:00
										 |  |  |     #{group}, | 
					
						
							| 
									
										
										
										
											2010-11-29 00:45:58 +08:00
										 |  |  |     "#{command["since"]}" } | 
					
						
							|  |  |  |     SPEC | 
					
						
							| 
									
										
										
										
											2010-11-29 04:37:19 +08:00
										 |  |  |     ret.strip | 
					
						
							|  |  |  |   end.join(",\n    ") | 
					
						
							| 
									
										
										
										
											2010-11-29 00:45:58 +08:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Write to stdout | 
					
						
							| 
									
										
										
										
											2010-11-29 04:37:19 +08: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-29 00:45:58 +08:00
										 |  |  | 
 |