Skip to content

Commit

Permalink
feat: add shutdown pass-through command (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan authored Sep 19, 2022
1 parent c24adc5 commit 257c69e
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/aspect/root/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ go_library(
"//cmd/aspect/modquery",
"//cmd/aspect/query",
"//cmd/aspect/run",
"//cmd/aspect/shutdown",
"//cmd/aspect/sync",
"//cmd/aspect/test",
"//cmd/aspect/version",
Expand Down
3 changes: 2 additions & 1 deletion cmd/aspect/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"aspect.build/cli/cmd/aspect/modquery"
"aspect.build/cli/cmd/aspect/query"
"aspect.build/cli/cmd/aspect/run"
"aspect.build/cli/cmd/aspect/shutdown"
"aspect.build/cli/cmd/aspect/sync"
"aspect.build/cli/cmd/aspect/test"
"aspect.build/cli/cmd/aspect/version"
Expand Down Expand Up @@ -91,7 +92,7 @@ func NewRootCmd(
cmd.AddCommand(query.NewDefaultQueryCmd())
cmd.AddCommand(run.NewDefaultRunCmd(pluginSystem))
cmd.AddCommand(sync.NewDefaultSyncCmd())
// shutdown
cmd.AddCommand(shutdown.NewDefaultShutdownCmd())
cmd.AddCommand(test.NewDefaultTestCmd(pluginSystem))
cmd.AddCommand(version.NewDefaultVersionCmd())

Expand Down
15 changes: 15 additions & 0 deletions cmd/aspect/shutdown/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "shutdown",
srcs = ["shutdown.go"],
importpath = "aspect.build/cli/cmd/aspect/shutdown",
visibility = ["//visibility:public"],
deps = [
"//pkg/aspect/root/flags",
"//pkg/aspect/shutdown",
"//pkg/interceptors",
"//pkg/ioutils",
"@com_github_spf13_cobra//:cobra",
],
)
46 changes: 46 additions & 0 deletions cmd/aspect/shutdown/shutdown.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2022 Aspect Build Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package shutdown

import (
"github.com/spf13/cobra"

"aspect.build/cli/pkg/aspect/root/flags"
"aspect.build/cli/pkg/aspect/shutdown"
"aspect.build/cli/pkg/interceptors"
"aspect.build/cli/pkg/ioutils"
)

func NewDefaultShutdownCmd() *cobra.Command {
return NewShutdownCmd(ioutils.DefaultStreams)
}

func NewShutdownCmd(streams ioutils.Streams) *cobra.Command {
cmd := &cobra.Command{
Use: "shutdown",
Short: "Stops the bazel server.",
Long: "This command shuts down the memory resident bazel server process.",
RunE: interceptors.Run(
[]interceptors.Interceptor{
flags.FlagsInterceptor(streams),
},
shutdown.New(streams).Run,
),
}

return cmd
}
1 change: 1 addition & 0 deletions docs/aspect.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Aspect CLI is a better frontend for running bazel
* [aspect modquery](aspect_modquery.md) - Queries the Bzlmod external dependency graph.
* [aspect query](aspect_query.md) - Executes a dependency graph query.
* [aspect run](aspect_run.md) - Builds the specified target and runs it with the given arguments.
* [aspect shutdown](aspect_shutdown.md) - Stops the bazel server.
* [aspect sync](aspect_sync.md) - Syncs all repositories specified in the workspace file.
* [aspect test](aspect_test.md) - Builds the specified targets and runs all test targets among them.
* [aspect version](aspect_version.md) - Print the version of aspect CLI as well as tools it invokes.
Expand Down
29 changes: 29 additions & 0 deletions docs/aspect_shutdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## aspect shutdown

Stops the bazel server.

### Synopsis

This command shuts down the memory resident bazel server process.

```
aspect shutdown [flags]
```

### Options

```
-h, --help help for shutdown
```

### Options inherited from parent commands

```
--aspect:config string config file (default is $HOME/.aspect.yaml)
--aspect:interactive Interactive mode (e.g. prompts for user input)
```

### SEE ALSO

* [aspect](aspect.md) - Aspect.build bazel wrapper

1 change: 1 addition & 0 deletions docs/command_list.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ COMMAND_LIST = [
"modquery",
"query",
"run",
"shutdown",
"sync",
"test",
"version",
Expand Down
14 changes: 14 additions & 0 deletions pkg/aspect/shutdown/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 = "shutdown",
srcs = ["shutdown.go"],
importpath = "aspect.build/cli/pkg/aspect/shutdown",
visibility = ["//visibility:public"],
deps = [
"//pkg/aspecterrors",
"//pkg/bazel",
"//pkg/ioutils",
"@com_github_spf13_cobra//:cobra",
],
)
53 changes: 53 additions & 0 deletions pkg/aspect/shutdown/shutdown.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2022 Aspect Build Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package shutdown

import (
"context"

"github.com/spf13/cobra"

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

type Shutdown struct {
ioutils.Streams
}

func New(streams ioutils.Streams) *Shutdown {
return &Shutdown{
Streams: streams,
}
}

func (v *Shutdown) Run(ctx context.Context, _ *cobra.Command, args []string) error {
bazelCmd := []string{"shutdown"}
bazelCmd = append(bazelCmd, args...)
bzl := bazel.New()

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

return nil
}

0 comments on commit 257c69e

Please sign in to comment.