Skip to content

Commit 00f39ae

Browse files
CLI module create behavior with existing meta.jsons (viamrobotics#3456)
1 parent 542fca9 commit 00f39ae

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

cli/module_registry.go

+34-15
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,26 @@ func CreateModuleAction(c *cli.Context) error {
9898
if err != nil {
9999
return err
100100
}
101-
// Check to make sure the user doesn't accidentally overwrite a module manifest
101+
102+
shouldWriteNewEmptyManifest := true
103+
104+
// If a meta.json exists in the current directory, we have a slightly different creation flow
105+
// in order to minimize user frustration. We will continue the creation if the args passed to create
106+
// match the values in the meta.json
102107
if _, err := os.Stat(defaultManifestFilename); err == nil {
103-
return errors.New("another module's meta.json already exists in the current directory. Delete it and try again")
108+
modManifest, err := loadManifest(defaultManifestFilename)
109+
if err != nil {
110+
return errors.New("another meta.json already exists in the current directory. Delete it and try again")
111+
}
112+
manifestModuleID, err := parseModuleID(modManifest.ModuleID)
113+
if err != nil ||
114+
manifestModuleID.name != moduleNameArg ||
115+
(manifestModuleID.prefix != org.GetId() && manifestModuleID.prefix != org.GetPublicNamespace()) {
116+
return errors.Errorf("a different module's meta.json already exists in the current directory. "+
117+
"Either delete that meta.json, or edit its module_id (%q) to match the args passed to this command",
118+
modManifest.ModuleID)
119+
}
120+
shouldWriteNewEmptyManifest = false
104121
}
105122

106123
response, err := client.createModule(moduleNameArg, org.GetId())
@@ -117,20 +134,22 @@ func CreateModuleAction(c *cli.Context) error {
117134
if response.GetUrl() != "" {
118135
printf(c.App.Writer, "You can view it here: %s", response.GetUrl())
119136
}
120-
emptyManifest := moduleManifest{
121-
ModuleID: returnedModuleID.String(),
122-
Visibility: moduleVisibilityPrivate,
123-
// This is done so that the json has an empty example
124-
Models: []ModuleComponent{
125-
{},
126-
},
127-
// TODO(RSDK-5608) don't auto populate until we are ready to release the build subcommand
128-
// Build: defaultBuildInfo,
129-
}
130-
if err := writeManifest(defaultManifestFilename, emptyManifest); err != nil {
131-
return err
137+
138+
if shouldWriteNewEmptyManifest {
139+
emptyManifest := moduleManifest{
140+
ModuleID: returnedModuleID.String(),
141+
Visibility: moduleVisibilityPrivate,
142+
// This is done so that the json has an empty example
143+
Models: []ModuleComponent{
144+
{},
145+
},
146+
}
147+
if err := writeManifest(defaultManifestFilename, emptyManifest); err != nil {
148+
return err
149+
}
150+
151+
printf(c.App.Writer, "Configuration for the module has been written to meta.json")
132152
}
133-
printf(c.App.Writer, "Configuration for the module has been written to meta.json")
134153
return nil
135154
}
136155

0 commit comments

Comments
 (0)