✨ Syntactic sugar in drop command for outputting json
This commit is contained in:
		
					parent
					
						
							
								80e07dbd14
							
						
					
				
			
			
				commit
				
					
						02a7babb36
					
				
			
		
					 1 changed files with 7 additions and 0 deletions
				
			
		|  | @ -21,6 +21,7 @@ import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
|  | 	"codeberg.org/danjones000/my-log/config" | ||||||
| 	"codeberg.org/danjones000/my-log/files" | 	"codeberg.org/danjones000/my-log/files" | ||||||
| 	"codeberg.org/danjones000/my-log/formatters" | 	"codeberg.org/danjones000/my-log/formatters" | ||||||
| 	"codeberg.org/danjones000/my-log/models" | 	"codeberg.org/danjones000/my-log/models" | ||||||
|  | @ -31,6 +32,7 @@ import ( | ||||||
| var d Date | var d Date | ||||||
| var fields map[string]string | var fields map[string]string | ||||||
| var j Json | var j Json | ||||||
|  | var outJson bool | ||||||
| 
 | 
 | ||||||
| // dropCmd represents the drop command | // dropCmd represents the drop command | ||||||
| var dropCmd = &cobra.Command{ | var dropCmd = &cobra.Command{ | ||||||
|  | @ -40,6 +42,10 @@ var dropCmd = &cobra.Command{ | ||||||
| 	Args:         cobra.ExactArgs(2), | 	Args:         cobra.ExactArgs(2), | ||||||
| 	SilenceUsage: true, | 	SilenceUsage: true, | ||||||
| 	RunE: func(cmd *cobra.Command, args []string) error { | 	RunE: func(cmd *cobra.Command, args []string) error { | ||||||
|  | 		if outJson { | ||||||
|  | 			config.Overrides["output.stdout.config.format"] = "json" | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		log := args[0] | 		log := args[0] | ||||||
| 		title := args[1] | 		title := args[1] | ||||||
| 		ms := &models.Metas{} | 		ms := &models.Metas{} | ||||||
|  | @ -83,6 +89,7 @@ func init() { | ||||||
| 	dropCmd.Flags().VarP(&d, "date", "d", "Date for log entry") | 	dropCmd.Flags().VarP(&d, "date", "d", "Date for log entry") | ||||||
| 	dropCmd.Flags().StringToStringVarP(&fields, "fields", "f", nil, "Fields you add to 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().VarP(&j, "json", "j", "Entire entry as json") | ||||||
|  | 	dropCmd.Flags().BoolVarP(&outJson, "output_json", "o", false, "Output result as JSON") | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Json struct { | type Json struct { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue