forked from grafana/tanka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds CLI-completion support to tanka 🎉 The main workflow commands (show, diff, apply) now support completing the environment. This is done using a combination of spf13/cobra and posener/complete. Supported shells are bash, zsh and fish. Install using `tk --install-completion`
- Loading branch information
Showing
10 changed files
with
214 additions
and
157 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
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 |
---|---|---|
@@ -1,31 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/sh0rez/tanka/pkg/jpath" | ||
) | ||
|
||
func completionCommand(rootCmd *cobra.Command) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "completion bash|zsh", | ||
Example: ` | ||
eval "$(tk completion bash)" | ||
eval "$(tk completion zsh)" | ||
`, | ||
Short: `create bash/zsh auto-completion.`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
switch shell := strings.ToLower(args[0]); shell { | ||
case "bash": | ||
return rootCmd.GenBashCompletion(os.Stdout) | ||
case "zsh": | ||
return rootCmd.GenZshCompletion(os.Stdout) | ||
default: | ||
return fmt.Errorf("unknown shell %q. Only bash and zsh are supported", shell) | ||
} | ||
}, | ||
// findBaseDirs searches for possible environments | ||
func findBaseDirs() (dirs []string) { | ||
pwd, err := os.Getwd() | ||
if err != nil { | ||
return | ||
} | ||
_, _, _, err = jpath.Resolve(pwd) | ||
if err == jpath.ErrorNoRoot { | ||
return | ||
} | ||
|
||
if err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error { | ||
if _, err := os.Stat(filepath.Join(path, "main.jsonnet")); err == nil { | ||
dirs = append(dirs, path) | ||
} | ||
return nil | ||
}); err != nil { | ||
log.Fatalln(err) | ||
} | ||
return dirs | ||
} |
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.