From ddbe71088164d7ef74957a29f25844d06a685a94 Mon Sep 17 00:00:00 2001 From: Christopher Allen Lane Date: Sun, 7 Aug 2022 14:08:25 -0400 Subject: [PATCH] feat: add the `--conf` command Add the `--conf` command, which dipslay's the current `cheat` configuration file path. --- cmd/cheat/cmd_conf.go | 11 +++++++++++ cmd/cheat/docopt.txt | 4 ++++ cmd/cheat/main.go | 3 +++ cmd/cheat/str_usage.go | 4 ++++ internal/config/config.go | 4 ++++ 5 files changed, 26 insertions(+) create mode 100644 cmd/cheat/cmd_conf.go diff --git a/cmd/cheat/cmd_conf.go b/cmd/cheat/cmd_conf.go new file mode 100644 index 0000000..65c1694 --- /dev/null +++ b/cmd/cheat/cmd_conf.go @@ -0,0 +1,11 @@ +package main + +import ( + "fmt" + + "github.com/cheat/cheat/internal/config" +) + +func cmdConf(opts map[string]interface{}, conf config.Config) { + fmt.Println(conf.Path) +} diff --git a/cmd/cheat/docopt.txt b/cmd/cheat/docopt.txt index e12615e..dd2b112 100644 --- a/cmd/cheat/docopt.txt +++ b/cmd/cheat/docopt.txt @@ -15,6 +15,7 @@ Options: -T --tags List all tags in use -v --version Print the version number --rm= Remove (delete) + --conf Display the config file path Examples: @@ -53,3 +54,6 @@ Examples: To remove (delete) the foo/bar cheatsheet: cheat --rm foo/bar + + To view the configuration file path: + cheat --conf diff --git a/cmd/cheat/main.go b/cmd/cheat/main.go index c40e138..8c6fdf6 100755 --- a/cmd/cheat/main.go +++ b/cmd/cheat/main.go @@ -120,6 +120,9 @@ func main() { var cmd func(map[string]interface{}, config.Config) switch { + case opts["--conf"].(bool): + cmd = cmdConf + case opts["--directories"].(bool): cmd = cmdDirectories diff --git a/cmd/cheat/str_usage.go b/cmd/cheat/str_usage.go index 0d69c57..b4c5eb8 100644 --- a/cmd/cheat/str_usage.go +++ b/cmd/cheat/str_usage.go @@ -24,6 +24,7 @@ Options: -T --tags List all tags in use -v --version Print the version number --rm= Remove (delete) + --conf Display the config file path Examples: @@ -62,5 +63,8 @@ Examples: To remove (delete) the foo/bar cheatsheet: cheat --rm foo/bar + + To view the configuration file path: + cheat --conf `) } diff --git a/internal/config/config.go b/internal/config/config.go index 7a51fa4..b0f4be9 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -20,6 +20,7 @@ type Config struct { Style string `yaml:"style"` Formatter string `yaml:"formatter"` Pager string `yaml:"pager"` + Path string } // New returns a new Config struct @@ -34,6 +35,9 @@ func New(opts map[string]interface{}, confPath string, resolve bool) (Config, er // initialize a config object conf := Config{} + // store the config path + conf.Path = confPath + // unmarshal the yaml err = yaml.UnmarshalStrict(buf, &conf) if err != nil {