diff options
Diffstat (limited to 'utils/generate-command-help.rb')
-rwxr-xr-x | utils/generate-command-help.rb | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/utils/generate-command-help.rb b/utils/generate-command-help.rb index 482a3b9f8..3ef00b3b5 100755 --- a/utils/generate-command-help.rb +++ b/utils/generate-command-help.rb @@ -1,4 +1,9 @@ -#!/usr/bin/env ruby +#!/usr/bin/env ruby -w +# Usage: generate-command-help.r [path/to/commands.json] +# or: generate-commands-json.py | generate-command-help.rb - +# +# Defaults to downloading commands.json from the redis-doc repo if not provided +# or STDINed. GROUPS = [ "generic", @@ -66,16 +71,27 @@ def commands require "net/https" require "json" require "uri" - - url = URI.parse "https://raw.githubusercontent.com/redis/redis-doc/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) + if ARGV.length > 0 + if ARGV[0] == '-' + data = STDIN.read + elsif FileTest.exist? ARGV[0] + data = File.read(ARGV[0]) + else + raise Exception.new "File not found: #{ARGV[0]}" + end else - response.error! + url = URI.parse "https://raw.githubusercontent.com/redis/redis-doc/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) + response.error! + return + else + data = response.body + end end + @commands = JSON.parse(data) end def generate_groups |