From 98f3a358f671fd9090836f4d87eddb88dbafdedf Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Sun, 3 Mar 2024 22:46:42 +0200 Subject: [PATCH] chore: Lint fix --- cmd/root.go | 10 ++++------ cmd/server/server.go | 31 ++++++++++--------------------- cmd/server/server_test.go | 3 ++- types/server.go | 2 +- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 25cf5b3..63764d7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,12 +3,12 @@ package cmd import ( "errors" "fmt" - "github.com/mitchellh/go-homedir" - "github.com/spf13/viper" "log" "os" + "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" + "github.com/spf13/viper" ) // rootCmd represents the base command when called without any subcommands @@ -37,7 +37,6 @@ func initConfig() { if err != nil { fmt.Println(err) os.Exit(1) - } viper.SetConfigName("config") viper.SetConfigType("yaml") @@ -45,7 +44,7 @@ func initConfig() { if err := viper.ReadInConfig(); err != nil { var configFileNotFoundError viper.ConfigFileNotFoundError if errors.As(err, &configFileNotFoundError) { - //create config file + // create config file err := os.MkdirAll(home+"/.chroma", 0700) if err != nil { // Unable to create directory @@ -53,7 +52,7 @@ func initConfig() { } _, err = os.Create(home + "/.chroma" + "/config.yaml") if err != nil { - //Unable to create file + // Unable to create file log.Fatal(err) } err = viper.WriteConfig() @@ -62,6 +61,5 @@ func initConfig() { os.Exit(1) } } - } } diff --git a/cmd/server/server.go b/cmd/server/server.go index 951851a..ac4ff5d 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -2,12 +2,13 @@ package server import ( "fmt" + "os" + "strconv" + "github.com/charmbracelet/huh" "github.com/go-playground/validator/v10" "github.com/spf13/cobra" "github.com/spf13/viper" - "os" - "strconv" ) const ( @@ -38,7 +39,7 @@ func getPort(changed bool) (int, error) { port = DefaultPort } var actualPort int - //if port == "" { + // if port == "" { // iPort := huh.NewInput().Value(&port).Title("Port").Placeholder(DefaultPort) // err := iPort.Run() // if err != nil { @@ -68,13 +69,13 @@ func getHost(changed bool) (string, error) { return "", fmt.Errorf("invalid host: %v", err) } - //if host == "" { + // if host == "" { // iHost := huh.NewInput().Value(&host).Title("Host").Placeholder(DefaultHost) // err := iHost.Run() // if err != nil { // return "", fmt.Errorf("unable to get host: %v", err) // } - //if host == "" { + // if host == "" { // host = DefaultHost // } //} @@ -82,18 +83,6 @@ func getHost(changed bool) (string, error) { return host, nil } -// getSecure is used for Interactive shell mode -func getSecure(changed bool) (bool, error) { - secure := Secure - - //err := huh.NewConfirm().Title("Use secure connection (https)?").Affirmative("Yes!").Negative("No.").Value - //if err != nil { - // return false, fmt.Errorf("unable to get confirmation: %v", err) - //} - return secure, nil -} - -// chroma server add -h localhost -p 8080 var Host string var Port string var Overwrite bool @@ -104,7 +93,7 @@ var AddCommand = &cobra.Command{ Short: "Add new or Update existing Chroma server", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - //get the first argument tht is our alias + // get the first argument tht is our alias alias := args[0] hostChanged := cmd.Flags().Changed("host") host, hostErr := getHost(hostChanged) @@ -128,8 +117,8 @@ var AddCommand = &cobra.Command{ if !portChanged { fmt.Printf("Using default port: %v\n", DefaultPort) } - //confirm := false - //if Host != "" || Port != "" { + // confirm := false + // if Host != "" || Port != "" { // confirm = true //} else { // err := huh.NewConfirm(). @@ -230,7 +219,7 @@ func init() { AddCommand.Flags().StringVarP(&Port, "port", "p", "", "Chroma server port") AddCommand.Flags().BoolVarP(&Overwrite, "overwrite", "o", false, "Overwrite existing server with the same alias") AddCommand.Flags().BoolVarP(&Secure, "secure", "s", false, "Use secure connection (https).") - //AddCommand.MarkFlagsRequiredTogether("host", "port") + // AddCommand.MarkFlagsRequiredTogether("host", "port") AddCommand.ValidArgs = []string{"alias"} RmCommand.ValidArgs = []string{"alias"} RmCommand.Flags().BoolVarP(&ForceDelete, "force", "f", false, "Force remove server without confirmation") diff --git a/cmd/server/server_test.go b/cmd/server/server_test.go index 75e51bf..4aecffa 100644 --- a/cmd/server/server_test.go +++ b/cmd/server/server_test.go @@ -1,8 +1,9 @@ package server import ( - "github.com/stretchr/testify/require" "testing" + + "github.com/stretchr/testify/require" ) func TestValidateHost(t *testing.T) { diff --git a/types/server.go b/types/server.go index e1b580b..c8fb0bb 100644 --- a/types/server.go +++ b/types/server.go @@ -1,6 +1,6 @@ package types -//connect to local Chroma +// connect to local Chroma type ServerConfig struct { Host string