()
| 23 | } |
| 24 | |
| 25 | func createCmd() *cobra.Command { |
| 26 | flags := &createCmdFlags{} |
| 27 | command := &cobra.Command{ |
| 28 | Use: "create [dir] --template <template>", |
| 29 | Short: "Initialize a directory as a devbox project using a template", |
| 30 | Args: cobra.MaximumNArgs(1), |
| 31 | RunE: func(cmd *cobra.Command, args []string) error { |
| 32 | if flags.template == "" && flags.repo == "" { |
| 33 | fmt.Fprintf( |
| 34 | cmd.ErrOrStderr(), |
| 35 | "Usage: devbox create [dir] --template <template>\n\n", |
| 36 | ) |
| 37 | templates.List(cmd.ErrOrStderr(), flags.showAll) |
| 38 | if !flags.showAll { |
| 39 | fmt.Fprintf( |
| 40 | cmd.ErrOrStderr(), |
| 41 | "\nTo see all available templates, run `devbox create --show-all`\n", |
| 42 | ) |
| 43 | } |
| 44 | return nil |
| 45 | } |
| 46 | return runCreateCmd(cmd, args, flags) |
| 47 | }, |
| 48 | } |
| 49 | |
| 50 | command.Flags().StringVarP( |
| 51 | &flags.template, "template", "t", "", |
| 52 | "template to initialize the project with", |
| 53 | ) |
| 54 | command.Flags().BoolVar( |
| 55 | &flags.showAll, "show-all", false, |
| 56 | "show all available templates", |
| 57 | ) |
| 58 | command.Flags().StringVarP( |
| 59 | &flags.repo, "repo", "r", "", |
| 60 | "Git repository HTTPS URL to import template files from. Example: https://github.com/jetify-com/devbox", |
| 61 | ) |
| 62 | command.Flags().StringVarP( |
| 63 | &flags.subdir, "subdir", "s", "", |
| 64 | "Subdirectory of the Git repository in which the template files reside. Example: examples/tutorial", |
| 65 | ) |
| 66 | // this command marks a flag as hidden. Error handling for it is not necessary. |
| 67 | _ = command.Flags().MarkHidden("repo") |
| 68 | _ = command.Flags().MarkHidden("subdir") |
| 69 | |
| 70 | return command |
| 71 | } |
| 72 | |
| 73 | func runCreateCmd(cmd *cobra.Command, args []string, flags *createCmdFlags) error { |
| 74 | path := handlePath(args, flags) |
no test coverage detected