package cmd import ( "encoding/json" "fmt" "log" bunkr "tea.chunkbyte.com/kato/grabrr/lib/bunkr" "github.com/spf13/cobra" ) // infoCmd represents the info command var infoCmd = &cobra.Command{ Use: "info", Short: "A simple info fetch of a bunkr album", Long: `The command is used to fetch information about a specific bunkrr album, it will reply with all the information it has about it.`, Run: func(cmd *cobra.Command, args []string) { if err := runInfoCommand(); err != nil { log.Fatalf("error: %v", err) } }, } var ( 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) if prettyPrint { fmt.Println(album.ToString()) } else { jsonObject, err := json.Marshal(album) if err != nil { panic(err) } fmt.Printf("%s", jsonObject) } return err }