Skip to content

Commit 0e6394e

Browse files
committed
commit: fixes for wheels cli generate commands
Trim controller and model command arguments and fix primaryKey assignment - Trim leading spaces from controller command actions argument. - Trim model command properties argument. - Fix issue where model command primaryKey was not passed to migration and default id was used
1 parent 61dd87c commit 0e6394e

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

cli/src/commands/wheels/generate/controller.cfc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ component aliases="wheels g controller" extends="../base" {
5656

5757
if (hasCustomActions) {
5858
// HIGHEST PRIORITY: Custom actions specified
59-
actionList = listToArray(arguments.actions);
59+
actionList = listToArray(trim(arguments.actions));
60+
// Remove empty elements and trim each action
61+
actionList = actionList.map(function(action) {
62+
return trim(action);
63+
}).filter(function(action) {
64+
return len(action) > 0;
65+
});
6066
} else if (arguments.crud) {
6167
if (arguments.api) {
6268
// API: No form actions (new, edit)
@@ -144,4 +150,4 @@ component aliases="wheels g controller" extends="../base" {
144150
setExitCode(1);
145151
}
146152
}
147-
}
153+
}

cli/src/commands/wheels/generate/helper.cfc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,17 @@ result = #functionList[1]#("some input");
287287

288288
private string function generateHighlightFunction() {
289289
var content = chr(9) & chr(9) & "// Highlight search terms in text" & chr(10);
290-
content &= chr(9) & chr(9) & "local.searchTerm = arguments.options.term ?: """";" & chr(10);
290+
content &= chr(9) & chr(9) & "local.term = arguments.options.term ?: """";" & chr(10);
291291
content &= chr(9) & chr(9) & "local.highlightClass = arguments.options.class ?: ""highlight"";" & chr(10);
292292
content &= chr(10);
293-
content &= chr(9) & chr(9) & "if (!len(local.searchTerm)) {" & chr(10);
293+
content &= chr(9) & chr(9) & "if (!len(local.term)) {" & chr(10);
294294
content &= chr(9) & chr(9) & chr(9) & "return arguments.value;" & chr(10);
295295
content &= chr(9) & chr(9) & "}" & chr(10);
296296
content &= chr(10);
297297
content &= chr(9) & chr(9) & "return reReplaceNoCase(" & chr(10);
298298
content &= chr(9) & chr(9) & chr(9) & "arguments.value," & chr(10);
299-
content &= chr(9) & chr(9) & chr(9) & """(#local.searchTerm#)""," & chr(10);
300-
content &= chr(9) & chr(9) & chr(9) & """<span class=\""#local.highlightClass#\"">\\1</span>""," & chr(10);
299+
content &= chr(9) & chr(9) & chr(9) & """('' & local.term & '')""," & chr(10);
300+
content &= chr(9) & chr(9) & chr(9) & """<span class=''' & local.highlightClass & '''>\\1</span>""," & chr(10);
301301
content &= chr(9) & chr(9) & chr(9) & """all""" & chr(10);
302302
content &= chr(9) & chr(9) & ");" & chr(10);
303303
return content;

cli/src/commands/wheels/generate/model.cfc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ component aliases='wheels g model' extends="../base" {
131131
name = arguments.name,
132132
properties = parsedProperties,
133133
baseDirectory = getCWD(),
134-
tableName = arguments.tableName
134+
tableName = arguments.tableName,
135+
primaryKey = arguments.primaryKey
135136
);
136137
} else {
137138
var actualTableName = len(arguments.tableName) ? arguments.tableName : helpers.pluralize(lCase(arguments.name));
@@ -176,7 +177,13 @@ component aliases='wheels g model' extends="../base" {
176177
var properties = [];
177178

178179
if (len(arguments.propertiesString)) {
179-
var propList = listToArray(arguments.propertiesString);
180+
var propList = listToArray(trim(arguments.propertiesString));
181+
// Remove empty elements and trim each property
182+
propList = propList.map(function(prop) {
183+
return trim(prop);
184+
}).filter(function(prop) {
185+
return len(prop) > 0;
186+
});
180187

181188
for (var prop in propList) {
182189
var parts = listToArray(prop, ":");
@@ -264,4 +271,4 @@ component aliases='wheels g model' extends="../base" {
264271

265272
return arguments.properties;
266273
}
267-
}
274+
}

cli/src/models/ScaffoldService.cfc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ component {
212212
required string name,
213213
required array properties,
214214
string baseDirectory = "",
215-
string tableName = ""
215+
string tableName = "",
216+
string primaryKey = "id"
216217
) {
217218
var timestamp = dateFormat(now(), "yyyymmdd") & timeFormat(now(), "HHmmss");
218219
var actualTableName = len(arguments.tableName) ? arguments.tableName : variables.helpers.pluralize(lCase(arguments.name));
@@ -231,7 +232,8 @@ component {
231232
var content = generateMigrationContentWithProperties(
232233
className = className,
233234
tableName = actualTableName,
234-
properties = arguments.properties
235+
properties = arguments.properties,
236+
primaryKey = arguments.primaryKey
235237
);
236238

237239
// Write migration file
@@ -246,7 +248,8 @@ component {
246248
private function generateMigrationContentWithProperties(
247249
required string className,
248250
required string tableName,
249-
required array properties
251+
required array properties,
252+
string primaryKey = "id"
250253
) {
251254
var content = '/*' & chr(10);
252255
content &= ' |----------------------------------------------------------------------------------------------|' & chr(10);
@@ -270,7 +273,7 @@ component {
270273
content &= ' function up() {' & chr(10);
271274
content &= ' transaction {' & chr(10);
272275
content &= ' try {' & chr(10);
273-
content &= ' t = createTable(name = ''#arguments.tableName#'', force=''false'', id=''true'', primaryKey=''id'');' & chr(10);
276+
content &= ' t = createTable(name = ''#arguments.tableName#'', force=''false'', id=''true'', primaryKey=''#arguments.primaryKey#'');' & chr(10);
274277

275278
// Add properties (skip association properties that don't have database columns)
276279
for (var prop in arguments.properties) {

0 commit comments

Comments
 (0)