use yaml config file

This commit is contained in:
André Roth committed 2024-12-11 12:02:52 +01:00
1 parent a880a88fc0
commit 0e0189f0eb
4 files changed
+479 -90

No files matched your search

+17 -5
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
}