Repository: sharkdp/bat
File: tests/syntax-tests/create_highlighted_versions.py (Python)

Code before:
import subprocess
import glob
import sys
import os.path as path
import os
import argparse


BAT_OPTIONS = [
    "--no-config",
    "--style=plain",
    "--color=always",
    "--theme='1337'",
    "--italic-text=always",
]

BINARY_OPTIONS = [
    "--show-all",
    "--no-config",
    "--style=plain",
    "--color=always",
    "--theme='1337'",
    "--italic-text=always",
]

binary_folders = ["plaintext.txt"]

def create_highlighted_versions(output_basepath):
    root = os.path.dirname(os.path.abspath(__file__))

    for source in glob.glob(path.join(root, "source", "*", "*")):
        try:
            env = os.environ.copy()
            env.pop("PAGER", None)
            env.pop("BAT_PAGER", None)
            env.pop("BAT_CONFIG_PATH", None)
            env.pop("BAT_STYLE", None)
            env.pop("BAT_THEME", None)
            env.pop("BAT_TABS", None)
            env["COLORTERM"] = "truecolor"  # make sure to output 24bit colors

            source_filename = path.basename(source)
            options = BAT_OPTIONS if source_filename not in binary_folders else BINARY_OPTIONS
            bat_output = subprocess.check_output(
                ["bat"] + options + [source],
                stderr=subprocess.PIPE, env=env,
            )

            source_dirname = path.basename(path.dirname(source))

            if source_filename == "LICENSE.md" or source_filename == "README.md":

Review comment (suggestion):
To make this more generally useful, what do you think about the following approach:

When reading one of the `source` folders, we check if a `tests/syntax-tests/source/…/bat_options` file exists. If it does, we read the file and expect each line to be an additional command-line option for `bat`.

So for your use case here, you would create `Plaintext/bat_options` with
```
--show-all
```
as the content.

Code after:
import subprocess
import glob
import sys
import os.path as path
import os
import argparse


BAT_OPTIONS = [
    "--no-config",
    "--style=plain",
    "--color=always",
    "--theme='1337'",
    "--italic-text=always",
]

SKIP_FILENAMES = [
    "LICENSE.md",
    "README.md",
    "bat_options",
]


def get_options(source):
    source_dirpath = path.dirname(source)
    options = BAT_OPTIONS.copy()
    options_file = path.join(source_dirpath, "bat_options")
    if path.exists(options_file):
        with open(options_file, "r") as f:
            options += list(map(lambda x: x.rstrip(), f.readlines()))
    return options



def create_highlighted_versions(output_basepath):
    root = os.path.dirname(os.path.abspath(__file__))

    for source in glob.glob(path.join(root, "source", "*", "*")):
        try:
            env = os.environ.copy()
            env.pop("PAGER", None)
            env.pop("BAT_PAGER", None)
            env.pop("BAT_CONFIG_PATH", None)
            env.pop("BAT_STYLE", None)
            env.pop("BAT_THEME", None)
            env.pop("BAT_TABS", None)
            env["COLORTERM"] = "truecolor"  # make sure to output 24bit colors

            source_dirname = path.basename(path.dirname(source))
            source_filename = path.basename(source)