From 7ccdadc4766b6e619cdc99cbb45f84903ab24bd3 Mon Sep 17 00:00:00 2001 From: "Aalyria Technologies, Inc" Date: Wed, 4 Dec 2024 16:23:08 +0000 Subject: [PATCH] Import changes. - af14ffdc64c2dc1b91877c22466a897d90c0abdf GitOrigin-RevId: af14ffdc64c2dc1b91877c22466a897d90c0abdf --- agent/cmd/agent/agent.go | 2 +- agent/internal/agentcli/BUILD | 4 ++++ agent/internal/agentcli/agentcli.go | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/agent/cmd/agent/agent.go b/agent/cmd/agent/agent.go index c16267d..e7ea131 100644 --- a/agent/cmd/agent/agent.go +++ b/agent/cmd/agent/agent.go @@ -29,7 +29,7 @@ func main() { AppName: "agent", Handles: agentcli.DefaultHandles(), Providers: []agentcli.Provider{}, - }).Run(context.Background(), os.Args[0], os.Args[1:]); err != nil { + }).Run(context.Background(), os.Args[1:]); err != nil { fmt.Fprintf(os.Stderr, "fatal error: %v\n", err) os.Exit(2) } diff --git a/agent/internal/agentcli/BUILD b/agent/internal/agentcli/BUILD index c1cbb4e..0b250aa 100644 --- a/agent/internal/agentcli/BUILD +++ b/agent/internal/agentcli/BUILD @@ -13,6 +13,7 @@ # limitations under the License. load("@rules_go//go:def.bzl", "go_library") +load("//:version.bzl", "VERSION") package(default_visibility = ["//visibility:public"]) @@ -24,6 +25,9 @@ go_library( "netlink_other.go", ], importpath = "aalyria.com/spacetime/agent/internal/agentcli", + x_defs = { + "Version": VERSION, + }, deps = [ "//agent", "//agent/enactment", diff --git a/agent/internal/agentcli/agentcli.go b/agent/internal/agentcli/agentcli.go index fc5c111..482e1c9 100644 --- a/agent/internal/agentcli/agentcli.go +++ b/agent/internal/agentcli/agentcli.go @@ -64,6 +64,8 @@ import ( "aalyria.com/spacetime/auth" ) +var Version = "0.0.0+development" + // Handles are abstractions over impure, external resources like time and stdio // streams. type Handles interface { @@ -114,7 +116,7 @@ type AgentConf struct { Providers []Provider } -func (ac AgentConf) Run(ctx context.Context, appName string, args []string) (err error) { +func (ac AgentConf) Run(ctx context.Context, args []string) (err error) { var log zerolog.Logger if os.Getenv("TERM") != "" { log = zerolog.New(zerolog.ConsoleWriter{Out: ac.Handles.Stderr(), TimeFormat: "2006-01-02 03:04:05PM"}) @@ -123,15 +125,16 @@ func (ac AgentConf) Run(ctx context.Context, appName string, args []string) (err } ctx = log.With().Timestamp().Logger().WithContext(ctx) - fs := flag.NewFlagSet(appName, flag.ContinueOnError) + fs := flag.NewFlagSet(ac.AppName, flag.ContinueOnError) fs.SetOutput(ac.Handles.Stderr()) fs.Usage = func() { w := fs.Output() - fmt.Fprintf(w, "Usage: %s [options]\n", appName) + fmt.Fprintf(w, "Usage: %s [options]\n", ac.AppName) fmt.Fprint(w, "\nOptions:\n") fs.PrintDefaults() } + versionFlag := fs.Bool("version", false, "Print the version") confPath := fs.String("config", "", "The path to a protobuf representation of the agent's configuration (an AgentParams message).") protoFormat := fs.String("format", "text", "The format (one of text, wire, or json) to read the configuration as.") dryRunOnly := fs.Bool("dry-run", false, "Just validate the config, don't start the agent. Exits with a non-zero return code if the config is invalid.") @@ -144,6 +147,12 @@ func (ac AgentConf) Run(ctx context.Context, appName string, args []string) (err return err } + if *versionFlag { + w := fs.Output() + fmt.Fprintf(w, "%s version %s\n", ac.AppName, Version) + return nil + } + params, err := readParams(*confPath, *protoFormat) if err != nil { return err