feat: add the `--conf` command

Add the `--conf` command, which dipslay's the current `cheat`
configuration file path.
This commit is contained in:
Christopher Allen Lane 2022-08-07 14:08:25 -04:00
parent d598d96fce
commit ddbe710881
5 changed files with 26 additions and 0 deletions

11
cmd/cheat/cmd_conf.go Normal file
View File

@ -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)
}

View File

@ -15,6 +15,7 @@ Options:
-T --tags List all tags in use
-v --version Print the version number
--rm=<cheatsheet> Remove (delete) <cheatsheet>
--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

View File

@ -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

View File

@ -24,6 +24,7 @@ Options:
-T --tags List all tags in use
-v --version Print the version number
--rm=<cheatsheet> Remove (delete) <cheatsheet>
--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
`)
}

View File

@ -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 {