MCPcopy Create free account
hub / github.com/celer-pkg/celer / doCreate

Method doCreate

cmds/cmd_create.go:87–133  ·  view source on GitHub ↗
(cmd *cobra.Command)

Source from the content-addressed store, hash-verified

85}
86
87func (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
135func (c *createCmd) validateInput(value, field string, allowSpace bool) error {
136 trimmed := strings.TrimSpace(value)

Callers 1

CommandMethod · 0.95

Calls 7

validatePlatformNameMethod · 0.95
createPlatformMethod · 0.95
validateProjectNameMethod · 0.95
createProjectMethod · 0.95
validatePortNameMethod · 0.95
createPortMethod · 0.95
PrintErrorFunction · 0.92

Tested by

no test coverage detected