]>
Commit | Line | Data |
---|---|---|
5397f2b5 TH |
1 | #!/usr/bin/env ruby |
2 | ||
3 | require 'net/http' | |
4 | require 'net/https' | |
5 | require 'json' | |
6 | require 'uri' | |
7 | ||
8 | dest = ARGV[0] | |
9 | tmpl = File.read './utils/help.h' | |
10 | ||
11 | url = URI.parse 'https://github.com/antirez/redis-doc/raw/master/commands.json' | |
12 | client = Net::HTTP.new url.host, url.port | |
13 | client.use_ssl = true | |
14 | res = client.get url.path | |
15 | ||
16 | def argument arg | |
17 | name = arg['name'].is_a?(Array) ? arg['name'].join(' ') : arg['name'] | |
18 | name = arg['enum'].join '|' if 'enum' == arg['type'] | |
19 | name = arg['command'] + ' ' + name if arg['command'] | |
20 | if arg['multiple'] | |
21 | name = "(#{name})" | |
22 | name += arg['optional'] ? '*' : '+' | |
23 | elsif arg['optional'] | |
24 | name = "(#{name})?" | |
25 | end | |
26 | name | |
27 | end | |
28 | ||
29 | def arguments command | |
30 | return '-' unless command['arguments'] | |
31 | command['arguments'].map do |arg| | |
32 | argument arg | |
33 | end.join ' ' | |
34 | end | |
35 | ||
36 | case res | |
37 | when Net::HTTPSuccess | |
38 | first = true | |
39 | commands = JSON.parse(res.body) | |
40 | c = commands.map do |key, command| | |
41 | buf = if first | |
42 | first = false | |
43 | ' ' | |
44 | else | |
45 | "\n ," | |
46 | end | |
47 | buf += " { \"#{key}\"\n" + | |
48 | " , \"#{arguments(command)}\"\n" + | |
49 | " , \"#{command['summary']}\"\n" + | |
50 | " , COMMAND_GROUP_#{command['group'].upcase}\n" + | |
51 | " , \"#{command['since']}\" }" | |
52 | end.join("\n") | |
53 | puts "\n// Auto-generated, do not edit.\n" + tmpl.sub('__COMMANDS__', c) | |
54 | else | |
55 | res.error! | |
56 | end |