-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cd497e
commit 718dcd5
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/afero" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var ConfigCmd = &cli.Command{ | ||
Name: "config", | ||
Subcommands: []*cli.Command{ | ||
configPathCmd, | ||
configShowCmd, | ||
}, | ||
} | ||
|
||
var configPathCmd = &cli.Command{ | ||
Name: "path", | ||
Action: func(_ *cli.Context) error { | ||
fs := afero.NewOsFs() | ||
|
||
userHomeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return fmt.Errorf("cannot user home dir: %v", err) | ||
} | ||
|
||
configPathFromEnv := os.Getenv(EnvVarName) | ||
xdgHomePathFromEnv := os.Getenv(XdgEnvVarName) | ||
|
||
confPath, err := LocateConfFile(fs, userHomeDir, configPathFromEnv, xdgHomePathFromEnv) | ||
if err != nil { | ||
return fmt.Errorf("could not locate config file: %w", err) | ||
} | ||
|
||
fmt.Println(confPath) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
var configShowCmd = &cli.Command{ | ||
Name: "show", | ||
Action: func(_ *cli.Context) error { | ||
fs := afero.NewOsFs() | ||
|
||
userHomeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return fmt.Errorf("cannot user home dir: %v", err) | ||
} | ||
|
||
configPathFromEnv := os.Getenv(EnvVarName) | ||
xdgHomePathFromEnv := os.Getenv(XdgEnvVarName) | ||
|
||
confPath, err := LocateConfFile(fs, userHomeDir, configPathFromEnv, xdgHomePathFromEnv) | ||
if err != nil { | ||
return fmt.Errorf("could not locate config file: %w", err) | ||
} | ||
|
||
conf, err := Load(confPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
confJson, err := json.MarshalIndent(conf, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println(string(confJson)) | ||
|
||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters