Info command update
This commit is contained in:
30
cmd/info.go
30
cmd/info.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user