| 86 | } |
| 87 | |
| 88 | func (i *installCmd) runInstall(nameVersions []string) error { |
| 89 | // Validate and clean input before initialization so input errors are reported first. |
| 90 | cleanedNameVersions := make([]string, 0, len(nameVersions)) |
| 91 | for _, nameVersion := range nameVersions { |
| 92 | cleanedNameVersion, err := i.validateAndCleanInput(nameVersion) |
| 93 | if err != nil { |
| 94 | return color.PrintError(err, "invalid package specification: %s", nameVersion) |
| 95 | } |
| 96 | cleanedNameVersions = append(cleanedNameVersions, cleanedNameVersion) |
| 97 | } |
| 98 | |
| 99 | if err := i.celer.Init(); err != nil { |
| 100 | return color.PrintError(err, "failed to initialize celer.") |
| 101 | } |
| 102 | |
| 103 | // Check git first as it's needed for cloning and reading commit hashes, |
| 104 | // and must check tool after celer initialized, since "downloads" will be assign value after init. |
| 105 | if err := buildtools.CheckTools(i.celer, "git"); err != nil { |
| 106 | return color.PrintError(err, "failed to check build tool: git") |
| 107 | } |
| 108 | |
| 109 | if err := i.overrideFlags(); err != nil { |
| 110 | return color.PrintError(err, "invalid install options.") |
| 111 | } |
| 112 | |
| 113 | // Install port one by one. |
| 114 | for _, nameVersion := range cleanedNameVersions { |
| 115 | if err := i.install(nameVersion); err != nil { |
| 116 | return err |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | return nil |
| 121 | } |
| 122 | |
| 123 | // validateAndCleanInput validates and cleans the package name@version input. |
| 124 | func (i *installCmd) validateAndCleanInput(nameVersion string) (string, error) { |