add images details

This commit is contained in:
Celogeek 2021-12-16 11:49:16 +01:00
parent 6c37970be2
commit 5b53dae3c4
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
5 changed files with 51 additions and 6 deletions

View File

@ -0,0 +1,11 @@
package piwigocli
type ImagesGroup struct {
Details ImagesDetailsCommand `command:"details" description:"Details of the images"`
}
var imagesGroup ImagesGroup
func init() {
parser.AddCommand("images", "Image management", "", &imagesGroup)
}

View File

@ -0,0 +1,34 @@
package piwigocli
import (
"net/url"
"github.com/celogeek/piwigo-cli/internal/piwigo"
)
type ImagesDetailsCommand struct {
Id string `short:"i" long:"id" description:"ID of the images" required:"true"`
}
type GetImagesDetailsResponse struct {
}
func (c *ImagesDetailsCommand) Execute(args []string) error {
p := piwigo.Piwigo{}
if err := p.LoadConfig(); err != nil {
return err
}
_, err := p.Login()
if err != nil {
return err
}
var resp GetImagesDetailsResponse
if err := p.Post("pwg.images.getInfo", &url.Values{
"image_id": []string{c.Id},
}, &resp); err != nil {
return err
}
return nil
}

View File

@ -1,8 +1,8 @@
package piwigocli package piwigocli
type SessionGroup struct { type SessionGroup struct {
Login LoginCommand `command:"login" description:"Initialize a connection to a piwigo instance"` Login SessionLoginCommand `command:"login" description:"Initialize a connection to a piwigo instance"`
Status StatusCommand `command:"status" description:"Get the status of your session"` Status SessionStatusCommand `command:"status" description:"Get the status of your session"`
} }
var sessionGroup SessionGroup var sessionGroup SessionGroup

View File

@ -6,13 +6,13 @@ import (
"github.com/celogeek/piwigo-cli/internal/piwigo" "github.com/celogeek/piwigo-cli/internal/piwigo"
) )
type LoginCommand struct { type SessionLoginCommand struct {
Url string `short:"u" long:"url" description:"Url of the instance" required:"true"` Url string `short:"u" long:"url" description:"Url of the instance" required:"true"`
Login string `short:"l" long:"login" description:"Login" required:"true"` Login string `short:"l" long:"login" description:"Login" required:"true"`
Password string `short:"p" long:"password" description:"Password" required:"true"` Password string `short:"p" long:"password" description:"Password" required:"true"`
} }
func (c *LoginCommand) Execute(args []string) error { func (c *SessionLoginCommand) Execute(args []string) error {
fmt.Printf("Login on %s...\n", c.Url) fmt.Printf("Login on %s...\n", c.Url)
p := piwigo.Piwigo{ p := piwigo.Piwigo{

View File

@ -7,10 +7,10 @@ import (
"github.com/jedib0t/go-pretty/v6/table" "github.com/jedib0t/go-pretty/v6/table"
) )
type StatusCommand struct { type SessionStatusCommand struct {
} }
func (c *StatusCommand) Execute(args []string) error { func (c *SessionStatusCommand) Execute(args []string) error {
p := piwigo.Piwigo{} p := piwigo.Piwigo{}
if err := p.LoadConfig(); err != nil { if err := p.LoadConfig(); err != nil {
return err return err