| 17 | } |
| 18 | |
| 19 | func (i *initCmd) Command(celer *configs.Celer) *cobra.Command { |
| 20 | i.celer = celer |
| 21 | command := &cobra.Command{ |
| 22 | Use: "init", |
| 23 | Short: "Init celer with configuration repository.", |
| 24 | Long: `Initialize celer with configuration repository. |
| 25 | |
| 26 | This command initializes celer in the current directory by creating a |
| 27 | celer.toml configuration file and cloning configuration files from a |
| 28 | remote Git repository. |
| 29 | |
| 30 | Examples: |
| 31 | celer init --url https://github.com/example/conf # Initialize with conf repo |
| 32 | celer init -u https://github.com/example/conf -b main # With specific branch |
| 33 | celer init --url https://github.com/example/conf --force # Force re-initialize`, |
| 34 | Args: cobra.NoArgs, |
| 35 | RunE: func(cmd *cobra.Command, args []string) error { |
| 36 | return i.doInit() |
| 37 | }, |
| 38 | ValidArgsFunction: i.completion, |
| 39 | } |
| 40 | |
| 41 | // Register flags. |
| 42 | command.Flags().StringVarP(&i.url, "url", "u", "", "URL of the configuration repository") |
| 43 | command.Flags().StringVarP(&i.branch, "branch", "b", "", "Branch of the configuration repository (default: repository's default branch)") |
| 44 | command.Flags().BoolVarP(&i.force, "force", "f", false, "Force re-initialize even if configuration exists") |
| 45 | |
| 46 | // Mark url as required. |
| 47 | command.MarkFlagRequired("url") |
| 48 | |
| 49 | // Silence cobra's error and usage output to avoid duplicate messages. |
| 50 | command.SilenceErrors = true |
| 51 | command.SilenceUsage = true |
| 52 | return command |
| 53 | } |
| 54 | |
| 55 | func (i *initCmd) doInit() error { |
| 56 | i.url = strings.TrimSpace(i.url) |