Skip to content

Commit b8f54fe

Browse files
Apply the run configuration on run, and add Run with Parameters… (#20)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent ae4aaeb commit b8f54fe

2 files changed

Lines changed: 55 additions & 12 deletions

File tree

‎package.json‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@
106106
"category": "Fallout",
107107
"icon": "$(play)"
108108
},
109+
{
110+
"command": "fallout.runTargetWithParameters",
111+
"title": "Run Target with Parameters…",
112+
"category": "Fallout",
113+
"icon": "$(run-all)"
114+
},
109115
{
110116
"command": "fallout.goToTarget",
111117
"title": "Go to Definition",
@@ -145,16 +151,25 @@
145151
"group": "inline@1"
146152
},
147153
{
148-
"command": "fallout.goToTarget",
154+
"command": "fallout.runTargetWithParameters",
149155
"when": "(view == fallout.build || view == fallout.buildExplorer) && viewItem == falloutTarget",
150156
"group": "inline@2"
157+
},
158+
{
159+
"command": "fallout.goToTarget",
160+
"when": "(view == fallout.build || view == fallout.buildExplorer) && viewItem == falloutTarget",
161+
"group": "inline@3"
151162
}
152163
],
153164
"commandPalette": [
154165
{
155166
"command": "fallout.runTarget",
156167
"when": "false"
157168
},
169+
{
170+
"command": "fallout.runTargetWithParameters",
171+
"when": "false"
172+
},
158173
{
159174
"command": "fallout.goToTarget",
160175
"when": "false"

‎src/extension.ts‎

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,16 @@ class DeploymentProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
121121
}
122122
}
123123

124-
function runInTerminal(root: string, args: string): void {
125-
const existing = vscode.window.terminals.find(t => t.name === 'Fallout');
126-
const terminal = existing ?? vscode.window.createTerminal({ name: 'Fallout', cwd: root });
124+
function runInTerminal(root: string, args: string, env?: Record<string, string>): void {
125+
const hasEnv = env !== undefined && Object.keys(env).length > 0;
126+
let terminal = vscode.window.terminals.find(t => t.name === 'Fallout');
127+
if (hasEnv) {
128+
// Terminal env is fixed at creation; recreate so the current secrets apply.
129+
terminal?.dispose();
130+
terminal = vscode.window.createTerminal({ name: 'Fallout', cwd: root, env });
131+
} else {
132+
terminal ??= vscode.window.createTerminal({ name: 'Fallout', cwd: root });
133+
}
127134
terminal.show();
128135
terminal.sendText(process.platform === 'win32' ? `./build.ps1 ${args}` : `./build.sh ${args}`);
129136
}
@@ -133,11 +140,27 @@ export function activate(context: vscode.ExtensionContext): void {
133140
const provider = new FalloutTargetsProvider(extensionVersion);
134141
const runConfig = new RunConfigStore(context);
135142

136-
const runTarget = (name: string) => {
137-
const root = provider.source?.root;
138-
if (root) {
139-
runInTerminal(root, name);
140-
}
143+
const workspaceRoot = () => provider.source?.root ?? vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
144+
145+
// Silent run (▶): apply saved parameters as args and secrets as env.
146+
const runTarget = async (name: string): Promise<void> => {
147+
const root = workspaceRoot();
148+
if (!root) { return; }
149+
const args = [name, runConfig.buildArgs()].filter(Boolean).join(' ');
150+
runInTerminal(root, args, await runConfig.buildEnv());
151+
};
152+
153+
// Prompt run: prefill with target + saved args, let the user tweak before running.
154+
const runTargetWithParameters = async (name: string): Promise<void> => {
155+
const root = workspaceRoot();
156+
if (!root) { return; }
157+
const edited = await vscode.window.showInputBox({
158+
title: `Run ${name}`,
159+
prompt: 'Arguments passed to the Fallout build (secrets are still applied as environment variables)',
160+
value: [name, runConfig.buildArgs()].filter(Boolean).join(' '),
161+
});
162+
if (edited === undefined) { return; } // cancelled
163+
runInTerminal(root, edited, await runConfig.buildEnv());
141164
};
142165

143166
const refreshAll = () => {
@@ -168,7 +191,12 @@ export function activate(context: vscode.ExtensionContext): void {
168191
vscode.commands.registerCommand('fallout.refreshTargets', refreshAll),
169192
vscode.commands.registerCommand('fallout.runTarget', (item?: TargetItem) => {
170193
if (item?.target) {
171-
runTarget(item.target.name);
194+
void runTarget(item.target.name);
195+
}
196+
}),
197+
vscode.commands.registerCommand('fallout.runTargetWithParameters', (item?: TargetItem) => {
198+
if (item?.target) {
199+
void runTargetWithParameters(item.target.name);
172200
}
173201
}),
174202
vscode.commands.registerCommand('fallout.goToTarget', (item?: TargetItem) => {
@@ -186,13 +214,13 @@ export function activate(context: vscode.ExtensionContext): void {
186214
provider.source ??= source;
187215
const graph = loadGraph(source);
188216
checkCompatibility(graph, extensionVersion);
189-
GraphPanel.createOrShow(context.extensionUri, graph, runTarget);
217+
GraphPanel.createOrShow(context.extensionUri, graph, name => void runTarget(name));
190218
} catch (e) {
191219
void vscode.window.showWarningMessage(`Fallout: could not parse ${source.file}: ${e}`);
192220
}
193221
}),
194222
vscode.commands.registerCommand('fallout.planTarget', () => {
195-
const root = provider.source?.root ?? vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
223+
const root = workspaceRoot();
196224
if (root) {
197225
runInTerminal(root, '--plan');
198226
}

0 commit comments

Comments
 (0)