Skip to content

Commit

Permalink
feat: add homedir support for config giles
Browse files Browse the repository at this point in the history
  • Loading branch information
krzko committed May 28, 2023
1 parent b902128 commit 1d62202
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.20

require (
github.com/fatih/color v1.15.0
github.com/mitchellh/go-homedir v1.1.0
github.com/olekukonko/tablewriter v0.0.5
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/urfave/cli/v2 v2.25.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPn
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
Expand Down
3 changes: 2 additions & 1 deletion internal/cli/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func genCleanCommand() *cli.Command {
os.Exit(1)
}

targetDir := "run_o11y_run_files"
homeDir := getHomeDir()
targetDir := filepath.Join(homeDir, ".run-o11y-run")
err := files.ExtractFiles(targetDir)
if err != nil {
fmt.Println("Error extracting files:", err)
Expand Down
11 changes: 11 additions & 0 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/fatih/color"
"github.com/mitchellh/go-homedir"
"github.com/urfave/cli/v2"
"golang.org/x/exp/slices"
)
Expand Down Expand Up @@ -73,6 +74,16 @@ func checkDockerAvailability() bool {
return err == nil
}

// getHomeDir returns the user's home directory
func getHomeDir() string {
home, err := homedir.Dir()
if err != nil {
fmt.Println("Failed to get home directory:", err)
os.Exit(1)
}
return home
}

// removeDirectory removes a directory and all its contents
func removeDirectory(dir string) error {
return os.RemoveAll(dir)
Expand Down
3 changes: 2 additions & 1 deletion internal/cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func genStartCommand() *cli.Command {
os.Exit(1)
}

targetDir := "run_o11y_run_files"
homeDir := getHomeDir()
targetDir := filepath.Join(homeDir, ".run-o11y-run")
err := files.ExtractFiles(targetDir)
if err != nil {
fmt.Println("Error extracting files:", err)
Expand Down
3 changes: 2 additions & 1 deletion internal/cli/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func genStopCommand() *cli.Command {
os.Exit(1)
}

targetDir := "run_o11y_run_files"
homeDir := getHomeDir()
targetDir := filepath.Join(homeDir, ".run-o11y-run")
err := files.ExtractFiles(targetDir)
if err != nil {
fmt.Println("Error extracting files:", err)
Expand Down

0 comments on commit 1d62202

Please sign in to comment.