feat(lmc): support multiple files via -f flag and fix empty context
This commit is contained in:
parent
5b6c65d30f
commit
4aaa80898d
1 changed files with 11 additions and 8 deletions
19
src/index.ts
19
src/index.ts
|
|
@ -31,7 +31,7 @@ async function main() {
|
||||||
version: { type: "boolean", short: "v" },
|
version: { type: "boolean", short: "v" },
|
||||||
"git-message": { type: "boolean", short: "g" },
|
"git-message": { type: "boolean", short: "g" },
|
||||||
review: { type: "boolean", short: "r" },
|
review: { type: "boolean", short: "r" },
|
||||||
file: { type: "string", short: "f" },
|
file: { type: "string", short: "f", multiple: true },
|
||||||
stdin: { type: "boolean", short: "i" },
|
stdin: { type: "boolean", short: "i" },
|
||||||
},
|
},
|
||||||
strict: true,
|
strict: true,
|
||||||
|
|
@ -46,7 +46,7 @@ async function main() {
|
||||||
const editConfig = args.config;
|
const editConfig = args.config;
|
||||||
const generateGitMessage = args["git-message"];
|
const generateGitMessage = args["git-message"];
|
||||||
const generateReview = args.review;
|
const generateReview = args.review;
|
||||||
const inputFile = args.file;
|
const inputFiles = args.file;
|
||||||
const stdinContent = args.stdin;
|
const stdinContent = args.stdin;
|
||||||
|
|
||||||
if (showVersion) {
|
if (showVersion) {
|
||||||
|
|
@ -82,15 +82,18 @@ async function main() {
|
||||||
const input = positionals.join(" ").trim();
|
const input = positionals.join(" ").trim();
|
||||||
let stdinText = "";
|
let stdinText = "";
|
||||||
if (stdinContent) stdinText = await consumers.text(process.stdin);
|
if (stdinContent) stdinText = await consumers.text(process.stdin);
|
||||||
let fileText = "";
|
const files = [];
|
||||||
if (inputFile)
|
for (const file of inputFiles ?? [])
|
||||||
fileText = fileFence(inputFile, await fs.readFile(inputFile, "utf8"));
|
files.push(fileFence(file, await fs.readFile(file, "utf8")));
|
||||||
|
|
||||||
let prompt = base(input, [fileText, contextFence(stdinText)]);
|
let prompt = base(input, [
|
||||||
|
...files,
|
||||||
|
stdinText ? contextFence(stdinText) : "",
|
||||||
|
]);
|
||||||
if (generateGitMessage) {
|
if (generateGitMessage) {
|
||||||
prompt = commitDiff(stdinText, [fileText]);
|
prompt = commitDiff(stdinText, [...files]);
|
||||||
} else if (generateReview) {
|
} else if (generateReview) {
|
||||||
prompt = review([fileText, stdinText ? diffFence(stdinText) : "", input]);
|
prompt = review([...files, stdinText ? diffFence(stdinText) : "", input]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!prompt) throw new Error("No prompt given.");
|
if (!prompt) throw new Error("No prompt given.");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue