use yaml config file

This commit is contained in:
André Roth
2024-12-02 20:56:17 +01:00
parent a880a88fc0
commit 0e0189f0eb
4 changed files with 479 additions and 90 deletions

View File

@@ -5,19 +5,30 @@ import (
"fmt"
"github.com/smira/commander"
"gopkg.in/yaml.v3"
)
func aptlyConfigShow(_ *commander.Command, _ []string) error {
show_yaml := context.Flags().Lookup("yaml").Value.Get().(bool)
config := context.Config()
prettyJSON, err := json.MarshalIndent(config, "", " ")
if err != nil {
return fmt.Errorf("unable to dump the config file: %s", err)
if show_yaml {
yamlData, err := yaml.Marshal(&config)
if err != nil {
return fmt.Errorf("error marshaling to YAML: %s", err)
}
fmt.Println(string(yamlData))
} else {
prettyJSON, err := json.MarshalIndent(config, "", " ")
if err != nil {
return fmt.Errorf("unable to dump the config file: %s", err)
}
fmt.Println(string(prettyJSON))
}
fmt.Println(string(prettyJSON))
return nil
}
@@ -35,5 +46,6 @@ Example:
`,
}
cmd.Flag.Bool("yaml", false, "show yaml config")
return cmd
}