feat: add info command
diff --git a/cmd/aspect/info/BUILD.bazel b/cmd/aspect/info/BUILD.bazel new file mode 100644 index 0000000..809d488 --- /dev/null +++ b/cmd/aspect/info/BUILD.bazel
@@ -0,0 +1,13 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "info", + srcs = ["info.go"], + importpath = "aspect.build/cli/cmd/aspect/info", + visibility = ["//visibility:public"], + deps = [ + "//pkg/aspect/info", + "//pkg/ioutils", + "@com_github_spf13_cobra//:cobra", + ], +)
diff --git a/cmd/aspect/info/info.go b/cmd/aspect/info/info.go new file mode 100644 index 0000000..24102ee --- /dev/null +++ b/cmd/aspect/info/info.go
@@ -0,0 +1,51 @@ +/* +Copyright © 2021 Aspect Build Systems + +Not licensed for re-use +*/ + +package info + +import ( + "github.com/spf13/cobra" + + "aspect.build/cli/pkg/aspect/info" + "aspect.build/cli/pkg/ioutils" +) + +func NewDefaultInfoCmd() *cobra.Command { + return NewInfoCmd(ioutils.DefaultStreams) +} + +func NewInfoCmd(streams ioutils.Streams) *cobra.Command { + v := info.New(streams) + + cmd := &cobra.Command{ + Use: "info", + Short: "Displays runtime info about the bazel server", + Long: `Displays information about the state of the bazel process in the +form of several "key: value" pairs. This includes the locations of +several output directories. Because some of the +values are affected by the options passed to 'bazel build', the +info command accepts the same set of options. + +A single non-option argument may be specified (e.g. "bazel-bin"), in +which case only the value for that key will be printed. + +If --show_make_env is specified, the output includes the set of key/value +pairs in the "Make" environment, accessible within BUILD files. + +The full list of keys and the meaning of their values is documented in +the bazel User Manual, and can be programmatically obtained with +'bazel help info-keys'. + +See also 'bazel version' for more detailed bazel version +information.`, + Args: cobra.MaximumNArgs(1), + RunE: v.Run, + } + + cmd.PersistentFlags().BoolVarP(&v.ShowMakeEnv, "show_make_env", "", false, `include the set of key/value pairs in the "Make" environment, +accessible within BUILD files`) + return cmd +}
diff --git a/cmd/aspect/root/BUILD.bazel b/cmd/aspect/root/BUILD.bazel index faa1504..b7c3b24 100644 --- a/cmd/aspect/root/BUILD.bazel +++ b/cmd/aspect/root/BUILD.bazel
@@ -11,6 +11,7 @@ deps = [ "//cmd/aspect/build", "//cmd/aspect/docs", + "//cmd/aspect/info", "//cmd/aspect/version", "//docs/help/topics", "//pkg/ioutils",
diff --git a/cmd/aspect/root/root.go b/cmd/aspect/root/root.go index 2345184..5b3213e 100644 --- a/cmd/aspect/root/root.go +++ b/cmd/aspect/root/root.go
@@ -17,6 +17,7 @@ "aspect.build/cli/cmd/aspect/build" "aspect.build/cli/cmd/aspect/docs" + "aspect.build/cli/cmd/aspect/info" "aspect.build/cli/cmd/aspect/version" "aspect.build/cli/docs/help/topics" "aspect.build/cli/pkg/ioutils" @@ -70,6 +71,7 @@ cmd.AddCommand(build.NewDefaultBuildCmd()) cmd.AddCommand(version.NewDefaultVersionCmd()) cmd.AddCommand(docs.NewDefaultDocsCmd()) + cmd.AddCommand(info.NewDefaultInfoCmd()) // ### "Additional help topic commands" which are not runnable // https://pkg.go.dev/github.com/spf13/cobra#Command.IsAdditionalHelpTopicCommand
diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index 4fd027d..3abc99d 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel
@@ -6,6 +6,7 @@ "aspect.md", "aspect_build.md", "aspect_docs.md", + "aspect_info.md", "aspect_version.md", ]
diff --git a/docs/aspect.md b/docs/aspect.md index 24c1aa8..69358f2 100644 --- a/docs/aspect.md +++ b/docs/aspect.md
@@ -18,6 +18,7 @@ * [aspect build](aspect_build.md) - Builds the specified targets, using the options. * [aspect docs](aspect_docs.md) - Open documentation in the browser +* [aspect info](aspect_info.md) - Displays runtime info about the bazel server * [aspect version](aspect_version.md) - Print the version of aspect CLI as well as tools it invokes ###### Auto generated by spf13/cobra
diff --git a/docs/aspect_info.md b/docs/aspect_info.md new file mode 100644 index 0000000..5f32620 --- /dev/null +++ b/docs/aspect_info.md
@@ -0,0 +1,49 @@ +## aspect info + +Displays runtime info about the bazel server + +### Synopsis + +Displays information about the state of the bazel process in the +form of several "key: value" pairs. This includes the locations of +several output directories. Because some of the +values are affected by the options passed to 'bazel build', the +info command accepts the same set of options. + +A single non-option argument may be specified (e.g. "bazel-bin"), in +which case only the value for that key will be printed. + +If --show_make_env is specified, the output includes the set of key/value +pairs in the "Make" environment, accessible within BUILD files. + +The full list of keys and the meaning of their values is documented in +the bazel User Manual, and can be programmatically obtained with +'bazel help info-keys'. + +See also 'bazel version' for more detailed bazel version +information. + +``` +aspect info [flags] +``` + +### Options + +``` + -h, --help help for info + --show_make_env include the set of key/value pairs in the "Make" environment, + accessible within BUILD files +``` + +### Options inherited from parent commands + +``` + --config string config file (default is $HOME/.aspect.yaml) + --interactive Interactive mode (e.g. prompts for user input) +``` + +### SEE ALSO + +* [aspect](aspect.md) - Aspect.build bazel wrapper + +###### Auto generated by spf13/cobra
diff --git a/pkg/aspect/info/BUILD.bazel b/pkg/aspect/info/BUILD.bazel new file mode 100644 index 0000000..81e0b64 --- /dev/null +++ b/pkg/aspect/info/BUILD.bazel
@@ -0,0 +1,13 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "info", + srcs = ["info.go"], + importpath = "aspect.build/cli/pkg/aspect/info", + visibility = ["//visibility:public"], + deps = [ + "//pkg/bazel", + "//pkg/ioutils", + "@com_github_spf13_cobra//:cobra", + ], +)
diff --git a/pkg/aspect/info/info.go b/pkg/aspect/info/info.go new file mode 100644 index 0000000..5132eb3 --- /dev/null +++ b/pkg/aspect/info/info.go
@@ -0,0 +1,38 @@ +/* +Copyright © 2021 Aspect Build Systems Inc + +Not licensed for re-use. +*/ + +package info + +import ( + "aspect.build/cli/pkg/bazel" + "aspect.build/cli/pkg/ioutils" + "github.com/spf13/cobra" +) + +type Info struct { + ioutils.Streams + + ShowMakeEnv bool +} + +func New(streams ioutils.Streams) *Info { + return &Info{ + Streams: streams, + } +} + +func (v *Info) Run(_ *cobra.Command, args []string) error { + bazelCmd := []string{"info"} + if v.ShowMakeEnv { + // Propagate the flag + bazelCmd = append(bazelCmd, "--show_make_env") + } + bazelCmd = append(bazelCmd, args...) + bzl := bazel.New() + bzl.Spawn(bazelCmd) + + return nil +}