Przeglądaj źródła

Add --line-numbers support to get command

The get command now supports --line-numbers flag to prefix each line
with its line number. When combined with --from, line numbers start
from the specified line.

Example:
  qmd get file.md --line-numbers
  qmd get file.md --from 10 -l 5 --line-numbers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tobi Lutke 5 miesięcy temu
rodzic
commit
3a9c5c921e
1 zmienionych plików z 10 dodań i 4 usunięć
  1. 10 4
      src/qmd.ts

+ 10 - 4
src/qmd.ts

@@ -801,7 +801,7 @@ function contextCheck(): void {
   closeDb();
 }
 
-function getDocument(filename: string, fromLine?: number, maxLines?: number): void {
+function getDocument(filename: string, fromLine?: number, maxLines?: number, lineNumbers?: boolean): void {
   const db = getDb();
 
   // Parse :linenum suffix from filename (e.g., "file.md:100")
@@ -899,15 +899,21 @@ function getDocument(filename: string, fromLine?: number, maxLines?: number): vo
   const context = getContextForPath(db, doc.collectionName, doc.path);
 
   let output = doc.body;
+  const startLine = fromLine || 1;
 
   // Apply line filtering if specified
   if (fromLine !== undefined || maxLines !== undefined) {
     const lines = output.split('\n');
-    const start = (fromLine || 1) - 1; // Convert to 0-indexed
+    const start = startLine - 1; // Convert to 0-indexed
     const end = maxLines !== undefined ? start + maxLines : lines.length;
     output = lines.slice(start, end).join('\n');
   }
 
+  // Add line numbers if requested
+  if (lineNumbers) {
+    output = addLineNumbers(output, startLine);
+  }
+
   // Output context header if exists
   if (context) {
     console.log(`Folder Context: ${context}\n---\n`);
@@ -2441,12 +2447,12 @@ switch (cli.command) {
 
   case "get": {
     if (!cli.args[0]) {
-      console.error("Usage: qmd get <filepath>[:line] [--from <line>] [-l <lines>]");
+      console.error("Usage: qmd get <filepath>[:line] [--from <line>] [-l <lines>] [--line-numbers]");
       process.exit(1);
     }
     const fromLine = cli.values.from ? parseInt(cli.values.from as string, 10) : undefined;
     const maxLines = cli.values.l ? parseInt(cli.values.l as string, 10) : undefined;
-    getDocument(cli.args[0], fromLine, maxLines);
+    getDocument(cli.args[0], fromLine, maxLines, cli.opts.lineNumbers);
     break;
   }