@solaqua/gji 0.1.0-beta.3 → 0.1.0-beta.5
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/dist/go.d.ts +0 -1
- package/dist/go.js +7 -48
- package/dist/init.js +15 -3
- package/package.json +1 -1
package/dist/go.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export interface GoCommandOptions {
|
|
|
7
7
|
stdout: (chunk: string) => void;
|
|
8
8
|
}
|
|
9
9
|
export interface GoCommandDependencies {
|
|
10
|
-
promptForCapturedOutputWorktree: (worktrees: WorktreeEntry[]) => Promise<string | null>;
|
|
11
10
|
promptForWorktree: (worktrees: WorktreeEntry[]) => Promise<string | null>;
|
|
12
11
|
}
|
|
13
12
|
export declare function createGoCommand(dependencies?: Partial<GoCommandDependencies>): (options: GoCommandOptions) => Promise<number>;
|
package/dist/go.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
2
|
import { isCancel, select } from '@clack/prompts';
|
|
3
3
|
import { listWorktrees } from './repo.js';
|
|
4
|
-
const
|
|
4
|
+
const GO_OUTPUT_FILE_ENV = 'GJI_GO_OUTPUT_FILE';
|
|
5
5
|
export function createGoCommand(dependencies = {}) {
|
|
6
|
-
const promptForCapturedOutput = dependencies.promptForCapturedOutputWorktree ?? promptForCapturedOutputWorktree;
|
|
7
6
|
const prompt = dependencies.promptForWorktree ?? promptForWorktree;
|
|
8
7
|
return async function runGoCommand(options) {
|
|
9
8
|
const worktrees = await listWorktrees(options.cwd);
|
|
@@ -16,13 +15,15 @@ export function createGoCommand(dependencies = {}) {
|
|
|
16
15
|
options.stdout(`${worktree.path}\n`);
|
|
17
16
|
return 0;
|
|
18
17
|
}
|
|
19
|
-
const chosenPath =
|
|
20
|
-
? await promptForCapturedOutput(worktrees)
|
|
21
|
-
: await prompt(worktrees);
|
|
18
|
+
const chosenPath = await prompt(worktrees);
|
|
22
19
|
if (!chosenPath) {
|
|
23
20
|
options.stderr('Aborted\n');
|
|
24
21
|
return 1;
|
|
25
22
|
}
|
|
23
|
+
if (process.env[GO_OUTPUT_FILE_ENV]) {
|
|
24
|
+
await writeFile(process.env[GO_OUTPUT_FILE_ENV], `${chosenPath}\n`, 'utf8');
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
26
27
|
options.stdout(`${chosenPath}\n`);
|
|
27
28
|
return 0;
|
|
28
29
|
};
|
|
@@ -42,45 +43,3 @@ async function promptForWorktree(worktrees) {
|
|
|
42
43
|
}
|
|
43
44
|
return choice;
|
|
44
45
|
}
|
|
45
|
-
async function promptForCapturedOutputWorktree(worktrees) {
|
|
46
|
-
const options = worktrees.map((worktree) => ({
|
|
47
|
-
value: worktree.path,
|
|
48
|
-
label: worktree.branch ?? '(detached)',
|
|
49
|
-
hint: worktree.path,
|
|
50
|
-
}));
|
|
51
|
-
const prompt = new SelectPrompt({
|
|
52
|
-
input: process.stdin,
|
|
53
|
-
options,
|
|
54
|
-
output: process.stderr,
|
|
55
|
-
render() {
|
|
56
|
-
const lines = ['Choose a worktree'];
|
|
57
|
-
switch (this.state) {
|
|
58
|
-
case 'submit': {
|
|
59
|
-
const selected = this.options[this.cursor];
|
|
60
|
-
lines.push(`> ${selected.label} (${selected.hint})`);
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
case 'cancel':
|
|
64
|
-
lines.push('> canceled');
|
|
65
|
-
break;
|
|
66
|
-
default:
|
|
67
|
-
lines.push(...this.options.map((option, index) => {
|
|
68
|
-
const prefix = index === this.cursor ? '> ' : ' ';
|
|
69
|
-
return `${prefix}${option.label} (${option.hint})`;
|
|
70
|
-
}));
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
return `${lines.join('\n')}\n`;
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
const choice = await prompt.prompt();
|
|
77
|
-
if (isCoreCancel(choice)) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
return choice;
|
|
81
|
-
}
|
|
82
|
-
function shouldUseCapturedOutputPrompt(options) {
|
|
83
|
-
return (!options.branch &&
|
|
84
|
-
options.print === true &&
|
|
85
|
-
process.env[GO_TTY_PROMPT_ENV] === '1');
|
|
86
|
-
}
|
package/dist/init.js
CHANGED
|
@@ -34,8 +34,16 @@ function gji --wraps gji --description 'gji shell integration'
|
|
|
34
34
|
return $status
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
set -l
|
|
38
|
-
or return
|
|
37
|
+
set -l output_file (mktemp -t gji-go.XXXXXX)
|
|
38
|
+
or return 1
|
|
39
|
+
env GJI_GO_OUTPUT_FILE=$output_file command gji go $argv
|
|
40
|
+
or begin
|
|
41
|
+
set -l status_code $status
|
|
42
|
+
rm -f $output_file
|
|
43
|
+
return $status_code
|
|
44
|
+
end
|
|
45
|
+
set -l target (cat $output_file)
|
|
46
|
+
rm -f $output_file
|
|
39
47
|
cd $target
|
|
40
48
|
return $status
|
|
41
49
|
end
|
|
@@ -56,7 +64,11 @@ gji() {
|
|
|
56
64
|
fi
|
|
57
65
|
|
|
58
66
|
local target
|
|
59
|
-
|
|
67
|
+
local output_file
|
|
68
|
+
output_file="$(mktemp -t gji-go.XXXXXX)" || return 1
|
|
69
|
+
GJI_GO_OUTPUT_FILE="$output_file" command gji go "$@" || { local status=$?; rm -f "$output_file"; return $status; }
|
|
70
|
+
target="$(cat "$output_file")"
|
|
71
|
+
rm -f "$output_file"
|
|
60
72
|
cd "$target" || return $?
|
|
61
73
|
return 0
|
|
62
74
|
fi
|