Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
aa669943
Commit
aa669943
authored
Jun 07, 2015
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make_bash_completion.py: Support Python 3.4
parent
e857e99d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
doc/bash_completion/make_bash_completion.py
doc/bash_completion/make_bash_completion.py
+9
-6
No files found.
doc/bash_completion/make_bash_completion.py
View file @
aa669943
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
__future__
import
print_function
import
subprocess
import
subprocess
from
StringIO
import
StringIO
import
io
import
re
import
re
import
sys
import
sys
import
os.path
import
os.path
...
@@ -14,10 +17,10 @@ class Option:
...
@@ -14,10 +17,10 @@ class Option:
def
get_all_options
(
cmd
):
def
get_all_options
(
cmd
):
opt_pattern
=
re
.
compile
(
r' (?:(-.), )?(--[^\s\[=]+)(\[)?'
)
opt_pattern
=
re
.
compile
(
r' (?:(-.), )?(--[^\s\[=]+)(\[)?'
)
proc
=
subprocess
.
Popen
([
cmd
,
"--help"
],
stdout
=
subprocess
.
PIPE
)
proc
=
subprocess
.
Popen
([
cmd
,
"--help"
],
stdout
=
subprocess
.
PIPE
)
stdoutdata
,
stderrdata
=
proc
.
communicate
()
stdoutdata
,
_
=
proc
.
communicate
()
cur_option
=
None
cur_option
=
None
opts
=
{}
opts
=
{}
for
line
in
StringIO
(
stdoutdata
):
for
line
in
io
.
StringIO
(
stdoutdata
.
decode
(
'utf-8'
)
):
match
=
opt_pattern
.
match
(
line
)
match
=
opt_pattern
.
match
(
line
)
if
not
match
:
if
not
match
:
continue
continue
...
@@ -45,7 +48,7 @@ _{name}()
...
@@ -45,7 +48,7 @@ _{name}()
-*)
-*)
COMPREPLY=( $( compgen -W '
\
COMPREPLY=( $( compgen -W '
\
'''
)
'''
)
for
opt
in
opts
.
iter
values
():
for
opt
in
opts
.
values
():
out
.
write
(
opt
.
long_opt
)
out
.
write
(
opt
.
long_opt
)
out
.
write
(
' '
)
out
.
write
(
' '
)
...
@@ -66,8 +69,8 @@ complete -F _{name} {name}
...
@@ -66,8 +69,8 @@ complete -F _{name} {name}
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
<
2
:
if
len
(
sys
.
argv
)
<
2
:
print
"Generates bash_completion using `/path/to/cmd --help'"
print
(
"Generates bash_completion using `/path/to/cmd --help'"
)
print
"Usage: make_bash_completion.py /path/to/cmd"
print
(
"Usage: make_bash_completion.py /path/to/cmd"
)
exit
(
1
)
exit
(
1
)
name
=
os
.
path
.
basename
(
sys
.
argv
[
1
])
name
=
os
.
path
.
basename
(
sys
.
argv
[
1
])
opts
=
get_all_options
(
sys
.
argv
[
1
])
opts
=
get_all_options
(
sys
.
argv
[
1
])
...
...
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