| 30 | } |
| 31 | |
| 32 | func (i *installCmd) Command(celer *configs.Celer) *cobra.Command { |
| 33 | i.celer = celer |
| 34 | command := &cobra.Command{ |
| 35 | Use: "install", |
| 36 | Short: "Install package(s).", |
| 37 | Long: `Install package(s). |
| 38 | |
| 39 | This command installs packages from available ports, either from the global |
| 40 | ports repository or from project-specific ports. The package name must be |
| 41 | specified in name@version format. |
| 42 | |
| 43 | FEATURES: |
| 44 | • Install packages with dependency resolution |
| 45 | • Support for development dependencies |
| 46 | • Force reinstallation with dependency handling |
| 47 | • Best-effort package cache storing by default |
| 48 | • Parallel build support |
| 49 | • Circular dependency detection |
| 50 | • Version conflict checking |
| 51 | |
| 52 | FLAGS: |
| 53 | -d, --dev Install as development dependency |
| 54 | -f, --force Force reinstallation (uninstall first if exists) |
| 55 | -r, --recursive With --force, recursively reinstall dependencies |
| 56 | -j, --jobs Number of parallel build jobs (default: system cores) |
| 57 | -v, --verbose Enable verbose output for debugging |
| 58 | |
| 59 | EXAMPLES: |
| 60 | celer install opencv@4.8.0 |
| 61 | celer install opencv@4.8.0 eigen@3.4.0 |
| 62 | celer install --dev gtest@1.12.1 |
| 63 | celer install --force --recursive boost@1.82.0 |
| 64 | celer install --jobs=8 --verbose opencv@4.8.0`, |
| 65 | Args: cobra.MinimumNArgs(1), |
| 66 | RunE: func(cmd *cobra.Command, args []string) error { |
| 67 | i.jobsChanged = cmd.Flags().Changed("jobs") |
| 68 | i.verboseChanged = cmd.Flags().Changed("verbose") |
| 69 | return i.runInstall(args) |
| 70 | }, |
| 71 | ValidArgsFunction: i.completion, |
| 72 | } |
| 73 | |
| 74 | // Register flags. |
| 75 | flags := command.Flags() |
| 76 | flags.BoolVarP(&i.dev, "dev", "d", false, "install in dev mode.") |
| 77 | flags.BoolVarP(&i.force, "force", "f", false, "try to uninstall before installation.") |
| 78 | flags.BoolVarP(&i.recursive, "recursive", "r", false, "combine with --force, recursively reinstall dependencies.") |
| 79 | flags.IntVarP(&i.jobs, "jobs", "j", i.celer.Jobs(), "the number of jobs to run in parallel.") |
| 80 | flags.BoolVarP(&i.verbose, "verbose", "v", false, "verbose detail information.") |
| 81 | |
| 82 | // Silence cobra's error and usage output to avoid duplicate messages. |
| 83 | command.SilenceErrors = true |
| 84 | command.SilenceUsage = true |
| 85 | return command |
| 86 | } |
| 87 | |
| 88 | func (i *installCmd) runInstall(nameVersions []string) error { |
| 89 | // Validate and clean input before initialization so input errors are reported first. |