From bd8a4ff911421789c9c1d937b117aba1253cb619 Mon Sep 17 00:00:00 2001 From: xzyaoi Date: Mon, 17 Sep 2018 00:42:06 +0800 Subject: [PATCH] add config handler --- cli/handler.go | 15 +++++++++++++++ cli/main.go | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/cli/handler.go b/cli/handler.go index 0c278c5d4..5b271e53f 100644 --- a/cli/handler.go +++ b/cli/handler.go @@ -4,9 +4,11 @@ import ( "github.com/fatih/color" "github.com/olekukonko/tablewriter" "github.com/urfave/cli" + "github.com/mitchellh/go-homedir" "os" "strconv" "strings" + "path/filepath" ) func InstallHandler(c *cli.Context) { @@ -81,3 +83,16 @@ func RepoHandler(c *cli.Context) { color.Red("Command Not Supported!") } } + +func ConfigHandler(c* cli.Context) { + configFilePath := filepath.Join(homedir.Dir(), "cvpm", "config.toml") + if _, err := os.Stat(configFilePath); os.IsNotExist(err) { + file, err := os.Create(configFilePath) + if err != nil { + color.Red("An error occured!") + } + defer file.Close() + } + +} + diff --git a/cli/main.go b/cli/main.go index 1151225ee..7e440c049 100644 --- a/cli/main.go +++ b/cli/main.go @@ -65,6 +65,13 @@ func main() { return nil }, }, + { + Name: "config", + Action: func(c *cli.Context) error { + ConfigHandler(c) + return nil + }, + }, } err := cvpm.Run(os.Args) if err != nil {