()
| 30 | } |
| 31 | |
| 32 | func cacheCmd() *cobra.Command { |
| 33 | flags := cacheFlags{} |
| 34 | cacheCommand := &cobra.Command{ |
| 35 | Use: "cache", |
| 36 | Short: "Collection of commands to interact with nix cache", |
| 37 | PersistentPreRunE: ensureNixInstalled, |
| 38 | } |
| 39 | |
| 40 | uploadCommand := &cobra.Command{ |
| 41 | Use: "upload [installable]", |
| 42 | Aliases: []string{"copy"}, // This mimics the nix command |
| 43 | Short: "upload specified or nix packages in current project to cache", |
| 44 | Long: heredoc.Doc(` |
| 45 | Upload specified nix installable or nix packages in current project to cache. |
| 46 | If [installable] is provided, only that installable will be uploaded. |
| 47 | Otherwise, all packages in the project will be uploaded. |
| 48 | To upload to specific cache, use --to flag. Otherwise, a cache from |
| 49 | the cache provider will be used, if available. |
| 50 | `), |
| 51 | Args: cobra.MaximumNArgs(1), |
| 52 | RunE: func(cmd *cobra.Command, args []string) error { |
| 53 | if len(args) > 0 { |
| 54 | return devbox.UploadInstallableToCache( |
| 55 | cmd.Context(), cmd.ErrOrStderr(), flags.to, args[0], |
| 56 | ) |
| 57 | } |
| 58 | box, err := devbox.Open(&devopt.Opts{ |
| 59 | Dir: flags.path, |
| 60 | Stderr: cmd.ErrOrStderr(), |
| 61 | }) |
| 62 | if err != nil { |
| 63 | return errors.WithStack(err) |
| 64 | } |
| 65 | return box.UploadProjectToCache(cmd.Context(), flags.to) |
| 66 | }, |
| 67 | } |
| 68 | |
| 69 | flags.pathFlag.register(uploadCommand) |
| 70 | uploadCommand.Flags().StringVar( |
| 71 | &flags.to, "to", "", "URI of the cache to copy to") |
| 72 | |
| 73 | cacheCommand.AddCommand(uploadCommand) |
| 74 | cacheCommand.AddCommand(cacheConfigureCmd()) |
| 75 | cacheCommand.AddCommand(cacheCredentialsCmd()) |
| 76 | cacheCommand.AddCommand(cacheEnableCmd()) |
| 77 | cacheCommand.AddCommand(cacheInfoCmd()) |
| 78 | |
| 79 | return cacheCommand |
| 80 | } |
| 81 | |
| 82 | func cacheConfigureCmd() *cobra.Command { |
| 83 | username := "" |
no test coverage detected