Skip to content

Commit

Permalink
fix: rename cube to aqua
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Aug 25, 2021
1 parent f56f549 commit ba312f8
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 17 deletions.
3 changes: 3 additions & 0 deletions cube.yaml → aqua.yaml
Expand Up @@ -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
22 changes: 22 additions & 0 deletions 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
}
32 changes: 18 additions & 14 deletions pkg/cli/runner.go
Expand Up @@ -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"
)

Expand All @@ -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",
Expand All @@ -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"},
},
},
},
},
}

Expand Down
9 changes: 7 additions & 2 deletions pkg/controller/exec.go
Expand Up @@ -2,6 +2,7 @@ package controller

import (
"context"
"errors"
"fmt"
"os"
"os/exec"
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/controller/install.go
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit ba312f8

Please sign in to comment.