Skip to content

Commit 04e63dd

Browse files
committed
brnaches
1 parent f46ec1e commit 04e63dd

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

‎src/commands/settings/branches.js‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { fetchApi } from '../../utils/fetchApi.js';
2+
3+
export async function runBranchesAll({ repo } = {}) {
4+
if (!repo) {
5+
const err = new Error('--repo is required');
6+
err.exitCode = 1;
7+
throw err;
8+
}
9+
return fetchApi('/extension/branches/all', 'POST', { repo });
10+
}
11+
12+
export async function runBranchesDefault({ repo } = {}) {
13+
if (!repo) {
14+
const err = new Error('--repo is required');
15+
err.exitCode = 1;
16+
throw err;
17+
}
18+
return fetchApi('/extension/branches/default', 'POST', { repo });
19+
}
20+
21+
export async function runBranchesUpdateDefault({ repo, branch } = {}) {
22+
if (!repo) {
23+
const err = new Error('--repo is required');
24+
err.exitCode = 1;
25+
throw err;
26+
}
27+
if (!branch) {
28+
const err = new Error('--branch is required');
29+
err.exitCode = 1;
30+
throw err;
31+
}
32+
return fetchApi('/extension/branches/update-default', 'POST', { repo, branch });
33+
}

‎src/commands/settings/index.js‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { runBranchesAll, runBranchesDefault, runBranchesUpdateDefault } from './branches.js';
2+
3+
/**
4+
* Register all `codeant settings <verb>` subcommands.
5+
*
6+
* Each subcommand implementation lives in its own file alongside this index
7+
* and exports a single async function named run<Command>(opts).
8+
*
9+
* To add a new subcommand:
10+
* 1. Create src/commands/settings/<name>.js exporting run<Name>(opts).
11+
* 2. Import it here.
12+
* 3. Add a settings.command(...).action(...) block below following the
13+
* existing pattern.
14+
*
15+
* @param {import('commander').Command} program
16+
* @param {{ runCmd: Function }} helpers
17+
*/
18+
export default function registerSettingsCommands(program, { runCmd }) {
19+
const settings = program
20+
.command('settings')
21+
.description('Manage CodeAnt AI settings');
22+
23+
// ── branches all ───────────────────────────────────────────────────────────
24+
settings
25+
.command('branches-all')
26+
.description('List all branches for a repository')
27+
.requiredOption('--repo <repo>', 'Repository (owner/repo)')
28+
.action((opts) => runCmd(() => runBranchesAll({ repo: opts.repo })));
29+
30+
// ── branches default ───────────────────────────────────────────────────────
31+
settings
32+
.command('branches-default')
33+
.description('Get the default branch for a repository')
34+
.requiredOption('--repo <repo>', 'Repository (owner/repo)')
35+
.action((opts) => runCmd(() => runBranchesDefault({ repo: opts.repo })));
36+
37+
// ── branches update-default ────────────────────────────────────────────────
38+
settings
39+
.command('branches-update-default')
40+
.description('Set the default branch for a repository')
41+
.requiredOption('--repo <repo>', 'Repository (owner/repo)')
42+
.requiredOption('--branch <name>', 'Branch name to set as default')
43+
.action((opts) => runCmd(() => runBranchesUpdateDefault({ repo: opts.repo, branch: opts.branch })));
44+
}

‎src/index.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as scm from './scm/index.js';
1919
import { setConfigValue } from './utils/config.js';
2020
import { track, shutdown as analyticsShutdown, isTelemetryDisabled } from './utils/analytics.js';
2121
import registerScansCommands from './commands/scans/index.js';
22+
import registerSettingsCommands from './commands/settings/index.js';
2223

2324
// Read version from package.json
2425
const require = createRequire(import.meta.url);
@@ -393,6 +394,9 @@ program
393394
// ─── Scans commands ───
394395
registerScansCommands(program, { runCmd });
395396

397+
// ─── Settings commands ───
398+
registerSettingsCommands(program, { runCmd });
399+
396400
// ─── Telemetry control ───
397401
program
398402
.command('set-telemetry <enabled>')

0 commit comments

Comments
 (0)