This repository has been archived by the owner on Sep 28, 2021. It is now read-only.
Completion on bash #184
Merged
Merged
Completion on bash #184
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4758b5e
Attempt to fix bash support
gabbaxx 6b95ff0
Attempt 2 to fix bash support
gabbaxx a080c73
Attempt 2 to fix bash support
gabbaxx bf34974
Attempt 2 to fix bash support
gabbaxx 0dcb633
Merge remote-tracking branch 'origin/master' into completion_on_bash
gabbaxx a5ae38c
Attempt 2 to fix bash support
gabbaxx File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"fmt" | ||
"net/http" | ||
"os" | ||
"runtime" | ||
"strings" | ||
|
||
"github.com/qlik-oss/corectl/internal" | ||
|
@@ -79,8 +80,6 @@ func Execute(mainVersion string) { | |
|
||
func init() { | ||
rootCmd.PersistentFlags().StringVarP(&explicitConfigFile, "config", "c", "", "path/to/config.yml where parameters can be set instead of on the command line") | ||
// Set annotation to run bash completion function for the config flag and only show .yaml or .yml files | ||
rootCmd.PersistentFlags().SetAnnotation("config", cobra.BashCompFilenameExt, []string{"yaml", "yml"}) | ||
|
||
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Logs extra information") | ||
viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose")) | ||
|
@@ -103,35 +102,27 @@ func init() { | |
|
||
rootCmd.PersistentFlags().StringP("app", "a", "", "App name, if no app is specified a session app is used instead.") | ||
viper.BindPFlag("app", rootCmd.PersistentFlags().Lookup("app")) | ||
// Set annotation to run bash completion function for the app flag | ||
// Set annotation to run bash completion function | ||
rootCmd.PersistentFlags().SetAnnotation("app", cobra.BashCompCustom, []string{"__corectl_get_apps"}) | ||
|
||
for _, command := range []*cobra.Command{buildCmd, setAllCmd} { | ||
// Don't bind these to viper since paths are treated separately to support relative paths! | ||
command.PersistentFlags().String("connections", "", "Path to a yml file containing the data connection definitions") | ||
// Set annotation to run bash completion function for the connections flag and only show .yml or .yaml files | ||
command.PersistentFlags().SetAnnotation("connections", cobra.BashCompFilenameExt, []string{"yml", "yaml"}) | ||
} | ||
|
||
for _, command := range []*cobra.Command{buildCmd, setAllCmd} { | ||
// Don't bind these to viper since paths are treated separately to support relative paths! | ||
command.PersistentFlags().String("dimensions", "", "A list of generic dimension json paths") | ||
// Set annotation to run bash completion function for the dimensions flag and only show .json files | ||
command.PersistentFlags().SetAnnotation("dimensions", cobra.BashCompFilenameExt, []string{"json"}) | ||
} | ||
|
||
for _, command := range []*cobra.Command{buildCmd, setAllCmd} { | ||
// Don't bind these to viper since paths are treated separately to support relative paths! | ||
command.PersistentFlags().String("measures", "", "A list of generic measures json paths") | ||
// Set annotation to run bash completion function for the measures flag and only show .json files | ||
command.PersistentFlags().SetAnnotation("measures", cobra.BashCompFilenameExt, []string{"json"}) | ||
} | ||
|
||
for _, command := range []*cobra.Command{buildCmd, setAllCmd} { | ||
// Don't bind these to viper since paths are treated separately to support relative paths! | ||
command.PersistentFlags().String("objects", "", "A list of generic object json paths") | ||
// Set annotation to run bash completion function for the objects flag and only show .json files | ||
command.PersistentFlags().SetAnnotation("objects", cobra.BashCompFilenameExt, []string{"json"}) | ||
} | ||
|
||
for _, command := range []*cobra.Command{buildCmd, reloadCmd} { | ||
|
@@ -145,8 +136,6 @@ func init() { | |
for _, command := range []*cobra.Command{buildCmd, setAllCmd} { | ||
// Don't bind these to viper since paths are treated separately to support relative paths! | ||
command.PersistentFlags().String("script", "", "path/to/reload-script.qvs that contains a qlik reload script. If omitted the last specified reload script for the current app is reloaded") | ||
// Set annotation to run bash completion function for the script flag and only show .qvs files | ||
command.PersistentFlags().SetAnnotation("script", cobra.BashCompFilenameExt, []string{"qvs"}) | ||
} | ||
|
||
for _, command := range []*cobra.Command{getAppsCmd, getConnectionsCmd, getDimensionsCmd, getMeasuresCmd, getObjectsCmd} { | ||
|
@@ -156,8 +145,13 @@ func init() { | |
for _, command := range []*cobra.Command{removeCmd} { | ||
command.PersistentFlags().Bool("suppress", false, "Suppress all confirmation dialogues") | ||
} | ||
|
||
catwalkCmd.PersistentFlags().String("catwalk-url", "https://catwalk.core.qlik.com", "Url to an instance of catwalk, if not provided the qlik one will be used.") | ||
|
||
if runtime.GOOS != "windows" { | ||
// Do not add bash completion annotations for paths and files as they are not compatible with windows. On windows | ||
// we instead rely on the default bash behavior | ||
addFileRelatedBashAnnotations() | ||
} | ||
} | ||
|
||
// GetRelativeParameter returns a parameter from the config file. | ||
|
@@ -249,47 +243,43 @@ const bashCompletionFunc = ` | |
echo "$result"; | ||
} | ||
|
||
__corectl_render_compreply() | ||
__corectl_call_corectl() | ||
{ | ||
if [[ $? -eq 0 ]]; then | ||
COMPREPLY+=( "${1[@]}" ) | ||
else | ||
COMPREPLY+=( $( compgen -W "" -- "$cur" ) ) | ||
fi | ||
local flags=$(__extract_flags_to_forward ${words[@]}) | ||
local corectl_out | ||
local errorcode | ||
corectl_out=$(corectl $1 $flags 2>/dev/null) | ||
errorcode=$? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move this to a common function for all commands? |
||
if [[ errorcode -eq 0 ]]; then | ||
local IFS=$'\n' | ||
COMPREPLY=( $(compgen -W "${corectl_out}" -- "$cur") ) | ||
else | ||
COMPREPLY=() | ||
fi; | ||
} | ||
|
||
__corectl_get_dimensions() | ||
{ | ||
local flags=$(__extract_flags_to_forward ${words[@]}) | ||
local corectl_out=$(corectl get dimensions --bash $flags 2>/dev/null) | ||
__corectl_render_compreply "${corectl_out[*]}" | ||
__corectl_call_corectl "get dimensions --bash" | ||
} | ||
|
||
__corectl_get_measures() | ||
{ | ||
local flags=$(__extract_flags_to_forward ${words[@]}) | ||
local corectl_out=$(corectl get measures --bash $flags 2>/dev/null) | ||
__corectl_render_compreply "${corectl_out[*]}" | ||
__corectl_call_corectl "get measures --bash" | ||
} | ||
|
||
__corectl_get_objects() | ||
{ | ||
local flags=$(__extract_flags_to_forward ${words[@]}) | ||
local corectl_out=$(corectl get objects --bash $flags 2>/dev/null) | ||
__corectl_render_compreply "${corectl_out[*]}" | ||
__corectl_call_corectl "get objects --bash" | ||
} | ||
|
||
__corectl_get_connections() | ||
{ | ||
local flags=$(__extract_flags_to_forward ${words[@]}) | ||
local corectl_out=$(corectl get connections --bash $flags 2>/dev/null) | ||
__corectl_render_compreply "${corectl_out[*]}" | ||
__corectl_call_corectl "get connections --bash" | ||
} | ||
|
||
__corectl_get_apps() | ||
{ | ||
local config=$(__extract_flags_to_forward ${words[@]}) | ||
local corectl_out=$(corectl get apps --bash $config 2>/dev/null) | ||
__corectl_render_compreply "${corectl_out[*]}" | ||
__corectl_call_corectl "get apps --bash" | ||
} | ||
` |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment to why this is not applicable for windows