Comments (6)
Yup, ClioPath does it: PRQL/prql#2847
from clio.
This is a neat idea. I have released version 0.3 which adds a struct for tracking a path (which may be stdin/stdout) and was the perfect place to add a files method to list files in a directory.
So you should now be able to do something like:
pub fn read_to_tree(path: ClioPath) -> anyhow::Result<SourceTree<String>> {
let mut sources = HashMap::new();
for file in path.files(has_extension("prql"))? {
let mut file_contents = String::new();
let path = file.path().to_owned();
file.open()?.read_to_string(&mut file_contents)?;
sources.insert(path, file_contents);
}
Ok(SourceTree::new(sources))
}
(well ignoring the relative path name tidying up you do)
Does that work? I contemplated making it return a Vec<Input>
but worried about it running out of file handles.
from clio.
ClioPath
looks great! I think that will work well. Thanks!
I'm CCing @aljazerzen who wrote most of the code on our end if he has any thoughts.
files
looks fine — I'm not even sure it's needed; can folks just pass a ClioPath
to WalkDir
? It would almost be passable exactly (i.e. without a &*path
) if it implemented AsRef<Path>
, though not sure whether there are other reasons not to do that...
from clio.
Wonderful! I'll close...
from clio.
Glad it was useful, of you have any other changes you want to make pull request are always welcome.
I didn't implement AsRef<Path>
as passing a ClioPath
to File::open
would then work but defy the entire point of clio which is the -
handling.
Passing it to walkdir would have similar issues, whereas the files method returns a Vec containing the original ClioPath if it is not a directory.
To be honest I should probably remove the Deref impl and pick some proper semantics for all Path methods and reimplemented properly.
Is stdin a file? Does it have metadata? Does it exist? What about URLs?
from clio.
Ah, that makes a lot of sense. Thanks for the explanation...
from clio.
Related Issues (17)
- Doesn't play nicely with clap 3.1's derive API HOT 2
- Warnings from clap 3.2 HOT 5
- Compatibility with Clap 4? HOT 4
- Feature-gated functionality not marked in docs HOT 1
- Errors displayed poorly HOT 1
- Clap 4.1.0 compat HOT 2
- Atomic write support? HOT 1
- More configuration options on `OsStrParser` (maybe making it a "PathParser`?) HOT 1
- does not compile on rust 1.65.0
- Make seek work with HTTP range requests
- Make seek work with stdin/stdout
- remove Deref<Path> from ClioPath
- Fix length for block devices
- Add directory arg support HOT 7
- exists() on "." always returns true even if the current working directory has been deleted.
- Github tags HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clio.