Giter Site home page Giter Site logo

Comments (9)

philshafer avatar philshafer commented on June 27, 2024 1

I've been thinking about this and realized that with a little work, I can make a "csv" encoder that does what you need. Sort of. If I'm seeing what you need correctly.

So imagine:

  • a customer "csv" encoder
  • the ability to pass "options" to encoders
  • the csv encoder supports three options:
    • path=some/path/in/the/hierarchy (emit only content under this specific hierarchy)
    • leafs=some.leafs.that.you.want (emit only leafs "some", "leafs", "that", "you", and "want")
    • no-header (so avoid the normal CSV header)

With no explicit "path", it emits all "lists". With no explict "leafs", it emits the set of fields under the first instance of the first list. Without the no-header, it emits a list of leafs that it's emitting.

Using the example of tests/core/test-01.c:

% test_01.test --libxo warn,encoder=csv:path=top/data/item
sku,name,sold,in-stock,on-order
GRO-000-415,gum,1412,54,10
HRD-000-212,rope,85,4,2
HRD-000-517,ladder,0,2,1
HRD-000-632,bolt,4123,144,42
% test_01.test --libxo warn,encoder=csv:path=top/data/item+leafs=name.sold
name,sold
gum,1412
rope,85
ladder,0
bolt,4123
water,17

So add the "no-header" to strip the header and "leafs=xxx" and you can trim the content to what you need.

Does that sounds reasonable and usable?

Check out commit a8e2070 (and the one before that). To see where I'm at. It's mostly coded, but needs some finishing touches and documentation.

Thanks,
Phil

from libxo.

philshafer avatar philshafer commented on June 27, 2024

from libxo.

Jamie-Landeg-Jones avatar Jamie-Landeg-Jones commented on June 27, 2024

Apologies for the delay in replying.

That's brilliant - better than what I was hoping for (the ability to filter out leafs)

Hopefully this will get libxo added to more utilities - this is much better for shell scripts than parsing human orientated output!

I notice you've committed this to FreeBSD-Current. Are there plans to MFC to 12-stable?

Thanks again, Jamie

from libxo.

philshafer avatar philshafer commented on June 27, 2024

from libxo.

philshafer avatar philshafer commented on June 27, 2024

from libxo.

Jamie-Landeg-Jones avatar Jamie-Landeg-Jones commented on June 27, 2024

Ha! You must have been terrible as a kid leading up to Christmas, and presents!

As for freebsd, I'm on 12-stable, I just installed the latest from git (seeing as you'd released it by the time I got around to it). It installed in /usr/local/... and seems ok to me (df --libxo=encoders=csv works fine)

I used your install instructions - I did have to use "gmake" rather than "make" to get it to install though.

I couldn't get "xo" command line to work with the csv encoder, but I haven't really used that command before, so put that down to my own stupidity!

I am a bit puzzled by why it's --html/--xml/--json/--text/--encoder=csv and not --encoder=html/xml/json/text/csv but it's not important!

By the way, talking of Christmas, I don't want to be the guy who tells you that santa doesn't exist.... but apparently, the rail-gauge size is a myth! https://www.snopes.com/fact-check/railroad-gauge-chariots/

from libxo.

philshafer avatar philshafer commented on June 27, 2024

from libxo.

philshafer avatar philshafer commented on June 27, 2024

from libxo.

philshafer avatar philshafer commented on June 27, 2024

The functionality has been added to the current libxo release.

Thanks,
Phil

from libxo.

Related Issues (20)

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.