Skip to content

Commit

Permalink
Import changes.
Browse files Browse the repository at this point in the history
  - af14ffdc64c2dc1b91877c22466a897d90c0abdf

GitOrigin-RevId: af14ffdc64c2dc1b91877c22466a897d90c0abdf
  • Loading branch information
Aalyria Technologies, Inc committed Dec 4, 2024
1 parent 9f140ac commit 7ccdadc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion agent/cmd/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions agent/internal/agentcli/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand All @@ -24,6 +25,9 @@ go_library(
"netlink_other.go",
],
importpath = "aalyria.com/spacetime/agent/internal/agentcli",
x_defs = {
"Version": VERSION,
},
deps = [
"//agent",
"//agent/enactment",
Expand Down
15 changes: 12 additions & 3 deletions agent/internal/agentcli/agentcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"})
Expand All @@ -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.")
Expand All @@ -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
Expand Down

0 comments on commit 7ccdadc

Please sign in to comment.