-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes terminal completion command for odo (#5856)
* Fixes terminal completion command for odo <!-- Thank you for opening a PR! Here are some things you need to know before submitting: 1. Please read our developer guideline: https://github.com/redhat-developer/odo/wiki/Dev:-odo-Dev-Guidelines 2. Label this PR accordingly with the '/kind' line 3. Ensure you have written and ran the appropriate tests: https://github.com/redhat-developer/odo/wiki/Dev:-Writing-and-running-tests 4. Read how we approve and LGTM each PR: https://github.com/redhat-developer/odo/wiki/Pull-Requests:-Review-guideline Documentation: If you are pushing a change to documentation, please read: https://github.com/redhat-developer/odo/wiki/Documentation:-Contributing --> **What type of PR is this:** <!-- Add one of the following kinds: /kind bug /kind feature /kind tests /kind documentation Feel free to use other [labels](https://github.com/redhat-developer/odo/labels) as needed. However one of the above labels must be present or the PR will not be reviewed. This instruction is for reviewers as well. --> /kind cleanup **What does this PR do / why we need it:** This PR: * Changes the command `odo utils terminal` to `odo completion` similar to kubectl. * Re-enables / fixes the terminal completion command support for bash, zsh, fish and powershelll * Updates Cobra to 1.13 to enable support for autocompleting descriptive commands. **Which issue(s) this PR fixes:** <!-- Specifying the issue will automatically close it when this PR is merged --> Fixes #5536 **How to test changes / Special notes to the reviewer:** Signed-off-by: Charlie Drage <charlie@charliedrage.com> * Update pkg/odo/cli/completion/completion.go Co-authored-by: Parthvi Vala <pvala@redhat.com> * Update pkg/odo/cli/completion/completion.go Co-authored-by: Parthvi Vala <pvala@redhat.com> * Update pkg/odo/cli/completion/completion.go Co-authored-by: Parthvi Vala <pvala@redhat.com> * Update pkg/odo/cli/completion/completion.go Co-authored-by: Parthvi Vala <pvala@redhat.com> * Remove hiding the output flag Signed-off-by: Charlie Drage <charlie@charliedrage.com> * Update pkg/odo/cli/completion/completion.go Co-authored-by: Parthvi Vala <pvala@redhat.com> * Fix Signed-off-by: Charlie Drage <charlie@charliedrage.com> * Update pkg/odo/cli/completion/completion.go Co-authored-by: Parthvi Vala <pvala@redhat.com> * fix help menu Signed-off-by: Charlie Drage <charlie@charliedrage.com> * fix vendoring * Fix vendoring * Fix descriptions * add viper * Revert back to old style * Update vendoring * Remove commented out code * ignore validation Co-authored-by: Parthvi Vala <pvala@redhat.com>
- Loading branch information
1 parent
c2abde1
commit 2217725
Showing
6 changed files
with
99 additions
and
211 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
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,94 @@ | ||
package completion | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/redhat-developer/odo/pkg/odo/util" | ||
"github.com/spf13/cobra" | ||
|
||
ktemplates "k8s.io/kubectl/pkg/util/templates" | ||
) | ||
|
||
const ( | ||
RecommendedCommandName = "completion" | ||
) | ||
|
||
var ( | ||
completionExample = ktemplates.Examples(` # BASH | ||
## Load into your current shell environment | ||
source <(%[1]s bash) | ||
## Load persistently | ||
### Save the completion to a file | ||
%[1]s bash > ~/.odo/completion.bash.inc | ||
### Load the completion from within your $HOME/.bash_profile | ||
source ~/.odo/completion.bash.inc | ||
# ZSH | ||
## Load into your current shell environment | ||
source <(odo zsh) | ||
## Load persistently | ||
%[1]s zsh > "${fpath[1]}/_odo" | ||
# FISH | ||
## Load into your current shell environment | ||
source <(%[1]s fish) | ||
## Load persistently | ||
%[1]s fish > ~/.config/fish/completions/odo.fish | ||
# POWERSHELL | ||
## Load into your current shell environment | ||
%[1]s powershell | Out-String | Invoke-Expression | ||
## Load persistently | ||
%[1]s powershell >> $PROFILE | ||
`) | ||
completionLongDesc = ktemplates.LongDesc(`Add odo completion support to your development environment. | ||
This will append your PS1 environment variable with odo component and application information.`) | ||
) | ||
|
||
// NewCmdCompletion implements the utils completion odo command | ||
func NewCmdCompletion(name, fullName string) *cobra.Command { | ||
completionCmd := &cobra.Command{ | ||
Use: name, | ||
Short: "Add odo completion support to your development environment", | ||
Long: completionLongDesc, | ||
Example: fmt.Sprintf(completionExample, fullName), | ||
DisableFlagsInUseLine: true, | ||
ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, | ||
Args: cobra.ExactValidArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Below we ignore the error returns in order to pass golint validation | ||
// We will handle the error in the main function / output when the user inputs `odo completion`. | ||
switch args[0] { | ||
case "bash": | ||
_ = cmd.Root().GenBashCompletion(os.Stdout) | ||
case "zsh": | ||
// Due to https://github.com/spf13/cobra/issues/1529 we cannot load zsh | ||
// via using source, so we need to add compdef to the beginning of the output so we can easily do: | ||
// source <(odo completion zsh) | ||
zsh := "#compdef odo\ncompdef _odo odo\n" | ||
out := os.Stdout | ||
_, _ = out.Write([]byte(zsh)) | ||
_ = cmd.Root().GenZshCompletion(out) | ||
case "fish": | ||
_ = cmd.Root().GenFishCompletion(os.Stdout, true) | ||
case "powershell": | ||
_ = cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout) | ||
} | ||
}, | ||
} | ||
|
||
completionCmd.SetUsageTemplate(util.CmdUsageTemplate) | ||
completionCmd.Annotations = map[string]string{"command": "utility"} | ||
return completionCmd | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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