summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatthieu <matthieu.cneude@gmail.com>2021-04-23 14:43:07 +0200
committermatthieu <matthieu.cneude@gmail.com>2021-04-23 14:43:07 +0200
commit5313a42aaad97db48901b22b92a1aeaf1469f271 (patch)
tree0c65d2cf6f02244cee394c6dd5578c4436cc5e2c
parent4dd55332eddeb5938455f7e3dbc88807f071bdad (diff)
Improve generate command
-rw-r--r--cmd/generate.go18
-rw-r--r--internal/platform/termui.go2
2 files changed, 16 insertions, 4 deletions
diff --git a/cmd/generate.go b/cmd/generate.go
index 4f06cf8..c2928c0 100644
--- a/cmd/generate.go
+++ b/cmd/generate.go
@@ -10,18 +10,19 @@ import (
"github.com/spf13/cobra"
)
-var configType string
+var configType, templateFile string
func generateCmd() *cobra.Command {
generateCmd := &cobra.Command{
Use: "generate",
- Short: "Generate default dashboard",
+ Short: "Generate dashboard templates",
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintln(os.Stdout, generate(args))
},
}
generateCmd.Flags().StringVarP(&configType, "type", "t", "", "Debug Mode - doesn't display graph")
+ generateCmd.Flags().StringVarP(&templateFile, "file", "f", "", "Save the template into a file ($XDG_CONFIG_HOME/<name_of_file>")
return generateCmd
}
@@ -37,7 +38,7 @@ func generate(args []string) string {
}
func createBlogDefaultConfig() string {
- wizardIntro("blogs")
+ wizardIntro("a blog")
keyfile := askKeyfile()
address := askSiteAddress()
viewID := askViewID()
@@ -50,7 +51,16 @@ func createBlogDefaultConfig() string {
b := bytes.NewBuffer([]byte{})
err = ut.Execute(b, internal.CreateBlogConfig(keyfile, address, viewID))
- return b.String()
+ if templateFile != "" {
+ cfg := createTemplateFile(templateFile, b.String())
+ return fmt.Sprintf("The file %s has been created.", cfg)
+ } else {
+ return b.String()
+ }
+}
+
+func createTemplateFile(filename string, template string) string {
+ return createConfig(dashPath(), filename+".yml", template)
}
func wizardIntro(name string) {
diff --git a/internal/platform/termui.go b/internal/platform/termui.go
index af01ef3..f8796f8 100644
--- a/internal/platform/termui.go
+++ b/internal/platform/termui.go
@@ -236,6 +236,8 @@ func (t *termUI) KEdit(key string, c chan<- time.Time, config string, editor str
if err != nil {
fmt.Println(err)
}
+
+ // Hot reload when command complete
c <- time.Now()
})
}