mirror of
https://github.com/holos-run/holos.git
synced 2026-03-22 02:05:00 +00:00
When the user generates a platform, we need to know the platform ID it's
linked to in the holos server. If there is no platform with the same
name, the `holos generate platform` command should error out.
This is necessary because the first thing we want to show is pushing an
updated form to `holos server`. To update the web ui the CLI needs to
know the platform ID to update.
This patch modifies the generate command to obtain a list of platforms
for the org and verify the generated name matches one of the platforms
that already exists.
A future patch could have the `generate platform` command call the
`holos.platform.v1alpha1.PlatformService.CreatePlatform` method if the
platform isn't found.
Results:
```sh
holos generate platform bare
```
```txt
4:15PM INF generate.go:77 wrote platform.metadata.json version=0.77.1 platform_id=018f826d-85a8-751f-96d0-0d2bf70df909 path=/home/jeff/holos/platform.metadata.json
4:15PM INF generate.go:89 generated platform bare version=0.77.1 platform_id=018f826d-85a8-751f-96d0-0d2bf70df909 path=/home/jeff/holos
```
```sh
cat platform.metadata.json
```
```json
{
"id": "018f826d-85a8-751f-96d0-0d2bf70df909",
"name": "bare",
"display_name": "Bare Platform"
}
```
90 lines
2.7 KiB
Go
90 lines
2.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"log/slog"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/holos-run/holos/version"
|
|
|
|
"github.com/holos-run/holos/internal/holos"
|
|
"github.com/holos-run/holos/internal/logger"
|
|
"github.com/holos-run/holos/internal/server"
|
|
|
|
"github.com/holos-run/holos/internal/cli/build"
|
|
"github.com/holos-run/holos/internal/cli/controller"
|
|
"github.com/holos-run/holos/internal/cli/create"
|
|
"github.com/holos-run/holos/internal/cli/generate"
|
|
"github.com/holos-run/holos/internal/cli/get"
|
|
"github.com/holos-run/holos/internal/cli/kv"
|
|
"github.com/holos-run/holos/internal/cli/login"
|
|
"github.com/holos-run/holos/internal/cli/logout"
|
|
"github.com/holos-run/holos/internal/cli/preflight"
|
|
"github.com/holos-run/holos/internal/cli/push"
|
|
"github.com/holos-run/holos/internal/cli/register"
|
|
"github.com/holos-run/holos/internal/cli/render"
|
|
"github.com/holos-run/holos/internal/cli/rpc"
|
|
"github.com/holos-run/holos/internal/cli/token"
|
|
"github.com/holos-run/holos/internal/cli/txtar"
|
|
)
|
|
|
|
// New returns a new root *cobra.Command for command line execution.
|
|
func New(cfg *holos.Config) *cobra.Command {
|
|
rootCmd := &cobra.Command{
|
|
Use: "holos",
|
|
Short: "holos manages a holistic integrated software development platform",
|
|
Version: version.Version,
|
|
Args: cobra.NoArgs,
|
|
CompletionOptions: cobra.CompletionOptions{
|
|
HiddenDefaultCmd: true, // Don't complete the complete subcommand itself
|
|
},
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
PersistentPreRunE: func(c *cobra.Command, args []string) error {
|
|
if err := cfg.Finalize(); err != nil {
|
|
return err
|
|
}
|
|
log := cfg.Logger()
|
|
c.Root().SetContext(logger.NewContext(c.Context(), log))
|
|
// Set the default logger after flag parsing.
|
|
slog.SetDefault(log)
|
|
return nil
|
|
},
|
|
RunE: func(c *cobra.Command, args []string) error {
|
|
return c.Usage()
|
|
},
|
|
}
|
|
rootCmd.SetVersionTemplate("{{.Version}}\n")
|
|
rootCmd.SetOut(cfg.Stdout())
|
|
rootCmd.PersistentFlags().SortFlags = false
|
|
rootCmd.PersistentFlags().AddGoFlagSet(cfg.LogFlagSet())
|
|
|
|
// subcommands
|
|
rootCmd.AddCommand(build.New(cfg))
|
|
rootCmd.AddCommand(render.New(cfg))
|
|
rootCmd.AddCommand(get.New(cfg))
|
|
rootCmd.AddCommand(create.New(cfg))
|
|
rootCmd.AddCommand(preflight.New(cfg))
|
|
rootCmd.AddCommand(login.New(cfg))
|
|
rootCmd.AddCommand(logout.New(cfg))
|
|
rootCmd.AddCommand(token.New(cfg))
|
|
rootCmd.AddCommand(rpc.New(cfg))
|
|
rootCmd.AddCommand(generate.New(cfg))
|
|
rootCmd.AddCommand(register.New(cfg))
|
|
rootCmd.AddCommand(push.New(cfg))
|
|
|
|
// Maybe not needed?
|
|
rootCmd.AddCommand(txtar.New(cfg))
|
|
|
|
// Deprecated, remove?
|
|
rootCmd.AddCommand(kv.New(cfg))
|
|
|
|
// Server
|
|
rootCmd.AddCommand(server.New(cfg))
|
|
|
|
// Controller
|
|
rootCmd.AddCommand(controller.New(cfg))
|
|
|
|
return rootCmd
|
|
}
|