Skip to content

Commit

Permalink
add multiple installation
Browse files Browse the repository at this point in the history
  • Loading branch information
snowmerak committed Jan 13, 2024
1 parent a8b8a3d commit afbbcf9
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmd/jetti/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,14 @@ func main() {
log.Println("tools registries renewed")
}
if param.Tools.Install {
if err := executor.InstallRegistry(); err != nil {
panic(err)
if param.Tools.Multi {
if err := executor.InstallMultipleRegistries(); err != nil {
panic(err)
}
} else {
if err := executor.InstallRegistry(); err != nil {
panic(err)
}
}
}
default:
Expand Down
1 change: 1 addition & 0 deletions internal/executor/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ type CLI struct {
Tools struct {
Renew bool `cmd:"" help:"Renew tools registry"`
Install bool `cmd:"" help:"Install tool"`
Multi bool `cmd:"" help:"Install multiple tools"`
} `cmd:"" help:"Search and install tools"`
}
69 changes: 69 additions & 0 deletions internal/executor/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,72 @@ loop:

return nil
}

type Candidate struct {
Repository string
Version string
}

func InstallMultipleRegistries() error {
registries, err := tools.GetRegistries()
if err != nil {
return err
}

multiSelectRegistry := &survey.MultiSelect{
Message: "Select registries to install",
Options: registries,
Default: nil,
}

selected := make([]string, 0)
if err := survey.AskOne(multiSelectRegistry, &selected); err != nil {
return err
}

candidates := make([]Candidate, 0, len(selected))

for _, registry := range selected {
reg, err := tools.GetRegistryInfo(registry)
if err != nil {
return err
}

sureConfirm := &survey.Confirm{
Message: fmt.Sprintf("Are you sure to install %s?\nrepository: %s\ndescription: %s\n", registry, reg.Repository, reg.Description),
Default: true,
}

sure := true
if err := survey.AskOne(sureConfirm, &sure); err != nil {
return err
}

if !sure {
continue
}

versionInput := &survey.Input{
Message: fmt.Sprintf("Input version to install %s", registry),
Default: "latest",
}

version := ""
if err := survey.AskOne(versionInput, &version); err != nil {
return err
}

candidates = append(candidates, Candidate{
Repository: reg.Repository,
Version: version,
})
}

for _, candidate := range candidates {
if err := tools.InstallRegistry(candidate.Repository, candidate.Version); err != nil {
return err
}
}

return nil
}

0 comments on commit afbbcf9

Please sign in to comment.