Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
50d0e82d
Commit
50d0e82d
authored
Nov 28, 2010
by
Pieter Noordhuis
Browse files
Update help.h generator script to output man-style argument list
parent
2612e052
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
src/help.h
View file @
50d0e82d
This diff is collapsed.
Click to expand it.
utils/generate-command-help.rb
View file @
50d0e82d
#!/usr/bin/env ruby
#!/usr/bin/env ruby
require
'net/http'
require
'net/https'
require
'json'
require
'uri'
dest
=
ARGV
[
0
]
tmpl
=
File
.
read
'./utils/help.h'
url
=
URI
.
parse
'https://github.com/antirez/redis-doc/raw/master/commands.json'
client
=
Net
::
HTTP
.
new
url
.
host
,
url
.
port
client
.
use_ssl
=
true
res
=
client
.
get
url
.
path
def
argument
arg
def
argument
arg
name
=
arg
[
'
name
'
].
is_a?
(
Array
)
?
arg
[
'
name
'
].
join
(
' '
)
:
arg
[
'
name
'
]
name
=
arg
[
"
name
"
].
is_a?
(
Array
)
?
arg
[
"
name
"
].
join
(
" "
)
:
arg
[
"
name
"
]
name
=
arg
[
'
enum
'
].
join
'|'
if
'
enum
'
==
arg
[
'
type
'
]
name
=
arg
[
"
enum
"
].
join
"|"
if
"
enum
"
==
arg
[
"
type
"
]
name
=
arg
[
'
command
'
]
+
' '
+
name
if
arg
[
'
command
'
]
name
=
arg
[
"
command
"
]
+
" "
+
name
if
arg
[
"
command
"
]
if
arg
[
'
multiple
'
]
if
arg
[
"
multiple
"
]
name
=
"
(
#{
name
}
)
"
name
=
"
#{
name
}
[
#{
name
}
...]
"
name
+=
arg
[
'optional'
]
?
'*'
:
'+'
end
els
if
arg
[
'
optional
'
]
if
arg
[
"
optional
"
]
name
=
"
(
#{
name
}
)?
"
name
=
"
[
#{
name
}
]
"
end
end
name
name
end
end
def
arguments
command
def
arguments
command
return
'-'
unless
command
[
'
arguments
'
]
return
"-"
unless
command
[
"
arguments
"
]
command
[
'
arguments
'
].
map
do
|
arg
|
command
[
"
arguments
"
].
map
do
|
arg
|
argument
arg
argument
arg
end
.
join
' '
end
.
join
" "
end
end
case
res
def
commands
when
Net
::
HTTPSuccess
return
@commands
if
@commands
first
=
true
commands
=
JSON
.
parse
(
res
.
body
)
require
"net/http"
c
=
commands
.
map
do
|
key
,
command
|
require
"net/https"
buf
=
if
first
require
"json"
first
=
false
require
"uri"
' '
url
=
URI
.
parse
"https://github.com/antirez/redis-doc/raw/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
)
else
else
"
\n
,"
response
.
error!
end
end
buf
+=
" {
\"
#{
key
}
\"\n
"
+
" ,
\"
#{
arguments
(
command
)
}
\"\n
"
+
" ,
\"
#{
command
[
'summary'
]
}
\"\n
"
+
" , COMMAND_GROUP_
#{
command
[
'group'
].
upcase
}
\n
"
+
" ,
\"
#{
command
[
'since'
]
}
\"
}"
end
.
join
(
"
\n
"
)
puts
"
\n
// Auto-generated, do not edit.
\n
"
+
tmpl
.
sub
(
'__COMMANDS__'
,
c
)
else
res
.
error!
end
end
def
generate_commands
commands
.
to_a
.
sort
do
|
x
,
y
|
x
[
0
]
<=>
y
[
0
]
end
.
map
do
|
key
,
command
|
<<-
SPEC
{ "
#{
key
}
",
"
#{
arguments
(
command
)
}
",
"
#{
command
[
"summary"
]
}
",
COMMAND_GROUP_
#{
command
[
"group"
].
upcase
}
,
"
#{
command
[
"since"
]
}
" }
SPEC
end
.
join
(
", "
)
end
# Write to stdout
tmpl
=
File
.
read
"./utils/help.h"
puts
"
\n
// Auto-generated, do not edit.
\n
"
+
tmpl
.
sub
(
"__COMMANDS__"
,
generate_commands
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment