-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from juanibiapina/new-completions
New completions system
- Loading branch information
Showing
23 changed files
with
381 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "sub" | ||
version = "2.1.0" | ||
version = "2.2.0" | ||
description = "Dynamically generate rich CLIs from scripts." | ||
authors = ["Juan Ibiapina <[email protected]>"] | ||
edition = "2021" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env bats | ||
|
||
load test_helper | ||
|
||
@test "completions: without arguments, lists commands" { | ||
fixture "completions-old" | ||
|
||
run main --completions | ||
|
||
assert_success | ||
assert_output "$(main --commands)" | ||
} | ||
|
||
@test "completions: fails gracefully when command is not found" { | ||
fixture "completions-old" | ||
|
||
run main --completions not-found | ||
|
||
assert_failure | ||
assert_output "" | ||
} | ||
|
||
@test "completions: invokes command completions" { | ||
fixture "completions-old" | ||
|
||
run main --completions with-completions | ||
|
||
assert_success | ||
assert_output "comp1 | ||
comp2" | ||
} | ||
|
||
@test "completions: lists nothing if command provides no completions" { | ||
fixture "completions-old" | ||
|
||
run main --completions no-completions | ||
|
||
assert_success | ||
assert_output "" | ||
} | ||
|
||
@test "completions: displays for directory commands" { | ||
fixture "completions-old" | ||
|
||
run main --completions directory | ||
|
||
assert_success | ||
assert_output "$(main --commands directory)" | ||
} | ||
|
||
@test "completions: displays double nested directory commands" { | ||
fixture "completions-old" | ||
|
||
run main --completions directory double | ||
|
||
assert_success | ||
assert_output "$(main --commands directory double)" | ||
} | ||
|
||
@test "completions: displays double nested subcommands" { | ||
fixture "completions-old" | ||
|
||
run main --completions directory double with-completions | ||
|
||
assert_success | ||
assert_output "comp11 | ||
comp21" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
$SUB_BIN --color never --name main --executable "${BASH_SOURCE[0]}" --relative ".." -- "$@" |
Empty file.
8 changes: 8 additions & 0 deletions
8
integration/fixtures/completions-old/libexec/directory/double/with-completions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Provide completions | ||
if [ "$1" = "--complete" ]; then | ||
echo comp11 | ||
echo comp21 | ||
exit | ||
fi |
Empty file.
8 changes: 8 additions & 0 deletions
8
integration/fixtures/completions-old/libexec/with-completions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Provide completions | ||
if [ "$1" = "--complete" ]; then | ||
echo comp1 | ||
echo comp2 | ||
exit | ||
fi |
14 changes: 8 additions & 6 deletions
14
integration/fixtures/completions/libexec/directory/double/with-completions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Usage: {cmd} <option> | ||
# Options: | ||
# option(script): Description of the option | ||
|
||
# Provide completions | ||
if [ "$1" = "--complete" ]; then | ||
echo comp11 | ||
echo comp21 | ||
exit | ||
fi | ||
set -e | ||
|
||
echo "comp11" | ||
echo "comp21" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Usage: {cmd} | ||
|
||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,29 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Usage: {cmd} <option1> <option2> | ||
# Options: | ||
# option1 (script): Description of option 1 | ||
# option2 (script): Description of option 2 | ||
|
||
# Provide completions | ||
if [ "$1" = "--complete" ]; then | ||
echo comp1 | ||
echo comp2 | ||
exit | ||
set -e | ||
|
||
if [[ "$_MAIN_COMPLETE" == "true" ]]; then | ||
if [[ "$_MAIN_COMPLETE_ARG" == "option1" ]]; then | ||
echo "comp1" | ||
echo "comp2" | ||
|
||
exit 0 | ||
fi | ||
|
||
if [[ "$_MAIN_COMPLETE_ARG" == "option2" ]]; then | ||
echo "comp3" | ||
echo "comp4" | ||
|
||
exit 0 | ||
fi | ||
|
||
exit 201 | ||
fi | ||
|
||
exit 202 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.