Git Product home page Git Product logo

Comments (6)

aljazerzen avatar aljazerzen commented on July 4, 2024 1

Yup, ClioPath does it: PRQL/prql#2847

from clio.

aj-bagwell avatar aj-bagwell commented on July 4, 2024

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.

max-sixty avatar max-sixty commented on July 4, 2024

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.

max-sixty avatar max-sixty commented on July 4, 2024

Wonderful! I'll close...

from clio.

aj-bagwell avatar aj-bagwell commented on July 4, 2024

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.

max-sixty avatar max-sixty commented on July 4, 2024

Ah, that makes a lot of sense. Thanks for the explanation...

from clio.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.