(cmd *cobra.Command)
| 85 | } |
| 86 | |
| 87 | func (c *createCmd) doCreate(cmd *cobra.Command) error { |
| 88 | // Check that exactly one flag is provided. |
| 89 | flags := cmd.Flags() |
| 90 | platformChanged := flags.Changed("platform") |
| 91 | projectChanged := flags.Changed("project") |
| 92 | portChanged := flags.Changed("port") |
| 93 | |
| 94 | provided := 0 |
| 95 | if platformChanged { |
| 96 | provided++ |
| 97 | } |
| 98 | if projectChanged { |
| 99 | provided++ |
| 100 | } |
| 101 | if portChanged { |
| 102 | provided++ |
| 103 | } |
| 104 | |
| 105 | if provided != 1 { |
| 106 | err := fmt.Errorf("invalid input argument") |
| 107 | return color.PrintError(err, "You must specify exactly one component to create (--platform, --project, or --port).") |
| 108 | } |
| 109 | |
| 110 | // Validate inputs and create. |
| 111 | if platformChanged { |
| 112 | if err := c.validatePlatformName(c.platform); err != nil { |
| 113 | return color.PrintError(err, "Invalid platform name.") |
| 114 | } |
| 115 | return c.createPlatform(c.platform) |
| 116 | } |
| 117 | |
| 118 | if projectChanged { |
| 119 | if err := c.validateProjectName(c.project); err != nil { |
| 120 | return color.PrintError(err, "Invalid project name.") |
| 121 | } |
| 122 | return c.createProject(c.project) |
| 123 | } |
| 124 | |
| 125 | if portChanged { |
| 126 | if err := c.validatePortName(c.port); err != nil { |
| 127 | return color.PrintError(err, "Invalid port name.") |
| 128 | } |
| 129 | return c.createPort(c.port) |
| 130 | } |
| 131 | |
| 132 | return nil |
| 133 | } |
| 134 | |
| 135 | func (c *createCmd) validateInput(value, field string, allowSpace bool) error { |
| 136 | trimmed := strings.TrimSpace(value) |
no test coverage detected