mirror of
https://github.com/jimeh/mje.git
synced 2026-02-19 01:46:40 +00:00
feat(commands/midjourney/collections): add list and get commands
This commit is contained in:
29
commands/midjourney/collections.go
Normal file
29
commands/midjourney/collections.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package midjourney
|
||||
|
||||
import (
|
||||
"github.com/jimeh/go-midjourney"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewCollections(mc *midjourney.Client) (*cobra.Command, error) {
|
||||
cmd := &cobra.Command{
|
||||
Use: "collections",
|
||||
Aliases: []string{"collection", "col"},
|
||||
Short: "Query collections",
|
||||
}
|
||||
|
||||
listCmd, err := NewCollectionsList(mc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
getCmd, err := NewCollectionsGet(mc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cmd.AddCommand(
|
||||
listCmd,
|
||||
getCmd,
|
||||
)
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
37
commands/midjourney/collections_get.go
Normal file
37
commands/midjourney/collections_get.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package midjourney
|
||||
|
||||
import (
|
||||
"github.com/jimeh/go-midjourney"
|
||||
"github.com/jimeh/mje/commands/render"
|
||||
"github.com/jimeh/mje/commands/shared"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewCollectionsGet(mc *midjourney.Client) (*cobra.Command, error) {
|
||||
cmd := &cobra.Command{
|
||||
Use: "get collection_id",
|
||||
Short: "Get a collection",
|
||||
RunE: collectionsGetRunE(mc),
|
||||
ArgAliases: []string{"collection_id"},
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func collectionsGetRunE(mc *midjourney.Client) shared.RunEFunc {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
q := &midjourney.CollectionsQuery{
|
||||
CollectionID: args[0],
|
||||
}
|
||||
|
||||
cols, err := mc.Collections(cmd.Context(), q)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
format := shared.FlagString(cmd, "format")
|
||||
|
||||
return render.Render(cmd.OutOrStdout(), format, cols)
|
||||
}
|
||||
}
|
||||
46
commands/midjourney/collections_list.go
Normal file
46
commands/midjourney/collections_list.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package midjourney
|
||||
|
||||
import (
|
||||
"github.com/jimeh/go-midjourney"
|
||||
"github.com/jimeh/mje/commands/render"
|
||||
"github.com/jimeh/mje/commands/shared"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewCollectionsList(mc *midjourney.Client) (*cobra.Command, error) {
|
||||
cmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Aliases: []string{"ls"},
|
||||
Short: "List collections",
|
||||
RunE: collectionsListRunE(mc),
|
||||
}
|
||||
|
||||
cmd.Flags().StringP("user-id", "u", "", "user ID to list jobs for")
|
||||
cmd.Flags().StringP(
|
||||
"collection-id", "c", "", "collection ID to list jobs for",
|
||||
)
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func collectionsListRunE(mc *midjourney.Client) shared.RunEFunc {
|
||||
return func(cmd *cobra.Command, _ []string) error {
|
||||
fs := cmd.Flags()
|
||||
q := &midjourney.CollectionsQuery{}
|
||||
|
||||
if v, err := fs.GetString("user-id"); err == nil && v != "" {
|
||||
q.UserID = v
|
||||
}
|
||||
if v, err := fs.GetString("collection-id"); err == nil && v != "" {
|
||||
q.CollectionID = v
|
||||
}
|
||||
cols, err := mc.Collections(cmd.Context(), q)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
format := shared.FlagString(cmd, "format")
|
||||
|
||||
return render.Render(cmd.OutOrStdout(), format, cols)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user