From 02a7babb36c23935006041d2f8753ea99246013b Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Mon, 7 Oct 2024 14:15:28 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Syntactic=20sugar=20in=20drop=20com?= =?UTF-8?q?mand=20for=20outputting=20json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/drop.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/drop.go b/cmd/drop.go index d74917e..2c246e6 100644 --- a/cmd/drop.go +++ b/cmd/drop.go @@ -21,6 +21,7 @@ import ( "fmt" "time" + "codeberg.org/danjones000/my-log/config" "codeberg.org/danjones000/my-log/files" "codeberg.org/danjones000/my-log/formatters" "codeberg.org/danjones000/my-log/models" @@ -31,6 +32,7 @@ import ( var d Date var fields map[string]string var j Json +var outJson bool // dropCmd represents the drop command var dropCmd = &cobra.Command{ @@ -40,6 +42,10 @@ var dropCmd = &cobra.Command{ Args: cobra.ExactArgs(2), SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { + if outJson { + config.Overrides["output.stdout.config.format"] = "json" + } + log := args[0] title := args[1] ms := &models.Metas{} @@ -83,6 +89,7 @@ func init() { dropCmd.Flags().VarP(&d, "date", "d", "Date for log entry") dropCmd.Flags().StringToStringVarP(&fields, "fields", "f", nil, "Fields you add to entry") dropCmd.Flags().VarP(&j, "json", "j", "Entire entry as json") + dropCmd.Flags().BoolVarP(&outJson, "output_json", "o", false, "Output result as JSON") } type Json struct {