Skip to content

Commit

Permalink
Print configuration info
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Jan 5, 2023
1 parent 82b43e8 commit e052de6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
35 changes: 35 additions & 0 deletions src/cmd/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
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)
}
19 changes: 16 additions & 3 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ var (
Date = "undefined"
CheckForUpdates = "false"
License = "Apache-2.0"

scFiles = []string{
"shortcuts.yaml",
"shortcuts.yml",
}
)

const (
Expand All @@ -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 {
Expand Down
12 changes: 3 additions & 9 deletions src/tui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -26,10 +25,6 @@ const (
)

var pcv *pcView = nil
var scFiles = []string{
"shortcuts.yaml",
"shortcuts.yml",
}

type pcView struct {
procTable *tview.Table
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit e052de6

Please sign in to comment.