Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add info command #29

Merged
merged 2 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmd/aspect/info/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
51 changes: 51 additions & 0 deletions cmd/aspect/info/info.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions cmd/aspect/root/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
deps = [
"//cmd/aspect/build",
"//cmd/aspect/docs",
"//cmd/aspect/info",
"//cmd/aspect/version",
"//docs/help/topics",
"//pkg/ioutils",
Expand Down
2 changes: 2 additions & 0 deletions cmd/aspect/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"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"
Expand Down Expand Up @@ -70,6 +71,7 @@ func NewRootCmd(streams ioutils.Streams, defaultInteractive bool) *cobra.Command
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
Expand Down
1 change: 1 addition & 0 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ _DOCS = [
"aspect.md",
"aspect_build.md",
"aspect_docs.md",
"aspect_info.md",
"aspect_version.md",
]

Expand Down
1 change: 1 addition & 0 deletions docs/aspect.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Aspect CLI is a better frontend for running bazel

* [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
49 changes: 49 additions & 0 deletions docs/aspect_info.md
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions pkg/aspect/info/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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/aspecterrors",
"//pkg/bazel",
"//pkg/ioutils",
"@com_github_spf13_cobra//:cobra",
],
)
47 changes: 47 additions & 0 deletions pkg/aspect/info/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
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"

"aspect.build/cli/pkg/aspecterrors"
)

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()

if exitCode, err := bzl.Spawn(bazelCmd); exitCode != 0 {
err = &aspecterrors.ExitError{
Err: err,
ExitCode: exitCode,
}
return err
}

return nil
}