mirror of
https://github.com/holos-run/holos.git
synced 2026-03-20 09:15:02 +00:00
This patch changes the behavior of all commands to execute in the current working directory of the platform root cue module. This gets cue vet working well, otherwise it complains about fully qualified paths. The cue command line expects the current working directory to be a cue module. The Env field of the Command schema wasn't implemented, so we remove it from the schema. It's unclear it's necessary. Setting the environment in the parent context should suffice for current use cases.
35 lines
769 B
Go
35 lines
769 B
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
"os"
|
|
|
|
"github.com/holos-run/holos/internal/cli"
|
|
"github.com/holos-run/holos/internal/holos"
|
|
"github.com/holos-run/holos/version"
|
|
)
|
|
|
|
// MakeMain makes a main function for the cli or tests.
|
|
func MakeMain(options ...holos.Option) func() int {
|
|
return func() (exitCode int) {
|
|
// TODO(jjm): check HOLOS_CHDIR and chdir if set for tests.
|
|
if len(os.Args) >= 2 && os.Args[1] == "version" {
|
|
if _, err := fmt.Println(version.GetVersion()); err != nil {
|
|
panic(err)
|
|
}
|
|
return 0
|
|
}
|
|
cfg := holos.New(options...)
|
|
slog.SetDefault(cfg.Logger())
|
|
ctx := context.Background()
|
|
cmd := cli.New(cfg)
|
|
|
|
if err := cmd.ExecuteContext(ctx); err != nil {
|
|
return cli.HandleError(ctx, err, cfg)
|
|
}
|
|
return 0
|
|
}
|
|
}
|