@ferueda/grove-cli 0.1.0
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/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +22 -0
- package/dist/commands/acquire.d.ts +3 -0
- package/dist/commands/acquire.d.ts.map +1 -0
- package/dist/commands/acquire.js +47 -0
- package/dist/commands/destroy.d.ts +4 -0
- package/dist/commands/destroy.d.ts.map +1 -0
- package/dist/commands/destroy.js +34 -0
- package/dist/commands/release.d.ts +3 -0
- package/dist/commands/release.d.ts.map +1 -0
- package/dist/commands/release.js +19 -0
- package/dist/commands/status.d.ts +3 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +47 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +19 -0
- package/package.json +20 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 grove contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { acquireCmd } from "./commands/acquire.js";
|
|
3
|
+
import { releaseCmd } from "./commands/release.js";
|
|
4
|
+
import { statusCmd } from "./commands/status.js";
|
|
5
|
+
import { destroyCmd, destroyAllCmd } from "./commands/destroy.js";
|
|
6
|
+
const program = new Command();
|
|
7
|
+
program
|
|
8
|
+
.name("grove")
|
|
9
|
+
.description("CLI for Grove - A programmatic git worktree pool manager")
|
|
10
|
+
.version("0.1.0");
|
|
11
|
+
program.addCommand(acquireCmd);
|
|
12
|
+
program.addCommand(releaseCmd);
|
|
13
|
+
program.addCommand(statusCmd);
|
|
14
|
+
program.addCommand(destroyCmd);
|
|
15
|
+
program.addCommand(destroyAllCmd);
|
|
16
|
+
try {
|
|
17
|
+
await program.parseAsync(process.argv);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
console.error(`Error: ${err.message}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acquire.d.ts","sourceRoot":"","sources":["../../src/commands/acquire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,eAAO,MAAM,UAAU,SA4CnB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { loadGrove } from "../utils.js";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import pc from "picocolors";
|
|
5
|
+
export const acquireCmd = new Command("acquire")
|
|
6
|
+
.description("Acquire a worktree from the pool")
|
|
7
|
+
.option("--shell", "Drop into an interactive subshell inside the worktree")
|
|
8
|
+
.option("-r, --repo <path>", "Path to repository root")
|
|
9
|
+
.action(async (options) => {
|
|
10
|
+
try {
|
|
11
|
+
const grove = await loadGrove({ repo: options.repo });
|
|
12
|
+
const slot = await grove.acquire();
|
|
13
|
+
if (options.shell) {
|
|
14
|
+
console.error(pc.green(`🌳 Entered worktree at ${slot.path}. Type 'exit' to return.`));
|
|
15
|
+
const shell = process.env.SHELL || "/bin/sh";
|
|
16
|
+
const env = { ...process.env, GROVE_DIR: slot.path };
|
|
17
|
+
const sigHandler = () => { };
|
|
18
|
+
process.on("SIGINT", sigHandler);
|
|
19
|
+
process.on("SIGTERM", sigHandler);
|
|
20
|
+
const child = spawn(shell, [], {
|
|
21
|
+
stdio: "inherit",
|
|
22
|
+
env,
|
|
23
|
+
cwd: slot.path,
|
|
24
|
+
});
|
|
25
|
+
child.on("exit", async (code) => {
|
|
26
|
+
process.off("SIGINT", sigHandler);
|
|
27
|
+
process.off("SIGTERM", sigHandler);
|
|
28
|
+
try {
|
|
29
|
+
await grove.release(slot.path);
|
|
30
|
+
console.error(pc.green("🌳 Worktree returned to pool."));
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
console.error(pc.red(`🌳 Warning: failed to release worktree: ${err.message}`));
|
|
34
|
+
}
|
|
35
|
+
process.exit(code ?? 0);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Output raw path to stdout for pipeability
|
|
40
|
+
process.stdout.write(slot.path + "\n");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
console.error(pc.red(err.message));
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destroy.d.ts","sourceRoot":"","sources":["../../src/commands/destroy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,UAAU,SAcnB,CAAC;AAEL,eAAO,MAAM,aAAa,SAatB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { loadGrove } from "../utils.js";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
export const destroyCmd = new Command("destroy")
|
|
5
|
+
.description("Destroy a specific worktree from the pool")
|
|
6
|
+
.argument("<path>", "Path to the worktree to destroy")
|
|
7
|
+
.option("-f, --force", "Force destroy even if in use")
|
|
8
|
+
.option("-r, --repo <path>", "Path to repository root")
|
|
9
|
+
.action(async (worktreePath, options) => {
|
|
10
|
+
try {
|
|
11
|
+
const grove = await loadGrove({ repo: options.repo });
|
|
12
|
+
await grove.destroy(worktreePath, { force: options.force });
|
|
13
|
+
console.error(pc.green(`🌳 Destroyed worktree at ${worktreePath}`));
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
console.error(pc.red(err.message));
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
export const destroyAllCmd = new Command("destroy-all")
|
|
21
|
+
.description("Destroy all worktrees in the pool")
|
|
22
|
+
.option("-f, --force", "Force destroy even if in use")
|
|
23
|
+
.option("-r, --repo <path>", "Path to repository root")
|
|
24
|
+
.action(async (options) => {
|
|
25
|
+
try {
|
|
26
|
+
const grove = await loadGrove({ repo: options.repo });
|
|
27
|
+
await grove.destroyAll({ force: options.force });
|
|
28
|
+
console.error(pc.green("🌳 Destroyed all worktrees in the pool."));
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
console.error(pc.red(err.message));
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"release.d.ts","sourceRoot":"","sources":["../../src/commands/release.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,UAAU,SAenB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { loadGrove } from "../utils.js";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
export const releaseCmd = new Command("release")
|
|
5
|
+
.description("Release a worktree back to the pool")
|
|
6
|
+
.argument("[path]", "Path to the worktree to release (defaults to CWD)")
|
|
7
|
+
.option("-r, --repo <path>", "Path to repository root")
|
|
8
|
+
.action(async (worktreePath, options) => {
|
|
9
|
+
try {
|
|
10
|
+
const targetPath = worktreePath || process.cwd();
|
|
11
|
+
const grove = await loadGrove({ repo: options.repo });
|
|
12
|
+
await grove.release(targetPath);
|
|
13
|
+
console.error(pc.green("🌳 Worktree returned to pool."));
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
console.error(pc.red(err.message));
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,SAAS,SAgDlB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { loadGrove } from "../utils.js";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
export const statusCmd = new Command("status")
|
|
5
|
+
.description("Show the status of all worktrees in the pool")
|
|
6
|
+
.option("-r, --repo <path>", "Path to repository root")
|
|
7
|
+
.action(async (options) => {
|
|
8
|
+
try {
|
|
9
|
+
const grove = await loadGrove({ repo: options.repo });
|
|
10
|
+
const trees = await grove.list();
|
|
11
|
+
if (trees.length === 0) {
|
|
12
|
+
console.log("🌳 No worktrees in pool.");
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
console.log(pc.bold("ID\tStatus\t\tPath"));
|
|
16
|
+
console.log("----------------------------------------");
|
|
17
|
+
for (const wt of trees) {
|
|
18
|
+
let statusStr = "";
|
|
19
|
+
switch (wt.status) {
|
|
20
|
+
case "available":
|
|
21
|
+
statusStr = pc.green(wt.status);
|
|
22
|
+
break;
|
|
23
|
+
case "in-use":
|
|
24
|
+
statusStr = pc.red(wt.status);
|
|
25
|
+
break;
|
|
26
|
+
case "dirty":
|
|
27
|
+
statusStr = pc.yellow(wt.status);
|
|
28
|
+
break;
|
|
29
|
+
case "you're here":
|
|
30
|
+
statusStr = pc.cyan(wt.status);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
const coloredPadded = statusStr + " ".repeat(12 - wt.status.length);
|
|
34
|
+
console.log(`${wt.name}\t${coloredPadded}\t${wt.path}`);
|
|
35
|
+
if (wt.processes.length > 0) {
|
|
36
|
+
console.log(pc.gray(` └─ Processes:`));
|
|
37
|
+
for (const p of wt.processes) {
|
|
38
|
+
console.log(pc.gray(` - PID: ${p.PID} ${p.Name ? `(${p.Name})` : ""}`));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
console.error(pc.red(err.message));
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
});
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,wBAAsB,YAAY,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,CAO/E;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAOxF"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { execa } from "execa";
|
|
2
|
+
import { createGrove } from "@ferueda/grove";
|
|
3
|
+
export async function findRepoRoot(cwd = process.cwd()) {
|
|
4
|
+
try {
|
|
5
|
+
const { stdout } = await execa("git", ["rev-parse", "--show-toplevel"], { cwd });
|
|
6
|
+
return stdout.trim();
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
throw new Error(`Directory ${cwd} is not inside a git repository`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export async function loadGrove(options) {
|
|
13
|
+
let repoRoot = options.repo || process.env.GROVE_REPO_ROOT;
|
|
14
|
+
if (!repoRoot) {
|
|
15
|
+
repoRoot = await findRepoRoot();
|
|
16
|
+
}
|
|
17
|
+
const groveDir = options.dir || process.env.GROVE_DIR;
|
|
18
|
+
return createGrove({ repoRoot, groveDir });
|
|
19
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ferueda/grove-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"files": [
|
|
5
|
+
"dist"
|
|
6
|
+
],
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"grove": "./dist/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"commander": "^13.0.0",
|
|
13
|
+
"execa": "^9.6.0",
|
|
14
|
+
"picocolors": "^1.1.0",
|
|
15
|
+
"@ferueda/grove": "0.1.0"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsgo -p tsconfig.json"
|
|
19
|
+
}
|
|
20
|
+
}
|