()
| 29 | } |
| 30 | |
| 31 | func addCmd() *cobra.Command { |
| 32 | flags := addCmdFlags{} |
| 33 | |
| 34 | command := &cobra.Command{ |
| 35 | Use: "add <pkg>...", |
| 36 | Short: "Add a new package to your devbox", |
| 37 | PreRunE: ensureNixInstalled, |
| 38 | RunE: func(cmd *cobra.Command, args []string) error { |
| 39 | if len(args) == 0 { |
| 40 | fmt.Fprintf( |
| 41 | cmd.ErrOrStderr(), |
| 42 | "Usage: %s\n\n%s\n", |
| 43 | cmd.UseLine(), |
| 44 | toSearchForPackages, |
| 45 | ) |
| 46 | return nil |
| 47 | } |
| 48 | err := addCmdFunc(cmd, args, flags) |
| 49 | if errors.Is(err, nix.ErrPackageNotFound) { |
| 50 | return usererr.WithUserMessage(err, toSearchForPackages) |
| 51 | } |
| 52 | return err |
| 53 | }, |
| 54 | } |
| 55 | |
| 56 | flags.config.register(command) |
| 57 | command.Flags().StringSliceVar( |
| 58 | &flags.allowInsecure, "allow-insecure", []string{}, |
| 59 | "allow adding packages marked as insecure.") |
| 60 | command.Flags().BoolVar( |
| 61 | &flags.disablePlugin, "disable-plugin", false, |
| 62 | "disable plugin (if any) for this package.") |
| 63 | command.Flags().StringSliceVarP( |
| 64 | &flags.platforms, "platform", "p", []string{}, |
| 65 | "add packages to run on only this platform.") |
| 66 | command.Flags().StringSliceVarP( |
| 67 | &flags.excludePlatforms, "exclude-platform", "e", []string{}, |
| 68 | "exclude packages from a specific platform.") |
| 69 | command.Flags().BoolVar( |
| 70 | &flags.patchGlibc, "patch-glibc", false, |
| 71 | "patch any ELF binaries to use the latest glibc version in nixpkgs") |
| 72 | command.Flags().StringVar( |
| 73 | &flags.patch, "patch", "auto", |
| 74 | "allow Devbox to patch the package to fix known issues (auto, always, never)") |
| 75 | command.Flags().StringSliceVarP( |
| 76 | &flags.outputs, "outputs", "o", []string{}, |
| 77 | "specify the outputs to select for the nix package") |
| 78 | |
| 79 | _ = command.Flags().MarkDeprecated("patch-glibc", `use --patch=always instead`) |
| 80 | command.MarkFlagsMutuallyExclusive("patch", "patch-glibc") |
| 81 | |
| 82 | return command |
| 83 | } |
| 84 | |
| 85 | func addCmdFunc(cmd *cobra.Command, args []string, flags addCmdFlags) error { |
| 86 | box, err := devbox.Open(&devopt.Opts{ |
no test coverage detected