Skip to content

Allow specifying multiple files on the command line #78

Closed
@chriselion

Description

@chriselion

This is similar to #40 but slightly different. I'd like to be able to pass multiple file names on the command line and check each one in sequence, e.g. markdown-link-check file1.md file2.md The motivation for this is trying to add a hook with pre-commit (https://pre-commit.com/); this splits the full list of files to check into smaller lists, but currently only one file from each list is checked.

This would also potentially allow some optimizations; for example if a URL appears in two markdown files, you would only need to make the request once and cache the status for subsequent checks.

Activity

lorenzwalthert

lorenzwalthert commented on Dec 26, 2019

@lorenzwalthert

I'd like to see this feature implemented too for the very same reason. Thanks for this cool package.

waylan

waylan commented on May 6, 2020

@waylan

I would like this option as well. We run all tests on our CI server. We need a single pass/fail report for all checked files. As the tool only checks a single file at a time, we need to write our own shell script which loops through all files, keeps track of any failures, and then reports a pass/fail. It would be nice if the tool could do all of that itself. Then we could simply call the tool once and be done.

NicolasMassart

NicolasMassart commented on Sep 25, 2020

@NicolasMassart
Contributor

for example if a URL appears in two markdown files, you would only need to make the request once and cache the status for subsequent checks.

This part is interesting and preventing calls to many similar urls is definitely a feature to add. Maybe in a separated ticket

added
enhancementNew feature request or implementation
and removed
enhancementNew feature request or implementation
on Sep 25, 2020
NicolasMassart

NicolasMassart commented on Sep 25, 2020

@NicolasMassart
Contributor

For the multiple files passed in a sorted manner, there's multiple things here:

Testing multiple files

This is what can be done with the find command for instance using find . -name \*.md -exec markdown-link-check {} \;
-exec runs markdown-link-check for each file (one by find output line)
To achieve this with an arbitrary input, not from the find command you can use the xargs shell command.
Use your command, whatever the command, can be git or ls we don't care as soon as it returns file paths, one by line like these with a link to "https://github.com/tcort/markdown-link-check" in each:

file1.md
file2.md
file3.md

Then use:

pre-commit [and the options here] | xargs -L1 node markdown-link-check

and you will have

FILE: file1.md
[✓] https://github.com/tcort/markdown-link-check

1 links checked.

FILE: file2.md
[✓] https://github.com/tcort/markdown-link-check

1 links checked.

FILE: file3.md
[✓] https://github.com/tcort/markdown-link-check

1 links checked.

See https://stackoverflow.com/questions/2711001/how-to-apply-shell-command-to-each-line-of-a-command-output for subtleties on using xargs

lorenzwalthert

lorenzwalthert commented on Sep 25, 2020

@lorenzwalthert

Thanks for the explanation. But for prec-commit hooks, we need a single command that takes options and a list of files. The approach with xargs does not work out of the box with that.

Also, I am not sure what exactly prevents you from just looping over the input files internally. This seems like not a great deal to implement and there is a high demand from the community.

chriselion

chriselion commented on Sep 25, 2020

@chriselion
Author

We were using an xargs-based approach for a while for pre-commit, and later a bash loop, but I eventually switched to a small python script that makes multiple calls to markdown-link-check

chriselion

chriselion commented on Sep 25, 2020

@chriselion
Author

This part is interesting and preventing calls to many similar urls is definitely a feature to add. Maybe in a separated ticket

Created a separate ticket. Lower priority than this one though (IMHO) #111

waylan

waylan commented on Sep 26, 2020

@waylan

While the find and xargs one-liners work, they don't result in a single unified report. I need a single pass/fail for all files. For an example, see my bash script. The first few lines are unique in that they build the list of files specific to my project, but the rest should be handled internally by markdown-link-check.

10 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature request or implementation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @waylan@NicolasMassart@chriselion@lorenzwalthert@kenji-miyake

      Issue actions

        Allow specifying multiple files on the command line · Issue #78 · tcort/markdown-link-check