diff --git a/src/cmd/info.go b/src/cmd/info.go new file mode 100644 index 0000000..476793b --- /dev/null +++ b/src/cmd/info.go @@ -0,0 +1,35 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "fmt" + "github.com/f1bonacc1/process-compose/src/config" + "github.com/spf13/cobra" +) + +// infoCmd represents the info command +var infoCmd = &cobra.Command{ + Use: "info", + Short: "Print configuration info", + Run: func(cmd *cobra.Command, args []string) { + printInfo() + }, +} + +func printInfo() { + format := "%-15s %s\n" + fmt.Println("Process Compose") + fmt.Printf(format, "Logs:", config.LogFilePath) + + path := config.GetShortCutsPath() + if len(path) > 0 { + fmt.Printf(format, "Shortcuts:", config.GetShortCutsPath()) + } + +} + +func init() { + rootCmd.AddCommand(infoCmd) +} diff --git a/src/config/config.go b/src/config/config.go index cf52d5c..b2bcf09 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -15,6 +15,11 @@ var ( Date = "undefined" CheckForUpdates = "false" License = "Apache-2.0" + + scFiles = []string{ + "shortcuts.yaml", + "shortcuts.yml", + } ) const ( @@ -25,19 +30,27 @@ const ( var LogFilePath = filepath.Join(os.TempDir(), fmt.Sprintf("process-compose-%s.log", mustUser())) -func ProcCompHome() string { +func procCompHome() string { if env := os.Getenv(pcConfigEnv); env != "" { return env } - xdgPcHome, err := xdg.ConfigFile("process-compose") if err != nil { log.Fatal().Err(err).Msg("Unable to create configuration directory for process compose") } - return xdgPcHome } +func GetShortCutsPath() string { + for _, path := range scFiles { + scPath := filepath.Join(procCompHome(), path) + if _, err := os.Stat(scPath); err == nil { + return scPath + } + } + return "" +} + func mustUser() string { usr, err := user.Current() if err != nil { diff --git a/src/tui/view.go b/src/tui/view.go index fba494d..7bfc4e9 100644 --- a/src/tui/view.go +++ b/src/tui/view.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/f1bonacc1/process-compose/src/config" "github.com/f1bonacc1/process-compose/src/updater" - "path/filepath" "time" "github.com/f1bonacc1/process-compose/src/app" @@ -26,10 +25,6 @@ const ( ) var pcv *pcView = nil -var scFiles = []string{ - "shortcuts.yaml", - "shortcuts.yml", -} type pcView struct { procTable *tview.Table @@ -86,10 +81,9 @@ func newPcView(logLength int) *pcView { } func (pv *pcView) loadShortcuts() { - for _, path := range scFiles { - if err := pv.shortcuts.loadFromFile(filepath.Join(config.ProcCompHome(), path)); err == nil { - break - } + path := config.GetShortCutsPath() + if len(path) > 0 { + pv.shortcuts.loadFromFile(path) } }