Skip to content

Commit 5a7f723

Browse files
authored
skip update warning on ensemble update cmd (#14)
1 parent 3605a5f commit 5a7f723

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/core/cliArgs.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** first top-level subcommand, ignoring global flags (e.g. --debug). */
2+
export function getTopLevelCommand(argv: string[]): string | undefined {
3+
const args = argv.slice(2);
4+
return args.find((arg) => !arg.startsWith('-'));
5+
}
6+
7+
export function isUpdateCommand(argv: string[] = process.argv): boolean {
8+
return getTopLevelCommand(argv) === 'update';
9+
}

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from './commands/release.js';
2323
import { updateCommand } from './commands/update.js';
2424
import { enableCommand } from './commands/enable.js';
25+
import { isUpdateCommand } from './core/cliArgs.js';
2526
import { printCliError, resolveDebugFlag } from './core/cliError.js';
2627
import { ui } from './core/ui.js';
2728

@@ -245,6 +246,11 @@ function checkForUpdates(): void {
245246
return;
246247
}
247248

249+
// user is already updating; don't suggest running `ensemble update` again.
250+
if (isUpdateCommand()) {
251+
return;
252+
}
253+
248254
// IMPORTANT: This command string must remain a static literal and MUST NOT
249255
// interpolate user-controlled input to avoid shell injection risks.
250256
const child = exec(

tests/core/cliArgs.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
import { getTopLevelCommand, isUpdateCommand } from '../../src/core/cliArgs.js';
4+
5+
describe('cliArgs', () => {
6+
describe('getTopLevelCommand', () => {
7+
it.each([
8+
[['node', 'ensemble', 'update'], 'update'],
9+
[['node', 'ensemble', '--debug', 'update'], 'update'],
10+
[['node', 'ensemble', 'push'], 'push'],
11+
[['node', 'ensemble', '--debug', 'push', '--app', 'uat'], 'push'],
12+
[['node', 'ensemble'], undefined],
13+
])('parses %j', (argv, expected) => {
14+
expect(getTopLevelCommand(argv)).toBe(expected);
15+
});
16+
});
17+
18+
describe('isUpdateCommand', () => {
19+
it.each([
20+
[['node', 'ensemble', 'update'], true],
21+
[['node', 'ensemble', '--debug', 'update'], true],
22+
[['node', 'ensemble', 'push'], false],
23+
[['node', 'ensemble', 'release', 'create'], false],
24+
])('detects update command in %j', (argv, expected) => {
25+
expect(isUpdateCommand(argv)).toBe(expected);
26+
});
27+
});
28+
});

0 commit comments

Comments
 (0)