Skip to content

Commit b62c447

Browse files
committed
Rename --code to --markdown, closes simonw#42
1 parent cfc9fa5 commit b62c447

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ This will output the contents of every file, with each file preceded by its rela
6464
files-to-prompt path/to/directory --cxml
6565
```
6666

67-
- `--code`: Output as fenced code blocks.
67+
- `--markdown`: Output as Markdown with fenced code blocks.
6868

6969
```bash
70-
files-to-prompt path/to/directory --code
70+
files-to-prompt path/to/directory --markdown
7171
```
7272

7373
- `-o/--output <file>`: Write the output to a file instead of printing it to the console.
@@ -214,12 +214,12 @@ Contents of file2.txt
214214
</documents>
215215
```
216216

217-
## --code fenced code block output
217+
## --markdown fenced code block output
218218

219-
The `--code` option will output the files as fenced code blocks, which can be useful for pasting into Markdown documents.
219+
The `--markdown` option will output the files as fenced code blocks, which can be useful for pasting into Markdown documents.
220220

221221
```bash
222-
files-to-prompt path/to/directory --code
222+
files-to-prompt path/to/directory --markdown
223223
```
224224
The language tag will be guessed based on the filename.
225225

files_to_prompt/cli.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ def add_line_numbers(content):
5252
return "\n".join(numbered_lines)
5353

5454

55-
def print_path(writer, path, content, cxml, code, line_numbers):
55+
def print_path(writer, path, content, cxml, markdown, line_numbers):
5656
if cxml:
5757
print_as_xml(writer, path, content, line_numbers)
58-
elif code:
59-
print_as_code(writer, path, content, line_numbers)
58+
elif markdown:
59+
print_as_markdown(writer, path, content, line_numbers)
6060
else:
6161
print_default(writer, path, content, line_numbers)
6262

@@ -84,7 +84,7 @@ def print_as_xml(writer, path, content, line_numbers):
8484
global_index += 1
8585

8686

87-
def print_as_code(writer, path, content, line_numbers):
87+
def print_as_markdown(writer, path, content, line_numbers):
8888
lang = EXT_TO_LANG.get(path.split(".")[-1], "")
8989
# Figure out how many backticks to use
9090
backticks = "```"
@@ -108,13 +108,13 @@ def process_path(
108108
ignore_patterns,
109109
writer,
110110
claude_xml,
111-
code,
111+
markdown,
112112
line_numbers=False,
113113
):
114114
if os.path.isfile(path):
115115
try:
116116
with open(path, "r") as f:
117-
print_path(writer, path, f.read(), claude_xml, code, line_numbers)
117+
print_path(writer, path, f.read(), claude_xml, markdown, line_numbers)
118118
except UnicodeDecodeError:
119119
warning_message = f"Warning: Skipping file {path} due to UnicodeDecodeError"
120120
click.echo(click.style(warning_message, fg="red"), err=True)
@@ -158,7 +158,12 @@ def process_path(
158158
try:
159159
with open(file_path, "r") as f:
160160
print_path(
161-
writer, file_path, f.read(), claude_xml, code, line_numbers
161+
writer,
162+
file_path,
163+
f.read(),
164+
claude_xml,
165+
markdown,
166+
line_numbers,
162167
)
163168
except UnicodeDecodeError:
164169
warning_message = (
@@ -220,7 +225,9 @@ def read_paths_from_stdin(use_null_separator):
220225
help="Output in XML-ish format suitable for Claude's long context window.",
221226
)
222227
@click.option(
223-
"--code", is_flag=True, help="Output in triple backtick fenced code blocks"
228+
"--markdown",
229+
is_flag=True,
230+
help="Output Markdown with fenced code blocks",
224231
)
225232
@click.option(
226233
"line_numbers",
@@ -245,7 +252,7 @@ def cli(
245252
ignore_patterns,
246253
output_file,
247254
claude_xml,
248-
code,
255+
markdown,
249256
line_numbers,
250257
null,
251258
):
@@ -275,7 +282,7 @@ def cli(
275282
...
276283
</documents>
277284
278-
If the `--code` flag is provided, the output will be structured as follows:
285+
If the `--markdown` flag is provided, the output will be structured as follows:
279286
280287
\b
281288
path/to/file1.py
@@ -316,7 +323,7 @@ def cli(
316323
ignore_patterns,
317324
writer,
318325
claude_xml,
319-
code,
326+
markdown,
320327
line_numbers,
321328
)
322329
if claude_xml:

tests/test_files_to_prompt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def test_paths_from_arguments_and_stdin(tmpdir):
377377
assert "Contents of file2" in result.output
378378

379379

380-
def test_code(tmpdir):
380+
def test_markdown(tmpdir):
381381
runner = CliRunner()
382382
with tmpdir.as_cwd():
383383
os.makedirs("test_dir")
@@ -389,7 +389,7 @@ def test_code(tmpdir):
389389
f.write("This is javascript")
390390
with open("test_dir/code.unknown", "w") as f:
391391
f.write("This is an unknown file type")
392-
result = runner.invoke(cli, ["test_dir", "--code"])
392+
result = runner.invoke(cli, ["test_dir", "--markdown"])
393393
assert result.exit_code == 0
394394
actual = result.output
395395
expected = (

0 commit comments

Comments
 (0)