querygit 1.0.0 → 1.0.1
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/package.json +1 -1
- package/src/index.js +36 -12
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { spawnSync } from "child_process";
|
|
4
4
|
|
|
5
5
|
const args = process.argv.slice(2);
|
|
6
6
|
const question = args.join(" ");
|
|
@@ -37,20 +37,44 @@ async function askGit(question) {
|
|
|
37
37
|
return data.choices[0].message.content.trim();
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
function tokenize(cmd) {
|
|
41
|
+
const tokens = [];
|
|
42
|
+
const re = /[^\s"']+|"([^"]*)"|'([^']*)'/g;
|
|
43
|
+
let m;
|
|
44
|
+
while ((m = re.exec(cmd))) {
|
|
45
|
+
tokens.push(m[1] ?? m[2] ?? m[0]);
|
|
46
|
+
}
|
|
47
|
+
return tokens;
|
|
48
|
+
}
|
|
49
|
+
|
|
40
50
|
function runGit(cmd) {
|
|
41
|
-
|
|
51
|
+
const parts = tokenize(cmd.trim());
|
|
52
|
+
|
|
53
|
+
if (parts[0] !== "git") {
|
|
42
54
|
return "Error: Only git commands are allowed";
|
|
43
55
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
56
|
+
|
|
57
|
+
const result = spawnSync("git", parts.slice(1), {
|
|
58
|
+
encoding: "utf-8",
|
|
59
|
+
stdio: "pipe",
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return result.stdout || result.stderr || "No results found";
|
|
49
63
|
}
|
|
50
64
|
|
|
51
65
|
const gitCmd = await askGit(question);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
console.log(
|
|
55
|
-
console.log("
|
|
56
|
-
console.log(
|
|
66
|
+
const result = runGit(gitCmd);
|
|
67
|
+
|
|
68
|
+
console.log();
|
|
69
|
+
console.log(" Model");
|
|
70
|
+
console.log(" -------");
|
|
71
|
+
console.log(" llama3.1-8b (Cerebras)");
|
|
72
|
+
console.log();
|
|
73
|
+
console.log(" Command");
|
|
74
|
+
console.log(" -------");
|
|
75
|
+
console.log(` ${gitCmd}`);
|
|
76
|
+
console.log();
|
|
77
|
+
console.log(" Result");
|
|
78
|
+
console.log(" -------");
|
|
79
|
+
result.trimEnd().split("\n").forEach(line => console.log(` ${line}`));
|
|
80
|
+
console.log();
|