Skip to content

Commit

Permalink
Merge pull request #1694 from afumagalli98/show-config-toml
Browse files Browse the repository at this point in the history
Added toml flag to show-config cmd
  • Loading branch information
afumagalli98 authored Nov 27, 2023
2 parents dfd2020 + b3f9712 commit bf360b3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd/show_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,29 @@ import (
"fmt"
"os"

"github.com/pelletier/go-toml"
"github.com/spf13/cobra"
)

var tomlFlag bool

// showConfigCmd represents the showConfig command
var showConfigCmd = &cobra.Command{
Use: "show-config",
Short: "Show the configuration",
Long: `Show all ercole configuration`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {

if tomlFlag {
enc := toml.NewEncoder(os.Stdout)
if err := enc.Encode(ercoleConfig); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}

os.Exit(0)
}

enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
if err := enc.Encode(ercoleConfig); err != nil {
Expand All @@ -40,4 +54,6 @@ var showConfigCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(showConfigCmd)

showConfigCmd.Flags().BoolVarP(&tomlFlag, "toml", "t", false, "Print the configuration as toml")
}

0 comments on commit bf360b3

Please sign in to comment.