Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying multiple files on the command line #78

Closed
chriselion opened this issue Jul 24, 2019 · 9 comments · Fixed by #179
Closed

Allow specifying multiple files on the command line #78

chriselion opened this issue Jul 24, 2019 · 9 comments · Fixed by #179
Labels
enhancement New feature request or implementation

Comments

@chriselion
Copy link

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.

@lorenzwalthert
Copy link

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

@waylan
Copy link

waylan commented May 6, 2020

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
Copy link
Contributor

NicolasMassart commented Sep 25, 2020

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

@NicolasMassart NicolasMassart added enhancement New feature request or implementation and removed enhancement New feature request or implementation labels Sep 25, 2020
@NicolasMassart
Copy link
Contributor

NicolasMassart commented Sep 25, 2020

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
Copy link

lorenzwalthert commented Sep 25, 2020

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
Copy link
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
Copy link
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

@NicolasMassart NicolasMassart added the enhancement New feature request or implementation label Sep 26, 2020
@waylan
Copy link

waylan commented Sep 26, 2020

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.

@kenji-miyake
Copy link
Contributor

Sent a draft PR here #178.
I'm glad if somebody would take a look and improve it. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature request or implementation
Projects
None yet
5 participants