From ba312f81a5d8d37bdd59006363ba50b2108edee4 Mon Sep 17 00:00:00 2001 From: Suzuki Shunsuke Date: Wed, 25 Aug 2021 22:31:32 +0900 Subject: [PATCH] fix: rename cube to aqua --- cube.yaml => aqua.yaml | 3 +++ pkg/cli/exec.go | 22 ++++++++++++++++++++++ pkg/cli/runner.go | 32 ++++++++++++++++++-------------- pkg/controller/exec.go | 9 +++++++-- pkg/controller/install.go | 5 ++++- 5 files changed, 54 insertions(+), 17 deletions(-) rename cube.yaml => aqua.yaml (85%) create mode 100644 pkg/cli/exec.go diff --git a/cube.yaml b/aqua.yaml similarity index 85% rename from cube.yaml rename to aqua.yaml index 5fa953b9c..4589b1bc8 100644 --- a/cube.yaml +++ b/aqua.yaml @@ -7,3 +7,6 @@ inline_repository: type: github_release repo: suzuki-shunsuke/akoi artifact: 'akoi_{{trimPrefix "v" .Package.Version}}_{{.OS}}_{{.Arch}}.tar.gz' + files: + - name: akoi + src: akoi diff --git a/pkg/cli/exec.go b/pkg/cli/exec.go new file mode 100644 index 000000000..2e8e6fc62 --- /dev/null +++ b/pkg/cli/exec.go @@ -0,0 +1,22 @@ +package cli + +import ( + "fmt" + + "github.com/suzuki-shunsuke/aqua/pkg/controller" + "github.com/urfave/cli/v2" +) + +func (runner *Runner) execAction(c *cli.Context) error { + param := &controller.Param{} + if err := runner.setCLIArg(c, param); err != nil { + return fmt.Errorf("parse the command line arguments: %w", err) + } + + ctrl, err := controller.New(c.Context, param) + if err != nil { + return fmt.Errorf("initialize a controller: %w", err) + } + + return ctrl.Exec(c.Context, param, c.Args().Slice()) //nolint:wrapcheck +} diff --git a/pkg/cli/runner.go b/pkg/cli/runner.go index 02918403a..9674369f5 100644 --- a/pkg/cli/runner.go +++ b/pkg/cli/runner.go @@ -2,12 +2,9 @@ package cli import ( "context" - "fmt" "io" - "path/filepath" "github.com/suzuki-shunsuke/aqua/pkg/constant" - "github.com/suzuki-shunsuke/aqua/pkg/controller" "github.com/urfave/cli/v2" ) @@ -18,17 +15,6 @@ type Runner struct { } func (runner *Runner) Run(ctx context.Context, args ...string) error { - if len(args) != 0 { - exeName := filepath.Base(args[0]) - if exeName != "aqua" { - param := &controller.Param{} - ctrl, err := controller.New(ctx, param) - if err != nil { - return fmt.Errorf("initialize a controller: %w", err) - } - return ctrl.Exec(ctx, param, exeName, args[1:]) //nolint:wrapcheck - } - } app := cli.App{ Name: "aqua", Usage: "General version manager. https://github.com/suzuki-shunsuke/aqua", @@ -52,6 +38,24 @@ func (runner *Runner) Run(ctx context.Context, args ...string) error { }, }, }, + { + Name: "exec", + Usage: "Execute tool", + Action: runner.execAction, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "log-level", + Usage: "log level", + EnvVars: []string{"CUBE_LOG_LEVEL"}, + }, + &cli.StringFlag{ + Name: "config", + Aliases: []string{"c"}, + Usage: "configuration file path", + EnvVars: []string{"CUBE_CONFIG"}, + }, + }, + }, }, } diff --git a/pkg/controller/exec.go b/pkg/controller/exec.go index eef705cec..5ba41c363 100644 --- a/pkg/controller/exec.go +++ b/pkg/controller/exec.go @@ -2,6 +2,7 @@ package controller import ( "context" + "errors" "fmt" "os" "os/exec" @@ -11,7 +12,11 @@ import ( "github.com/suzuki-shunsuke/go-timeout/timeout" ) -func (ctrl *Controller) Exec(ctx context.Context, param *Param, exeName string, args []string) error { +func (ctrl *Controller) Exec(ctx context.Context, param *Param, args []string) error { + if len(args) == 0 { + return errors.New("command is required") + } + exeName := args[0] cfg := Config{} wd, err := os.Getwd() if err != nil { @@ -38,7 +43,7 @@ func (ctrl *Controller) Exec(ctx context.Context, param *Param, exeName string, return fmt.Errorf("repository isn't found %s", pkg.Name) } - return ctrl.exec(ctx, exeName, pkg, pkgInfo, args) + return ctrl.exec(ctx, exeName, pkg, pkgInfo, args[1:]) } return nil } diff --git a/pkg/controller/install.go b/pkg/controller/install.go index d6b1a265b..cf1dc39e0 100644 --- a/pkg/controller/install.go +++ b/pkg/controller/install.go @@ -73,7 +73,10 @@ func (ctrl *Controller) installPackage(ctx context.Context, inlineRepo map[strin // create a symbolic link for _, file := range pkgInfo.Files { - if err := os.Symlink(filepath.Join(ctrl.RootDir, "bin", "aqua"), file.Name); err != nil { + if _, err := os.Stat(filepath.Join(ctrl.RootDir, "bin", file.Name)); err == nil { + continue + } + if err := os.Symlink("aqua-proxy", filepath.Join(ctrl.RootDir, "bin", file.Name)); err != nil { return fmt.Errorf("create a symbolic link: %w", err) } }