Repository navigation
Description
I work a lot with OpenShift, and nushell is actually really handy for it. The oc get command outputs a space separated table which can be easily parsed by nushell by piping it into split-column " ". However, the original table's headers get parsed as the first row of the table. Naturally I can skip 1 and it works, but the resulting table doesn't have any headers.
Is there a way to make it parse the first line as headers when running the split-column command or is there a smarter way to do this? And if there isn't, is that something you'd want to put into the shell?
oc get pods raw output:
NAME READY STATUS RESTARTS AGE
<pod-name> 1/1 Running 0 2d
nushell 2.0 output. oc get pods | split-column " "
---+-----------------------------+---------+---------+----------+---------
# | Column1 | Column2 | Column3 | Column4 | Column5
---+-----------------------------+---------+---------+----------+---------
0 | NAME | READY | STATUS | RESTARTS | AGE
1 | <pod-name> | 1/1 | Running | 0 | 2d
It seems that the behavior changed in nushell 3.0, where split-column " " splits only on single spaces, creating a bunch of extra columns when there is more than one space in a row.
nushell 3.0 output. The ellipses in the first column indicate that the pod name is longer. oc get pods | split-column " "
━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━
# │ Column1 │ Column2 │ Column3 │ Column4 │ Column5 │ Column6 │ Column7 │ Column8 │ Column9 │ Column1 │ Column1 │ Column1 │ Column1 │ Column1 │ Column1 │ Column1 │ ...
│ │ │ │ │ │ │ │ │ │ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │
───┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────
0 │ NAME │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ...
1 │ pod-name│ │ │ │ │ │ │ 1/1 │ │ │ │ │ Running │ │ │ │ ...
│ ... │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ ... │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ -4-lch8 │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ c │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
Also, not my original point, but the 2.0 behavior of split-column seems more intuitive to me, though it might not be in certain cases.
Thanks!
Activity
sophiajt commentedon Oct 9, 2019
A few ideas:
split-columntakes an optional--collapse-empty(when we add aliases in the future, it should let you turn this into your default if you want). This should get you back to the 0.2 behavior.If those columns are tab separated, you could also run it through the
from-tsvcommand which will parse the first line as the headers.thomasheartman commentedon Oct 9, 2019
Right! If ‘collapse-empty’ makes it work like in 0.2, then that’s great! Thanks!
As for using ‘from-tsv’: the columns seem to use spaces in this case. I did try ‘from-tsv’ and it parses the headers, but it turns them into one column. Similarly the remaining rows seem to arbitrarily decide whether to split or not, but there’s never more than one column.
sophiajt commentedon Oct 9, 2019
Sounds good.
Makes me wonder if we want some kind of
from-ssv:)thomasheartman commentedon Oct 10, 2019
If you're open to that, I'd love to give it a little look later? I assume I could base it off the
from-tsvcommand and go from there.sophiajt commentedon Oct 10, 2019
Yup, sounds good
thomasheartman commentedon Oct 13, 2019
Hey! So I've implemented a
from-ssvfilter now and have written tests that mirror the ones forfrom-ssv(reading input and fetching expected values). They're passing and all is good, but when I try and build and run the project, the output I get from using the command is a blank table with one column namedvalue. That said, I can work on the table as if it had all the expected columns, so it seems to be there, just ... hidden.I suspect that I've either not wired it up correctly somewhere, or that I need to implement the
to-ssvcommand to see any output. Is this correct? Thanks :)sophiajt commentedon Oct 13, 2019
@t-hart that's great! I'm not quite sure what it might be. It's probably easier to read over the code.
Feel free to post a Draft PR here and we can take a look.
thomasheartman commentedon Oct 14, 2019
Ah, it was just me being careless. I'd forgotten to trim empty lines and an initial empty line had snuck into my input. I'll put some tests in for that and then get the PR open.
One thing, though: I've implemented the
headerlessoption similarly tofrom-tsv, but the behaviour is a bit unintuitive to me. I'd expectedheaderlessto mean that the first row of the input should be treated as data rather than column names, whereas with theheaderlessflag, it's just discarded. Is this the intended behavior?add the example results to the documentation pages (nushell#807)