Update config generator

This commit is contained in:
Ryan McGuire 2023-12-29 09:22:19 -05:00
parent 5c2a9513a4
commit ea0157a997
3 changed files with 18 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package cmd package cmd
import ( import (
"bytes"
"fmt" "fmt"
"os" "os"
@ -47,9 +48,12 @@ func runConfigGenerateCmd(cmd *cobra.Command, args []string) {
plog.Args("file", configFile)) plog.Args("file", configFile))
} else { } else {
c, _ := yaml.Marshal(newConf) var c bytes.Buffer
enc := yaml.NewEncoder(&c)
enc.SetIndent(2)
enc.Encode(newConf)
plog.Info("Suggest running with --write or redirect (> " + configFile + ")") plog.Info("Suggest running with --write or redirect (> " + configFile + ")")
fmt.Print(string(c)) fmt.Print(c.String())
} }
} }
@ -96,6 +100,14 @@ func promptConfigSettings(c *config.Config) *config.Config {
Show(); err == nil { Show(); err == nil {
c.GitlabToken = token c.GitlabToken = token
} }
if dirMode, err := pterm.DefaultInteractiveConfirm.
WithDefaultValue(true).
WithDefaultText("Open project directories instead of main files (yes for vscode)?").
Show(); err == nil {
c.Editor.OpenDirectory = dirMode
}
return c return c
} }

View File

@ -111,7 +111,7 @@ func getEntrypointFile(projectPath string) string {
if err := os.Chdir(projectPath); err != nil { if err := os.Chdir(projectPath); err != nil {
return "" return ""
} else if conf.Editor.OpenDirectory { } else if conf.Editor.OpenDirectory {
return projectPath return "."
} }
// Search list of well-known main files // Search list of well-known main files

View File

@ -15,9 +15,9 @@ type Config struct {
} }
type editorConfig struct { type editorConfig struct {
DisplayName string `yaml:"displanName" json:"displanName"` DisplayName string `yaml:"displanName,omitempty" json:"displanName"`
Binary string `yaml:"binary" json:"binary"` Binary string `yaml:"binary,omitempty" json:"binary"`
OpenFlags string `yaml:"openFlags" json:"openFlags"` OpenFlags string `yaml:"openFlags,omitempty" json:"openFlags"`
OpenDirectory bool `yaml:"openDirectory" json:"openDirectory" description:"Don't open well-known files, open directory"` OpenDirectory bool `yaml:"openDirectory" json:"openDirectory" description:"Don't open well-known files, open directory"`
} }