init ucind CLI commands

This commit is contained in:
Pavel Sviderski
2024-11-28 13:54:37 +10:00
parent 73785007cb
commit 7aa7a9fea1
4 changed files with 122 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
package cluster
import (
"fmt"
"github.com/spf13/cobra"
"uncloud/internal/ucind"
)
type createOptions struct {
}
func NewCreateCommand() *cobra.Command {
//opts := createOptions{}
cmd := &cobra.Command{
Use: "create [NAME]",
Short: "Create a new cluster.",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
p := cmd.Context().Value("provisioner").(*ucind.Provisioner)
name := DefaultClusterName
if len(args) > 0 {
name = args[0]
}
if err := p.CreateCluster(cmd.Context(), name, ucind.CreateClusterOptions{}); err != nil {
return fmt.Errorf("create cluster '%s': %w", name, err)
}
fmt.Printf("Cluster '%s' created.\n", name)
return nil
},
}
return cmd
}
+30
View File
@@ -0,0 +1,30 @@
package cluster
import (
"fmt"
"github.com/spf13/cobra"
"uncloud/internal/ucind"
)
func NewRemoveCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "rm [NAME]",
Short: "Remove a cluster.",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
p := cmd.Context().Value("provisioner").(*ucind.Provisioner)
name := DefaultClusterName
if len(args) > 0 {
name = args[0]
}
if err := p.RemoveCluster(cmd.Context(), name); err != nil {
return fmt.Errorf("remove cluster '%s': %w", name, err)
}
fmt.Printf("Cluster '%s' removed.\n", name)
return nil
},
}
return cmd
}
+20
View File
@@ -0,0 +1,20 @@
package cluster
import (
"github.com/spf13/cobra"
)
const DefaultClusterName = "ucind-default"
func NewRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "cluster",
Short: "Manage local Docker-based clusters.",
}
cmd.AddCommand(
NewCreateCommand(),
//NewListCommand(),
NewRemoveCommand(),
)
return cmd
}