collectName prompts for the application/API name if not already provided.
(cmd *cobra.Command, inputs *SetupInputs)
| 784 | |
| 785 | // collectName prompts for the application/API name if not already provided. |
| 786 | func collectName(cmd *cobra.Command, inputs *SetupInputs) error { |
| 787 | if setupName.IsSet(cmd) { |
| 788 | if inputs.Name == "" { |
| 789 | return fmt.Errorf("application name cannot be empty") |
| 790 | } |
| 791 | return nil |
| 792 | } |
| 793 | |
| 794 | switch { |
| 795 | case inputs.App: |
| 796 | defaultName := inputs.Name |
| 797 | if defaultName == "" { |
| 798 | defaultName = "My App" |
| 799 | } |
| 800 | inputs.Name = defaultName |
| 801 | if err := setupName.Ask(cmd, &inputs.Name, &defaultName); err != nil { |
| 802 | return fmt.Errorf("failed to enter application name: %w", err) |
| 803 | } |
| 804 | if inputs.Name == "" { |
| 805 | return fmt.Errorf("application name cannot be empty") |
| 806 | } |
| 807 | |
| 808 | case inputs.API && inputs.Name == "": |
| 809 | cwd, _ := os.Getwd() |
| 810 | defaultName := filepath.Base(cwd) |
| 811 | if defaultName == "" || defaultName == "." { |
| 812 | defaultName = "my-api" |
| 813 | } |
| 814 | inputs.Name = defaultName |
| 815 | if err := setupName.Ask(cmd, &inputs.Name, &defaultName); err != nil { |
| 816 | return fmt.Errorf("failed to enter API name: %w", err) |
| 817 | } |
| 818 | } |
| 819 | return nil |
| 820 | } |
| 821 | |
| 822 | func collectAPIInputs(cmd *cobra.Command, cli *cli, inputs *SetupInputs) error { |
| 823 | // Identifier. |
no test coverage detected