-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updating documentation * Cleaning up gdg-template ChangeLog: - Refactoring GDG template tool - Refactoring GDG CLI tool * Additional documentation prepping for the v0.6.0 release.
- Loading branch information
1 parent
0e945da
commit 09e5db5
Showing
32 changed files
with
629 additions
and
384 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,31 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"github.com/esnet/gdg/internal/config" | ||
"github.com/spf13/cobra" | ||
"gopkg.in/yaml.v3" | ||
"log" | ||
"log/slog" | ||
) | ||
|
||
var showConfigCmd = &cobra.Command{ | ||
Use: "config", | ||
Short: "Show current templates configuration", | ||
Long: `Show current templates configuration`, | ||
Aliases: []string{"cfg"}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
data, err := yaml.Marshal(config.Config().GetTemplateConfig()) | ||
if err != nil { | ||
log.Fatalf("unable to load template configuration: %v", err) | ||
} | ||
slog.Info("Configuration", | ||
slog.String("template-config", tplCfgFile), | ||
slog.String("gdg-config", cfgFile)) | ||
fmt.Println(string(data)) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(showConfigCmd) | ||
} |
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,60 @@ | ||
package cli | ||
|
||
import ( | ||
assets "github.com/esnet/gdg/config" | ||
"github.com/esnet/gdg/internal/config" | ||
appconfig "github.com/esnet/gdg/internal/log" | ||
"github.com/esnet/gdg/internal/templating" | ||
"github.com/spf13/cobra" | ||
"log" | ||
"log/slog" | ||
"os" | ||
) | ||
|
||
var ( | ||
cfgFile string | ||
tplCfgFile string | ||
template templating.Templating | ||
rootCmd = &cobra.Command{ | ||
Use: "gdg-generate", | ||
Short: "Generates dashboard templates for use with GDG given a valid configuration", | ||
Long: `Generates dashboard templates for use with GDG given a valid configuration`, | ||
} | ||
) | ||
|
||
func init() { | ||
cobra.OnInitialize(initConfig) | ||
rootCmd.CompletionOptions.DisableDefaultCmd = true | ||
|
||
rootCmd.PersistentFlags().StringP("config", "c", "", "config file (default: config/importer.yml)") | ||
rootCmd.PersistentFlags().StringP("template-config", "", "", "GDG Template configuration file override. (default: config/templates.yml)") | ||
} | ||
|
||
func initConfig() { | ||
var err error | ||
cfgFile, err = rootCmd.Flags().GetString("config") | ||
if err != nil { | ||
log.Fatal("unable to get config file") | ||
} | ||
tplCfgFile, err = rootCmd.Flags().GetString("template-config") | ||
if err != nil { | ||
log.Fatal("unable to get template config file") | ||
} | ||
|
||
defaultConfiguration, err := assets.GetFile("importer-example.yml") | ||
if err != nil { | ||
slog.Warn("unable to load default configuration, no fallback") | ||
} | ||
|
||
config.InitGdgConfig(cfgFile, defaultConfiguration) | ||
config.InitTemplateConfig(tplCfgFile) | ||
cfg := config.Config() | ||
appconfig.InitializeAppLogger(os.Stdout, os.Stderr, cfg.IsDebug()) | ||
template = templating.NewTemplate() | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
} |
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,70 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"github.com/jedib0t/go-pretty/v6/table" | ||
"github.com/spf13/cobra" | ||
"log" | ||
"log/slog" | ||
"os" | ||
) | ||
|
||
var tplCmd = &cobra.Command{ | ||
Use: "template", | ||
Aliases: []string{"tpl", "templates"}, | ||
Short: "Templating Utilities", | ||
Long: `Templating Utilities`, | ||
} | ||
|
||
var listTemplatesCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List current templates", | ||
Long: `List current templates`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
templates := template.ListTemplates() | ||
slog.Info("Available templates for current configuration", | ||
slog.String("template-config", tplCfgFile), | ||
slog.String("gdg-config", cfgFile)) | ||
for ndx, t := range templates { | ||
slog.Info(fmt.Sprintf("%d: %s", ndx+1, t)) | ||
} | ||
}, | ||
} | ||
|
||
var generateTemplatesCmd = &cobra.Command{ | ||
Use: "generate", | ||
Aliases: []string{}, | ||
Short: "Generate current templates", | ||
Long: `Generate current templates`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
templateFilter, _ := cmd.Flags().GetString("template") | ||
payload, err := template.Generate(templateFilter) | ||
if err != nil { | ||
log.Fatal("Failed to generate templates", slog.Any("err", err)) | ||
} | ||
|
||
tableObj := table.NewWriter() | ||
tableObj.SetOutputMirror(os.Stdout) | ||
tableObj.SetStyle(table.StyleLight) | ||
|
||
tableObj.AppendHeader(table.Row{"Template Name", "Output"}) | ||
count := 0 | ||
for key, val := range payload { | ||
count += len(val) | ||
for _, file := range val { | ||
tableObj.AppendRow(table.Row{key, file}) | ||
} | ||
} | ||
slog.Info("Generate dashboards for the given templates", | ||
slog.Any("template-count", len(payload)), | ||
slog.Any("dashboard-count", count)) | ||
tableObj.Render() | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(tplCmd) | ||
tplCmd.AddCommand(listTemplatesCmd) | ||
tplCmd.AddCommand(generateTemplatesCmd) | ||
generateTemplatesCmd.PersistentFlags().StringP("template", "t", "", "Specify template name, optional. Default is to operate on all configured templates that are found.") | ||
} |
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,19 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/esnet/gdg/internal/version" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version number of gdg-generate", | ||
Long: `Print the version number of gdg-generate`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
version.PrintVersionInfo() | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
} |
Oops, something went wrong.