fd icon indicating copy to clipboard operation
fd copied to clipboard

Is it possible to use fd as a library?

Open joehillen opened this issue 3 years ago • 8 comments

Pardon my ignorance. I'm new to rust.

I'd like to use fd's features in the program I'm writing. Is it possible to use a bin crate as a library? Is there some special I would need to do to make it work?

joehillen avatar Aug 25 '21 16:08 joehillen

As it currently exists not really. The Cargo.toml only defines a [bin] section and everything in the src/ directory exists within that binary. If some component of the binary was to be broken out into it's own workspace it could then be used as a library, pending approval from the maintainer. What is it you were looking to do? It is possible that the utility you are looking for is provided by a dependency to fd or otherwise exists on crates.io

will459 avatar Aug 28 '21 03:08 will459

In particular the ignore crate may be what you want.

tmccombs avatar Aug 29 '21 16:08 tmccombs

I would suggest against that, since fd has no specification for the output (yet). For example #861 changed the output formatting, which broke my simple dotfile skeleton.

I would wait at least until #760 is fixed for all command line options. Then try to convince @sharkdp to refactor it into a lib and cli frontend. See this article for accurate information (also linked in the issue).

matu3ba avatar Dec 16 '21 19:12 matu3ba

For example #861 changed the output formatting, which broke my simple dotfile skeleton.

Sorry for that. Maybe that should have been pointed out as a breaking change in the release notes (https://github.com/sharkdp/fd/releases/tag/v8.3.0)

Then try to convince @sharkdp to refactor it into a lib and cli frontend.

I know that this could be valuable for others. I have done the same (split into bin+library) with my command-line tools bat, pastel, diskus and hexyl. The main problem is that it causes much more maintenance. Because now the interface between the library and the CLI frontend becomes a public API that needs to be carefully designed, should not have breaking changes too often, etc.

Given that the ignore crate provides a core part of fd already, I would indeed need some convincing arguments (like someone stepping up as a maintainer for the library part in the future) to consider such a move for fd, as this sounds like a lot of work.

sharkdp avatar Dec 28 '21 12:12 sharkdp

@sharkdp not really a very convincing argument but ignore's frontend is relatively low-level and annoying to use than what would be an fd's frontend if all of the later's args were to be ~~converted~~ moved to a builder interface.

AlaaZorkane avatar Jan 23 '22 22:01 AlaaZorkane

So what kind of applications would you all like to build with fd-as-a-library?

sharkdp avatar Jan 29 '22 15:01 sharkdp

So what kind of applications would you all like to build with fd-as-a-library?

Finding dependencies in some Linux environment automatically for development tools. Like finding QEMU and images to boot automatically, so the user doesn't have to constantly specify paths to things in a large build directory (Yocto is like this). I could just use the stdout though.

peterdelevoryas avatar Aug 17 '22 06:08 peterdelevoryas

So what kind of applications would you all like to build with fd-as-a-library?

I'm writing a dev-tool that needs to scan an entire filesystem for git repos, then store their config data. Subsequent runs pull from the stored file and either clone-and-set-up the repos again with all remotes & branches, or pick up new repositories and add them to the config.

tydavis avatar May 12 '23 23:05 tydavis