grabrr/cmd/info.go

54 lines
1.1 KiB
Go
Raw Normal View History

2025-07-22 15:09:48 +03:00
package cmd
import (
2025-07-23 16:41:01 +03:00
"encoding/json"
2025-07-22 15:09:48 +03:00
"fmt"
2025-07-23 15:08:33 +03:00
"log"
bunkr "tea.chunkbyte.com/kato/grabrr/lib/bunkr"
2025-07-22 15:09:48 +03:00
"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) {
2025-07-23 15:08:33 +03:00
if err := runInfoCommand(); err != nil {
log.Fatalf("error: %v", err)
}
2025-07-22 15:09:48 +03:00
},
}
var (
2025-07-23 16:41:01 +03:00
albumURL string
prettyPrint bool
2025-07-22 15:09:48 +03:00
)
func init() {
rootCmd.AddCommand(infoCmd)
infoCmd.Flags().StringVarP(&albumURL, "url", "u", "", "Bunkrr album url (required)")
2025-07-23 16:41:01 +03:00
infoCmd.Flags().BoolVarP(&prettyPrint, "pretty", "p", false, "Whether or not to Pretty Print, otherwise export json")
2025-07-22 15:09:48 +03:00
infoCmd.MarkFlagRequired("url")
2025-07-23 15:08:33 +03:00
}
func runInfoCommand() error {
album, err := bunkr.FetchAlbumInfo(albumURL)
2025-07-23 16:41:01 +03:00
if prettyPrint {
fmt.Println(album.ToString())
} else {
jsonObject, err := json.Marshal(album)
if err != nil {
panic(err)
}
fmt.Printf("%s", jsonObject)
}
2025-07-22 15:09:48 +03:00
2025-07-23 15:08:33 +03:00
return err
2025-07-22 15:09:48 +03:00
}