Files
ssh-hub/util/util.go
Denys Seredenko 121c2505e6
All checks were successful
Build and Test / build-test (1.23.4) (push) Successful in 1m37s
* showing help by basic call
* autocompletion for exec
2025-02-18 19:34:15 +01:00

33 lines
618 B
Go

package util
import (
"encoding/json"
"github.com/spf13/cobra"
"os"
"strings"
)
func SaveConfig(data *map[string]string) error {
jsonData, err := json.Marshal(data)
cobra.CheckErr(err)
homeDir, err := os.UserHomeDir()
cobra.CheckErr(err)
f, err := os.Create(homeDir + "/.ssh-hub-config.json")
cobra.CheckErr(err)
_, err = f.Write(jsonData)
cobra.CheckErr(err)
return nil
}
func AutocompleteConfig(conf *map[string]string, partialInput string) []string {
var result []string
for key := range *conf {
if strings.Contains(key, partialInput) {
result = append(result, key)
}
}
return result
}