Info command update

This commit is contained in:
2025-07-23 17:55:12 +03:00
parent 06db684c43
commit b8d6934025
3 changed files with 65 additions and 24 deletions

View File

@@ -5,9 +5,8 @@ import (
"fmt"
"log"
bunkr "tea.chunkbyte.com/kato/grabrr/lib/bunkr"
"github.com/spf13/cobra"
bunkr "tea.chunkbyte.com/kato/grabrr/lib/bunkr"
)
// infoCmd represents the info command
@@ -25,29 +24,42 @@ var infoCmd = &cobra.Command{
var (
albumURL string
prettyPrint bool
prettyJson 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.Flags().BoolVarP(&prettyJson, "json", "j", true, "Whether or not to pretty print the JSON output")
infoCmd.MarkFlagRequired("url")
}
func runInfoCommand() error {
album, err := bunkr.FetchAlbumInfo(albumURL)
if err != nil {
return err
}
if prettyPrint {
fmt.Println(album.ToString())
} else {
jsonObject, err := json.Marshal(album)
if err != nil {
panic(err)
if prettyJson {
prettyJSON, err := json.MarshalIndent(album, "", " ")
if err != nil {
return err
}
fmt.Printf("%s", prettyJSON)
} else {
jsonObject, err := json.Marshal(album)
if err != nil {
return err
} else {
fmt.Printf("%s", jsonObject)
}
}
fmt.Printf("%s", jsonObject)
}
return err
return nil
}