Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(reportbug): parse various option args from option help #852

Merged
merged 2 commits into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 6 additions & 28 deletions completions/reportbug
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,19 @@ _reportbug()
done)' -- "$cur"))
return
;;
--bts | -!(-*)B)
COMPREPLY=($(compgen -W "debian guug kde mandrake help" -- \
"$cur"))
--tag | --ui | --interface | --type | --bts | --severity | --mode | -!(-*)[TutBS])
akinomyoga marked this conversation as resolved.
Show resolved Hide resolved
COMPREPLY+=($(
compgen -W \
'$("$1" $prev help 2>&1 | sed -ne /^[[:space:]]/p)' \
akinomyoga marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'$("$1" $prev help 2>&1 | sed -ne /^[[:space:]]/p)' \
'$("$1" $prev help 2>&1 </dev/null | sed -ne "/^[[:space:]]/p")' \

I also suggest quoting the regex passed to sed. I noticed that sed -ne /^[[:space:]]/p produces an error message and outputs the help text of sed in my Debian 10. This is caused by nullglob: the word /^[[:space:]]/p contains a glob pattern [[:space:]] matching nothing, so sed receives just an option -ne as its commandline arguments.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry. This workaround turned out to fail to produce the candidates. I expected that help should output candidates even without stdin, but it seems to fail when stdin is redirected /dev/null. I'll think about an alternative workaround.

-- "$cur"
))
return
;;
--editor | --mua | --mbox-reader-cmd | -!(-*)e)
compopt -o filenames
COMPREPLY=($(compgen -c -- "$cur"))
return
;;
--mode)
COMPREPLY=($(compgen -W "novice standard expert" -- "$cur"))
return
;;
--severity | -!(-*)S)
COMPREPLY=($(compgen -W "grave serious important normal minor
wishlist" -- "$cur"))
return
;;
--ui | --interface | -!(-*)u)
COMPREPLY=($(compgen -W "newt text gnome" -- "$cur"))
return
;;
--type | -!(-*)t)
COMPREPLY=($(compgen -W "gnats debbugs" -- "$cur"))
return
;;
--tag | -!(-*)T)
COMPREPLY=($(compgen -W "none woody potato sarge sarge-ignore
etch etch-ignore lenny lenny-ignore sid experimental confirmed
d-i fixed fixed-in-experimental fixed-upstream help l10n
moreinfo patch pending security unreproducible upstream wontfix
ipv6 lfs" -- "$cur"))
return
;;
--from-buildd)
COMPREPLY=($(compgen -S "_" -W '$(apt-cache dumpavail | \
command grep "^Source: $cur" | sort -u | cut -f2 -d" ")'))
Expand Down
4 changes: 4 additions & 0 deletions test/t/test_reportbug.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ class TestReportbug:
@pytest.mark.complete("reportbug --m", require_cmd=True)
def test_1(self, completion):
assert completion

@pytest.mark.complete("reportbug --bts=", require_cmd=True)
def test_bts(self, completion):
assert "default" in completion