Skip to content

Commit 61dd87c

Browse files
authored
Merge pull request #1848 from wheels-dev/fix/wheels-cli-fixes
Fix/wheels cli fixes
2 parents 7d2cf4a + c39cc96 commit 61dd87c

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

cli/src/commands/wheels/reload.cfc

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,100 @@ component aliases='wheels r' extends="base" {
2424
requireWheelsApp(getCWD());
2525
arguments=reconstructArgs(arguments);
2626
var serverDetails = $getServerInfo();
27+
var appSettings = $getAppSettings(mode);
2728

29+
var reloadPassword = StructKeyExists(appSettings, "reloadPassword") ? appSettings.reloadPassword : "";
30+
getURL = serverDetails.serverURL & "/index.cfm?reload=#mode#";
31+
32+
// Handle password logic
33+
if (len(reloadPassword)) {
34+
// Password is configured
35+
if (len(password)) {
36+
// User provided a password, validate it against configured one
37+
if (password != reloadPassword) {
38+
detailOutput.error("Invalid password. The configured reload password does not match the provided password.");
39+
return;
40+
}
41+
getURL &= "&password=#password#";
42+
} else {
43+
detailOutput.error("Reload password is configured but not provided!");
44+
return;
45+
}
46+
} else {
47+
// No password configured - check if user provided one unnecessarily
48+
if (len(password)) {
49+
detailOutput.statusWarning("No reload password is configured in settings, but you provided one. Proceeding without password.");
50+
}
51+
}
2852
getURL = serverDetails.serverURL &
2953
"/index.cfm?reload=#mode#&password=#password#";
3054
var loc = new Http( url=getURL ).send().getPrefix();
3155
detailOutput.statusSuccess("Reload Request sent");
3256
}
3357

58+
private struct function $getAppSettings(required string mode="development") {
59+
try {
60+
local.appPath = getCWD();
61+
local.settingsFile = local.appPath & "/config/settings.cfm";
62+
local.envSettingsFile = local.appPath & "/config/" & arguments.mode & "/settings.cfm";
63+
local.settings = {};
64+
65+
// Override with app settings if file exists
66+
if (FileExists(local.settingsFile)) {
67+
local.settingsContent = FileRead(local.settingsFile);
68+
parseSettings(local.settingsContent, local.settings);
69+
}
70+
71+
// Override with environment-specific settings
72+
if (FileExists(local.envSettingsFile)) {
73+
local.envSettingsContent = FileRead(local.envSettingsFile);
74+
parseSettings(local.envSettingsContent, local.settings);
75+
}
76+
77+
return local.settings;
78+
} catch (any e) {
79+
detailOutput.error("Error reading settings: #e.message#");
80+
if (StructKeyExists(e, "detail") && Len(e.detail)) {
81+
detailOutput.output("Details: #e.detail#");
82+
}
83+
}
84+
}
85+
86+
private void function parseSettings(required string content, required struct settings) {
87+
local.pattern = '(?i)set\s*\(\s*([^)]+)\)';
88+
local.matches = REMatch(local.pattern, arguments.content);
89+
90+
for (local.match in local.matches) {
91+
try {
92+
// extract the inside of set(...)
93+
local.inner = REReplace(local.match, '(?i)^set\s*\(|\);?$', '', 'all');
94+
95+
// split only on FIRST =
96+
local.eqPos = Find("=", local.inner);
97+
if (!local.eqPos) continue;
98+
99+
local.key = Trim(Left(local.inner, local.eqPos - 1));
100+
local.value = Trim(Mid(local.inner, local.eqPos + 1));
101+
102+
// strip quotes
103+
local.value = REReplace(local.value, "^['""]|['""]$", "", "all");
104+
105+
// coerce types
106+
if (local.value == "true") {
107+
local.value = true;
108+
} else if (local.value == "false") {
109+
local.value = false;
110+
} else if (IsNumeric(local.value)) {
111+
local.value = Val(local.value);
112+
}
113+
114+
arguments.settings[local.key] = local.value;
115+
} catch (any e) {
116+
detailOutput.error("Error reading settings: #e.message#");
117+
if (StructKeyExists(e, "detail") && Len(e.detail)) {
118+
detailOutput.output("Details: #e.detail#");
119+
}
120+
}
121+
}
122+
}
34123
}

0 commit comments

Comments
 (0)