diff --git a/cmd/uncloud/main.go b/cmd/uncloud/main.go index c1ee2ba5..dce2ad7a 100644 --- a/cmd/uncloud/main.go +++ b/cmd/uncloud/main.go @@ -36,11 +36,12 @@ func main() { } // TODO: allow to override using UNCLOUD_CONFIG env var. cmd.PersistentFlags().StringVar(&configPath, "uncloud-config", "~/.config/uncloud/config.toml", - "path to the Uncloud configuration file") + "path to the Uncloud configuration file.") _ = cmd.MarkPersistentFlagFilename("uncloud-config", "toml") cmd.AddCommand( machine.NewRootCommand(), + NewRunCommand(), ) cobra.CheckErr(cmd.Execute()) } diff --git a/cmd/uncloud/run.go b/cmd/uncloud/run.go new file mode 100644 index 00000000..3a0055bb --- /dev/null +++ b/cmd/uncloud/run.go @@ -0,0 +1,41 @@ +package main + +import ( + "fmt" + "github.com/spf13/cobra" + "uncloud/internal/cli" +) + +type runOptions struct { + name string + publish []string + cluster string +} + +func NewRunCommand() *cobra.Command { + opts := runOptions{} + cmd := &cobra.Command{ + Use: "run IMAGE", + Short: "Run a service in a cluster.", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + uncli := cmd.Context().Value("cli").(*cli.CLI) + + image := args[0] + + //return uncli.RunService(cmd.Context(), ...) + return fmt.Errorf("not implemented: run image %q %s", image, uncli) + }, + } + cmd.Flags().StringVarP(&opts.name, "name", "n", "", + "Assign a name to the service. A random name is generated if not specified.") + cmd.Flags().StringVarP( + &opts.cluster, "cluster", "c", "", + "Name of the cluster to run the service in. (default is the current cluster)", + ) + cmd.Flags().StringSliceVarP(&opts.publish, "publish", "p", nil, + "Publish a service port to make it accessible outside the cluster. Can be specified multiple times. "+ + "Format: [load_balancer_port:]container_port[/protocol]") + + return cmd +}