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" },
|
||||
"git-message": { type: "boolean", short: "g" },
|
||||
review: { type: "boolean", short: "r" },
|
||||
file: { type: "string", short: "f" },
|
||||
file: { type: "string", short: "f", multiple: true },
|
||||
stdin: { type: "boolean", short: "i" },
|
||||
},
|
||||
strict: true,
|
||||
|
|
@ -46,7 +46,7 @@ async function main() {
|
|||
const editConfig = args.config;
|
||||
const generateGitMessage = args["git-message"];
|
||||
const generateReview = args.review;
|
||||
const inputFile = args.file;
|
||||
const inputFiles = args.file;
|
||||
const stdinContent = args.stdin;
|
||||
|
||||
if (showVersion) {
|
||||
|
|
@ -82,15 +82,18 @@ async function main() {
|
|||
const input = positionals.join(" ").trim();
|
||||
let stdinText = "";
|
||||
if (stdinContent) stdinText = await consumers.text(process.stdin);
|
||||
let fileText = "";
|
||||
if (inputFile)
|
||||
fileText = fileFence(inputFile, await fs.readFile(inputFile, "utf8"));
|
||||
const files = [];
|
||||
for (const file of inputFiles ?? [])
|
||||
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) {
|
||||
prompt = commitDiff(stdinText, [fileText]);
|
||||
prompt = commitDiff(stdinText, [...files]);
|
||||
} 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.");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue