Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 18 additions & 13 deletions cli/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,22 +355,27 @@ func (t *autoCompleter) Do(line []rune, pos int) (options [][]rune, offset int)
return nil, 0
}

autocompleteAPIArgs := []string{"listall=true"}
if autocompleteAPI.Noun == "templates" {
autocompleteAPIArgs = append(autocompleteAPIArgs, "templatefilter=executable")
}
completeArgs := t.Config.Core.AutoComplete
autocompleteAPIArgs := []string{}
argOptions := []argOption{}
if completeArgs {
autocompleteAPIArgs = []string{"listall=true"}
if autocompleteAPI.Noun == "templates" {
autocompleteAPIArgs = append(autocompleteAPIArgs, "templatefilter=executable")
}

if apiFound.Name != "provisionCertificate" && autocompleteAPI.Name == "listHosts" {
autocompleteAPIArgs = append(autocompleteAPIArgs, "type=Routing")
}
if apiFound.Name != "provisionCertificate" && autocompleteAPI.Name == "listHosts" {
autocompleteAPIArgs = append(autocompleteAPIArgs, "type=Routing")
}

spinner := t.Config.StartSpinner("fetching options, please wait...")
request := cmd.NewRequest(nil, completer.Config, nil)
response, _ := cmd.NewAPIRequest(request, autocompleteAPI.Name, autocompleteAPIArgs, false)
t.Config.StopSpinner(spinner)
spinner := t.Config.StartSpinner("fetching options, please wait...")
request := cmd.NewRequest(nil, completer.Config, nil)
response, _ := cmd.NewAPIRequest(request, autocompleteAPI.Name, autocompleteAPIArgs, false)
t.Config.StopSpinner(spinner)

hasID := strings.HasSuffix(arg.Name, "id=") || strings.HasSuffix(arg.Name, "ids=")
argOptions := buildArgOptions(response, hasID)
hasID := strings.HasSuffix(arg.Name, "id=") || strings.HasSuffix(arg.Name, "ids=")
argOptions = buildArgOptions(response, hasID)
}

filteredOptions := []argOption{}
if len(argOptions) > 0 {
Expand Down
27 changes: 14 additions & 13 deletions cmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@ func init() {
Name: "set",
Help: "Configures options for cmk",
SubCommands: map[string][]string{
"prompt": {"🐵", "🐱", "random"},
"asyncblock": {"true", "false"},
"timeout": {"600", "1800", "3600"},
"output": config.GetOutputFormats(),
"profile": {},
"url": {},
"username": {},
"password": {},
"domain": {},
"apikey": {},
"secretkey": {},
"verifycert": {"true", "false"},
"debug": {"true", "false"},
"prompt": {"🐵", "🐱", "random"},
"asyncblock": {"true", "false"},
"timeout": {"600", "1800", "3600"},
"output": config.GetOutputFormats(),
"profile": {},
"url": {},
"username": {},
"password": {},
"domain": {},
"apikey": {},
"secretkey": {},
"verifycert": {"true", "false"},
"debug": {"true", "false"},
"autocomplete": {"true", "false"},
},
Handle: func(r *Request) error {
if len(r.Args) < 1 {
Expand Down
19 changes: 13 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ type ServerProfile struct {

// Core block describes common options for the CLI
type Core struct {
Prompt string `ini:"prompt"`
AsyncBlock bool `ini:"asyncblock"`
Timeout int `ini:"timeout"`
Output string `ini:"output"`
VerifyCert bool `ini:"verifycert"`
ProfileName string `ini:"profile"`
Prompt string `ini:"prompt"`
AsyncBlock bool `ini:"asyncblock"`
Timeout int `ini:"timeout"`
Output string `ini:"output"`
VerifyCert bool `ini:"verifycert"`
ProfileName string `ini:"profile"`
AutoComplete bool `ini:"autocomplete"`
}

// Config describes CLI config file and default options
Expand Down Expand Up @@ -140,6 +141,7 @@ func defaultCoreConfig() Core {
Output: JSON,
VerifyCert: true,
ProfileName: "localcloud",
AutoComplete: true,
}
}

Expand Down Expand Up @@ -250,6 +252,9 @@ func saveConfig(cfg *Config) *Config {
// Update
core := new(Core)
conf.Section(ini.DEFAULT_SECTION).MapTo(core)
if (!conf.Section(ini.DEFAULT_SECTION).HasKey("autocomplete")) {
core.AutoComplete = true
}
cfg.Core = core
}

Expand Down Expand Up @@ -339,6 +344,8 @@ func (c *Config) UpdateConfig(key string, value string, update bool) {
} else {
DisableDebugging()
}
case "autocomplete":
c.Core.AutoComplete = value == "true"
default:
fmt.Println("Invalid option provided:", key)
return
Expand Down