mirror of
https://github.com/hanzoai/base.git
synced 2026-10-21 03:41:50 +00:00
Adds collection/record/login/whoami/crons + daemon lifecycle + cluster (base-ha HA) + operator (K8s CRD) + config/status/self/rpc. Lux/cli network flags (--mainnet/--testnet/--devnet/--dev). All Base daemons (atsd-style binaries) get the full CLI for free via base.Start() or manual cmd.AddCommand(cmd.NewCLICommand()).
72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
package cli
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// NewCollectionCommand returns the `collection` subcommand tree.
|
|
func NewCollectionCommand(clientFn func() *Client, formatFn func() Format) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "collection",
|
|
Short: "Manage collections",
|
|
}
|
|
|
|
cmd.AddCommand(collectionListCmd(clientFn, formatFn))
|
|
cmd.AddCommand(collectionGetCmd(clientFn, formatFn))
|
|
cmd.AddCommand(collectionSchemaCmd(clientFn, formatFn))
|
|
|
|
return cmd
|
|
}
|
|
|
|
func collectionListCmd(clientFn func() *Client, formatFn func() Format) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "list",
|
|
Short: "List all collections",
|
|
SilenceUsage: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
data, _, err := clientFn().Get("/collections")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return Print(os.Stdout, formatFn(), data)
|
|
},
|
|
}
|
|
}
|
|
|
|
func collectionGetCmd(clientFn func() *Client, formatFn func() Format) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "get <name>",
|
|
Short: "Show a collection's schema",
|
|
Args: cobra.ExactArgs(1),
|
|
SilenceUsage: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
data, _, err := clientFn().Get("/collections/" + args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return Print(os.Stdout, formatFn(), data)
|
|
},
|
|
}
|
|
}
|
|
|
|
func collectionSchemaCmd(clientFn func() *Client, formatFn func() Format) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "schema <name>",
|
|
Short: "Export a collection's schema as JSON (pipe to file)",
|
|
Example: "base collection schema users > schema.json",
|
|
Args: cobra.ExactArgs(1),
|
|
SilenceUsage: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
data, _, err := clientFn().Get("/collections/" + args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// schema always outputs JSON regardless of --format
|
|
return Print(os.Stdout, FormatJSON, data)
|
|
},
|
|
}
|
|
}
|
|
|