custom-menu-cli 1.0.4 → 2.0.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/README-pt.md +16 -2
- package/README.md +16 -2
- package/menu.json +14 -0
- package/package.json +1 -1
- package/src/actions.js +15 -4
package/README-pt.md
CHANGED
|
@@ -94,8 +94,8 @@ O arquivo JSON que define o menu tem a seguinte estrutura:
|
|
|
94
94
|
|
|
95
95
|
```json
|
|
96
96
|
{
|
|
97
|
-
"name": "
|
|
98
|
-
"description": "
|
|
97
|
+
"name": "custom-menu-cli",
|
|
98
|
+
"description": "JSON-based terminal menu",
|
|
99
99
|
"options": [
|
|
100
100
|
{
|
|
101
101
|
"id": "1",
|
|
@@ -114,6 +114,13 @@ O arquivo JSON que define o menu tem a seguinte estrutura:
|
|
|
114
114
|
"name": "Up Service",
|
|
115
115
|
"type": "action",
|
|
116
116
|
"command": "echo 'Up A'"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"id": "1.3",
|
|
120
|
+
"name": "Restart Project A (from inside)",
|
|
121
|
+
"type": "custom-action",
|
|
122
|
+
"idList": ["1.1", "1.2"],
|
|
123
|
+
"confirm": true
|
|
117
124
|
}
|
|
118
125
|
]
|
|
119
126
|
},
|
|
@@ -123,6 +130,13 @@ O arquivo JSON que define o menu tem a seguinte estrutura:
|
|
|
123
130
|
"type": "custom-action",
|
|
124
131
|
"idList": ["1.1", "1.2"],
|
|
125
132
|
"confirm": true
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"id": "3",
|
|
136
|
+
"name": "Restart Project A (Nested)",
|
|
137
|
+
"type": "custom-action",
|
|
138
|
+
"idList": ["1.3"],
|
|
139
|
+
"confirm": true
|
|
126
140
|
}
|
|
127
141
|
]
|
|
128
142
|
}
|
package/README.md
CHANGED
|
@@ -95,8 +95,8 @@ The JSON file that defines the menu has the following structure:
|
|
|
95
95
|
|
|
96
96
|
```json
|
|
97
97
|
{
|
|
98
|
-
"name": "
|
|
99
|
-
"description": "
|
|
98
|
+
"name": "custom-menu-cli",
|
|
99
|
+
"description": "JSON-based terminal menu",
|
|
100
100
|
"options": [
|
|
101
101
|
{
|
|
102
102
|
"id": "1",
|
|
@@ -115,6 +115,13 @@ The JSON file that defines the menu has the following structure:
|
|
|
115
115
|
"name": "Up Service",
|
|
116
116
|
"type": "action",
|
|
117
117
|
"command": "echo 'Up A'"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"id": "1.3",
|
|
121
|
+
"name": "Restart Project A (from inside)",
|
|
122
|
+
"type": "custom-action",
|
|
123
|
+
"idList": ["1.1", "1.2"],
|
|
124
|
+
"confirm": true
|
|
118
125
|
}
|
|
119
126
|
]
|
|
120
127
|
},
|
|
@@ -124,6 +131,13 @@ The JSON file that defines the menu has the following structure:
|
|
|
124
131
|
"type": "custom-action",
|
|
125
132
|
"idList": ["1.1", "1.2"],
|
|
126
133
|
"confirm": true
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"id": "3",
|
|
137
|
+
"name": "Restart Project A (Nested)",
|
|
138
|
+
"type": "custom-action",
|
|
139
|
+
"idList": ["1.3"],
|
|
140
|
+
"confirm": true
|
|
127
141
|
}
|
|
128
142
|
]
|
|
129
143
|
}
|
package/menu.json
CHANGED
|
@@ -19,6 +19,13 @@
|
|
|
19
19
|
"name": "Up Service",
|
|
20
20
|
"type": "action",
|
|
21
21
|
"command": "echo 'Up A'"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"id": "1.3",
|
|
25
|
+
"name": "Restart Project A (from inside)",
|
|
26
|
+
"type": "custom-action",
|
|
27
|
+
"idList": ["1.1", "1.2"],
|
|
28
|
+
"confirm": true
|
|
22
29
|
}
|
|
23
30
|
]
|
|
24
31
|
},
|
|
@@ -28,6 +35,13 @@
|
|
|
28
35
|
"type": "custom-action",
|
|
29
36
|
"idList": ["1.1", "1.2"],
|
|
30
37
|
"confirm": true
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"id": "3",
|
|
41
|
+
"name": "Restart Project A (Nested)",
|
|
42
|
+
"type": "custom-action",
|
|
43
|
+
"idList": ["1.3"],
|
|
44
|
+
"confirm": true
|
|
31
45
|
}
|
|
32
46
|
]
|
|
33
47
|
}
|
package/package.json
CHANGED
package/src/actions.js
CHANGED
|
@@ -14,14 +14,25 @@ async function handleAction(selected) {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
async function handleCustomAction(selected, flatMap) {
|
|
17
|
+
async function handleCustomAction(selected, flatMap, depth = 0) {
|
|
18
|
+
if (depth >= 3) {
|
|
19
|
+
console.log(chalk.red(`Maximum recursion depth (3) exceeded for custom action: ${selected.id}`));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
18
22
|
const proceed = selected.confirm ? await confirmExecution(chalk.yellow(`Execute command list ${selected.idList.join(', ')}?`)) : true;
|
|
19
23
|
if (proceed) {
|
|
20
24
|
for (const id of selected.idList) {
|
|
21
25
|
const cmd = flatMap[id];
|
|
22
|
-
if (cmd
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
if (cmd) {
|
|
27
|
+
if (cmd.type === 'action' && cmd.command) {
|
|
28
|
+
console.log(chalk.blue(`Executing command: [id: ${cmd.id} name: ${cmd.name} ]`));
|
|
29
|
+
await terminal.execCommandSync(cmd.command);
|
|
30
|
+
} else if (cmd.type === 'custom-action') {
|
|
31
|
+
console.log(chalk.blue(`Executing custom action: [id: ${cmd.id} name: ${cmd.name} ]`));
|
|
32
|
+
await handleCustomAction(cmd, flatMap, depth + 1);
|
|
33
|
+
} else {
|
|
34
|
+
console.log(chalk.red(`Unknown or unexecutable type for id: ${cmd.id}`));
|
|
35
|
+
}
|
|
25
36
|
}
|
|
26
37
|
}
|
|
27
38
|
}
|