Comments (9)
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.
from libxo.
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.
from libxo.
from libxo.
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.
from libxo.
from libxo.
The functionality has been added to the current libxo release.
Thanks,
Phil
from libxo.
Related Issues (20)
- Document "xo"'s --not-first option HOT 1
- "xo" need option to make JSON object wrapper HOT 1
- "xo" needs a means of handling lists and instances HOT 1
- Newline before closing brace in json output HOT 2
- libtool makes unreliable executable names HOT 1
- 1.3.1 Ubuntu 18.04 WSL missing so HOT 3
- typo HOT 2
- Fails to build with GCC on FreeBSD HOT 2
- check width of unicode characters
- FreeBSD's json format prints an unescaped new line before the final closing bracket HOT 2
- No man page for xo_emit_field() HOT 6
- Man pages not escaping some newlines (PR included) HOT 1
- XOF_UNDERSCORES: hyphens in topmost keys are not replaced HOT 2
- xo/xo.c#L99: add missing UNUSED marker for all unused flags HOT 2
- libxo inconsistent field truncation HOT 3
- Linux: <sys/sysctl.h> missing HOT 2
- Core dump when compile with gcc 10 HOT 3
- xo.h defines NORETURN and PRINTFLIKE without a "XO_" prefix
- adding keys test_05 changes padding output for HIPx HOT 2
- Incorrect usage of an internal Glibc header (sys/cdefs.h)
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 libxo.