mage-remote-run 0.8.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/mage-remote-run.js
CHANGED
|
@@ -27,7 +27,14 @@ program
|
|
|
27
27
|
subcommandDescription: (cmd) => chalk.gray(cmd.description()),
|
|
28
28
|
optionTerm: (option) => chalk.yellow(option.flags),
|
|
29
29
|
optionDescription: (option) => chalk.gray(option.description)
|
|
30
|
-
})
|
|
30
|
+
})
|
|
31
|
+
.addHelpText('before', chalk.hex('#FFA500')(`
|
|
32
|
+
_ __ ___ __ _ __ _ ___ _ __ ___ _ __ ___ ___ | |_ ___ _ __ _ _ _ __
|
|
33
|
+
| '_ \` _ \\ / _\` |/ _\` |/ _ \\____| '__/ _ \\ '_ \` _ \\ / _ \\| __/ _ \\____| '__| | | | '_ \\
|
|
34
|
+
| | | | | | (_| | (_| | __/____| | | __/ | | | | | (_) | || __/____| | | |_| | | | |
|
|
35
|
+
|_| |_| |_|\\__,_|\\__, |\\___| |_| \\___|_| |_| |_|\\___/ \\__\\___| |_| \\__,_|_| |_|
|
|
36
|
+
|___/
|
|
37
|
+
`));
|
|
31
38
|
|
|
32
39
|
|
|
33
40
|
|
|
@@ -6,6 +6,57 @@ import { input, confirm, select } from '@inquirer/prompts';
|
|
|
6
6
|
import inquirer from 'inquirer';
|
|
7
7
|
import chalk from 'chalk';
|
|
8
8
|
|
|
9
|
+
// Helper to handle interactive connection configuration and testing
|
|
10
|
+
async function configureAndTestConnection(name, initialSettings = {}) {
|
|
11
|
+
let settings = await askForProfileSettings(initialSettings);
|
|
12
|
+
|
|
13
|
+
while (true) {
|
|
14
|
+
const shouldTest = await confirm({
|
|
15
|
+
message: 'Test connection?',
|
|
16
|
+
default: true
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (shouldTest) {
|
|
20
|
+
console.log(chalk.blue(`\nTesting connection "${name}"...`));
|
|
21
|
+
try {
|
|
22
|
+
const client = await createClient(settings);
|
|
23
|
+
const start = Date.now();
|
|
24
|
+
await client.get('V1/store/storeViews');
|
|
25
|
+
const duration = Date.now() - start;
|
|
26
|
+
console.log(chalk.green(`✔ Connection successful! (${duration}ms)`));
|
|
27
|
+
break; // Test passed, proceed to save
|
|
28
|
+
} catch (e) {
|
|
29
|
+
console.error(chalk.red(`✖ Connection failed: ${e.message}`));
|
|
30
|
+
const shouldEdit = await confirm({
|
|
31
|
+
message: 'Connection failed. Do you want to change settings?',
|
|
32
|
+
default: true
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (shouldEdit) {
|
|
36
|
+
// Re-ask for settings using current values as defaults
|
|
37
|
+
settings = await askForProfileSettings(settings);
|
|
38
|
+
continue; // Loop back to test
|
|
39
|
+
} else {
|
|
40
|
+
// If they don't want to edit, ask if they want to save anyway
|
|
41
|
+
const saveAnyway = await confirm({
|
|
42
|
+
message: 'Save configuration anyway?',
|
|
43
|
+
default: false
|
|
44
|
+
});
|
|
45
|
+
if (!saveAnyway) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
break; // Break to save
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
// User skipped test, save
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return settings;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
9
60
|
export function registerConnectionCommands(program) {
|
|
10
61
|
const connections = program.command('connection').description('Manage mage-remote-run connection profiles');
|
|
11
62
|
|
|
@@ -19,7 +70,11 @@ export function registerConnectionCommands(program) {
|
|
|
19
70
|
validate: value => value ? true : 'Name is required'
|
|
20
71
|
});
|
|
21
72
|
|
|
22
|
-
const settings = await
|
|
73
|
+
const settings = await configureAndTestConnection(name);
|
|
74
|
+
if (!settings) {
|
|
75
|
+
console.log(chalk.yellow('\nConfiguration cancelled.'));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
23
78
|
|
|
24
79
|
await addProfile(name, settings);
|
|
25
80
|
console.log(chalk.green(`\nProfile "${name}" saved successfully!`));
|
|
@@ -90,15 +145,35 @@ export function registerConnectionCommands(program) {
|
|
|
90
145
|
} catch (e) { handleError(e); }
|
|
91
146
|
});
|
|
92
147
|
|
|
93
|
-
connections.command('edit
|
|
148
|
+
connections.command('edit [name]')
|
|
94
149
|
.description('Edit a connection profile')
|
|
95
150
|
.action(async (name) => {
|
|
96
151
|
try {
|
|
97
152
|
const config = await loadConfig();
|
|
153
|
+
const profiles = Object.keys(config.profiles || {});
|
|
154
|
+
|
|
155
|
+
if (profiles.length === 0) {
|
|
156
|
+
console.log(chalk.yellow('No profiles found to edit.'));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (!name) {
|
|
161
|
+
name = await select({
|
|
162
|
+
message: 'Select Profile to Edit:',
|
|
163
|
+
choices: profiles.map(p => ({ value: p, name: p }))
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
98
167
|
const profile = config.profiles[name];
|
|
99
168
|
if (!profile) throw new Error(`Profile ${name} not found`);
|
|
100
169
|
|
|
101
|
-
|
|
170
|
+
console.log(chalk.blue(`Editing profile "${name}"`));
|
|
171
|
+
|
|
172
|
+
const settings = await configureAndTestConnection(name, profile);
|
|
173
|
+
if (!settings) {
|
|
174
|
+
console.log(chalk.yellow('\nEdit cancelled.'));
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
102
177
|
|
|
103
178
|
config.profiles[name] = settings;
|
|
104
179
|
await saveConfig(config);
|
|
@@ -190,7 +265,8 @@ export function registerConnectionCommands(program) {
|
|
|
190
265
|
});
|
|
191
266
|
|
|
192
267
|
connections.command('select')
|
|
193
|
-
.description('Select the active connection profile')
|
|
268
|
+
.description('Select the active connection profile (aliases: change, switch)')
|
|
269
|
+
.aliases(['switch', 'change'])
|
|
194
270
|
.action(async () => {
|
|
195
271
|
try {
|
|
196
272
|
const config = await loadConfig();
|