Skip to content

Commit

Permalink
chore: Lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tazarov committed Mar 3, 2024
1 parent 71e10ef commit 98f3a35
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
10 changes: 4 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,23 +37,22 @@ func initConfig() {
if err != nil {
fmt.Println(err)
os.Exit(1)

}
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(home + "/.chroma")
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
log.Fatal(err)
}
_, err = os.Create(home + "/.chroma" + "/config.yaml")
if err != nil {
//Unable to create file
// Unable to create file
log.Fatal(err)
}
err = viper.WriteConfig()
Expand All @@ -62,6 +61,5 @@ func initConfig() {
os.Exit(1)
}
}

}
}
31 changes: 10 additions & 21 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -68,32 +69,20 @@ 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
// }
//}

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 <alias> -h localhost -p 8080
var Host string
var Port string
var Overwrite bool
Expand All @@ -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)
Expand All @@ -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().
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/server_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package server

import (
"github.com/stretchr/testify/require"
"testing"

"github.com/stretchr/testify/require"
)

func TestValidateHost(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion types/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package types

//connect to local Chroma
// connect to local Chroma

type ServerConfig struct {
Host string
Expand Down

0 comments on commit 98f3a35

Please sign in to comment.