diff --git a/cmd/info.go b/cmd/info.go index d123e7e..1d16568 100644 --- a/cmd/info.go +++ b/cmd/info.go @@ -1,6 +1,7 @@ package cmd import ( + "encoding/json" "fmt" "log" @@ -22,20 +23,31 @@ var infoCmd = &cobra.Command{ } var ( - albumURL string + albumURL string + prettyPrint bool ) func init() { rootCmd.AddCommand(infoCmd) infoCmd.Flags().StringVarP(&albumURL, "url", "u", "", "Bunkrr album url (required)") + infoCmd.Flags().BoolVarP(&prettyPrint, "pretty", "p", false, "Whether or not to Pretty Print, otherwise export json") infoCmd.MarkFlagRequired("url") } func runInfoCommand() error { album, err := bunkr.FetchAlbumInfo(albumURL) - fmt.Println(album.ToString()) + if prettyPrint { + fmt.Println(album.ToString()) + } else { + jsonObject, err := json.Marshal(album) + if err != nil { + panic(err) + } + + fmt.Printf("%s", jsonObject) + } return err }