Skip to content

Commit

Permalink
chore: minor docs and cli fixes (#66)
Browse files Browse the repository at this point in the history
* docs: update invalid command

* chore: fix command description

* move dagger client config to sub commands

not all commands needs dagger client.

no need to make uncessary connections
  • Loading branch information
aweris authored Aug 8, 2023
1 parent 3004923 commit f9afc77
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The following command will install latest version of `gale` to your current dire
- `BIN_DIR` to specify the directory to install `gale` to, e.g. `BIN_DIR=/usr/local/bin` default is current directory

```bash!
curl https://raw.githubusercontent.com/aweris/gale/main/hack/install_gale.sh | sudo VERSION=v0.0.1 INSTALL_DIR=/usr/local/bin sh
curl -sfLo install.sh https://raw.githubusercontent.com/aweris/gale/main/hack/install.sh; sudo GALE_VERSION=v0.0.2 BIN_DIR=/usr/local/bin sh ./install.sh
```

**Note:** It's not possible install `gale` using `go install` because `gale` requires the version information to be
Expand Down
19 changes: 18 additions & 1 deletion cmd/gale/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package list
import (
"fmt"

"dagger.io/dagger"

"github.com/spf13/cobra"

"github.com/aweris/gale/internal/config"
"github.com/aweris/gale/internal/core"
)

Expand All @@ -18,8 +21,22 @@ func NewCommand() *cobra.Command {

cmd := &cobra.Command{
Use: "list",
Short: "List all workflows and jobs under the current repository",
Short: "List all workflows and jobs under it",
Args: cobra.NoArgs,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
client, err := dagger.Connect(cmd.Context(), dagger.WithLogOutput(cmd.OutOrStdout()))
if err != nil {
return err
}

config.SetClient(client)

return nil
},
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
// Close the client connection when the command is done.
return config.Client().Close()
},
RunE: func(cmd *cobra.Command, args []string) error {
repo, err := core.GetRepository(repo, getOpts)
if err != nil {
Expand Down
17 changes: 0 additions & 17 deletions cmd/gale/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,18 @@ import (
"fmt"
"os"

"dagger.io/dagger"

"github.com/spf13/cobra"

"github.com/aweris/gale/cmd/gale/list"
"github.com/aweris/gale/cmd/gale/run"
"github.com/aweris/gale/cmd/gale/version"
"github.com/aweris/gale/internal/config"
)

// NewCommand creates a new root command.
func NewCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "gale <command> [flags]",
Short: "Gale is a tool to run Github Actions locally",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
client, err := dagger.Connect(cmd.Context(), dagger.WithLogOutput(cmd.OutOrStdout()))
if err != nil {
return err
}

config.SetClient(client)

return nil
},
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
// Close the client connection when the command is done.
return config.Client().Close()
},
}

return cmd
Expand Down
19 changes: 18 additions & 1 deletion cmd/gale/run/run.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package run

import (
"github.com/aweris/gale/internal/dagger/images"
"dagger.io/dagger"

"github.com/spf13/cobra"

"github.com/aweris/gale/internal/config"
"github.com/aweris/gale/internal/dagger/images"
"github.com/aweris/gale/pkg/gale"
)

Expand All @@ -16,6 +19,20 @@ func NewCommand() *cobra.Command {
Short: "Run Github Actions by providing workflow and job name",
Args: cobra.ExactArgs(2),
SilenceUsage: true, // don't print usage when error occurs
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
client, err := dagger.Connect(cmd.Context(), dagger.WithLogOutput(cmd.OutOrStdout()))
if err != nil {
return err
}

config.SetClient(client)

return nil
},
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
// Close the client connection when the command is done.
return config.Client().Close()
},
RunE: func(cmd *cobra.Command, args []string) error {
_, err := images.
RunnerBase().
Expand Down

0 comments on commit f9afc77

Please sign in to comment.