Skip to content

Commit

Permalink
feat: remove the configuration bin_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Aug 27, 2021
1 parent d04c3bc commit 1c29df1
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -36,7 +36,7 @@ e.g.
## Directory Structure

```
.aqua/bin/ # config.bin_dir (default .aqua/bin)
.aqua/bin/
akoi (symbolic link to ~/.aqua/bin/aqua-proxy)
~/.aqua/ # $AQUA_ROOT_DIR (default ~/.aqua)
bin/
Expand Down
1 change: 0 additions & 1 deletion docs/config.md
Expand Up @@ -19,7 +19,6 @@ If the confgiuration file path isn't specified, the file named `[.]aqua.y[a]ml`

* `packages`: The list of installed packages
* `inline_repository`: The list of package metadata
* `bin_dir`: (default: `.aqua/bin`) The directory path where links to [aqua-proxy](https://github.com/suzuki-shunsuke/aqua-proxy) are created

### type: Package

Expand Down
6 changes: 3 additions & 3 deletions docs/usage.md
Expand Up @@ -9,12 +9,12 @@ USAGE:
aqua [global options] command [command options] [arguments...]

VERSION:
0.1.0-6 (unreleased)
0.1.0-7 (unreleased)

COMMANDS:
install, i Install tools
exec Execute tool
get-bin-dir Get the configuration `bin_dir`
get-bin-dir Show the path where the packages are installed
version Show version
help, h Shows a list of commands or help for one command

Expand Down Expand Up @@ -56,7 +56,7 @@ USAGE:
```console
$ aqua help get-bin-dir
NAME:
aqua get-bin-dir - Get the configuration `bin_dir`
aqua get-bin-dir - Show the path where the packages are installed

USAGE:
aqua get-bin-dir [arguments...]
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/runner.go
Expand Up @@ -64,7 +64,7 @@ func (runner *Runner) Run(ctx context.Context, args ...string) error {
},
{
Name: "get-bin-dir",
Usage: "Get the configuration `bin_dir`",
Usage: "Show the path where the packages are installed",
Action: runner.getBinDirAction,
},
{
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/config.go
Expand Up @@ -14,7 +14,6 @@ import (
type Config struct {
Packages []*Package `validate:"dive"`
InlineRepository []*PackageInfo `yaml:"inline_repository" validate:"dive"`
BinDir string `yaml:"bin_dir"`
}

type Package struct {
Expand Down
6 changes: 2 additions & 4 deletions pkg/controller/exec.go
Expand Up @@ -30,9 +30,6 @@ func (ctrl *Controller) Exec(ctx context.Context, param *Param, args []string) e
if err := ctrl.readConfig(param.ConfigFilePath, cfg); err != nil {
return err
}
if cfg.BinDir == "" {
cfg.BinDir = filepath.Join(filepath.Dir(param.ConfigFilePath), ".aqua", "bin")
}
inlineRepo := make(map[string]*PackageInfo, len(cfg.InlineRepository))
for _, pkgInfo := range cfg.InlineRepository {
inlineRepo[pkgInfo.Name] = pkgInfo
Expand Down Expand Up @@ -82,7 +79,8 @@ func (ctrl *Controller) Exec(ctx context.Context, param *Param, args []string) e
continue
}

if err := ctrl.installPackage(ctx, inlineRepo, pkg, cfg, false); err != nil {
binDir := filepath.Join(filepath.Dir(param.ConfigFilePath), ".aqua", "bin")
if err := ctrl.installPackage(ctx, inlineRepo, pkg, binDir, false); err != nil {
return err
}

Expand Down
4 changes: 0 additions & 4 deletions pkg/controller/get_bin_dir.go
Expand Up @@ -19,10 +19,6 @@ func (ctrl *Controller) GetBinDir(cfgFilePath string) error {
if err := ctrl.readConfig(cfgFilePath, cfg); err != nil {
return err
}
if cfg.BinDir != "" {
fmt.Fprintln(ctrl.Stdout, cfg.BinDir)
return nil
}
fmt.Fprintln(ctrl.Stdout, filepath.Join(filepath.Dir(cfgFilePath), ".aqua", "bin"))
return nil
}
16 changes: 7 additions & 9 deletions pkg/controller/install.go
Expand Up @@ -26,15 +26,13 @@ func (ctrl *Controller) Install(ctx context.Context, param *Param) error { //nol
if err := ctrl.readConfig(param.ConfigFilePath, cfg); err != nil {
return err
}
if cfg.BinDir == "" {
cfg.BinDir = filepath.Join(filepath.Dir(param.ConfigFilePath), ".aqua", "bin")
}
binDir := filepath.Join(filepath.Dir(param.ConfigFilePath), ".aqua", "bin")

if err := validate.Struct(cfg); err != nil {
return fmt.Errorf("configuration is invalid: %w", err)
}

if err := os.MkdirAll(cfg.BinDir, 0o775); err != nil { //nolint:gomnd
if err := os.MkdirAll(binDir, 0o775); err != nil { //nolint:gomnd
return fmt.Errorf("create the directory: %w", err)
}
inlineRepo := make(map[string]*PackageInfo, len(cfg.InlineRepository))
Expand Down Expand Up @@ -63,7 +61,7 @@ func (ctrl *Controller) Install(ctx context.Context, param *Param) error { //nol
go func(pkg *Package) {
defer wg.Done()
maxInstallChan <- struct{}{}
if err := ctrl.installPackage(ctx, inlineRepo, pkg, cfg, param.OnlyLink); err != nil {
if err := ctrl.installPackage(ctx, inlineRepo, pkg, binDir, param.OnlyLink); err != nil {
<-maxInstallChan
logrus.WithFields(logrus.Fields{
"package_name": pkg.Name,
Expand Down Expand Up @@ -103,7 +101,7 @@ func getMaxParallelism() int {
return num
}

func (ctrl *Controller) installPackage(ctx context.Context, inlineRepo map[string]*PackageInfo, pkg *Package, cfg *Config, onlyLink bool) error {
func (ctrl *Controller) installPackage(ctx context.Context, inlineRepo map[string]*PackageInfo, pkg *Package, binDir string, onlyLink bool) error {
logE := logrus.WithFields(logrus.Fields{
"package_name": pkg.Name,
"package_version": pkg.Version,
Expand All @@ -129,7 +127,7 @@ func (ctrl *Controller) installPackage(ctx context.Context, inlineRepo map[strin
}

for _, file := range pkgInfo.Files {
if err := ctrl.createLink(cfg, file); err != nil {
if err := ctrl.createLink(binDir, file); err != nil {
return err
}
}
Expand Down Expand Up @@ -162,8 +160,8 @@ func getPkgPath(aquaRootDir string, pkg *Package, pkgInfo *PackageInfo, assetNam
return filepath.Join(aquaRootDir, "pkgs", pkgInfo.Type, "github.com", pkgInfo.RepoOwner, pkgInfo.RepoName, pkg.Version, assetName)
}

func (ctrl *Controller) createLink(cfg *Config, file *File) error {
linkPath := filepath.Join(cfg.BinDir, file.Name)
func (ctrl *Controller) createLink(binDir string, file *File) error {
linkPath := filepath.Join(binDir, file.Name)
linkDest := filepath.Join(ctrl.RootDir, "bin", "aqua-proxy")
if fileInfo, err := os.Lstat(linkPath); err == nil {
switch mode := fileInfo.Mode(); {
Expand Down

0 comments on commit 1c29df1

Please sign in to comment.