Path Enhancement Project #2: parse, join and split#3256
Path Enhancement Project #2: parse, join and split#3256sophiajt merged 27 commits intonushell:mainfrom
Conversation
a056e2a to
f9762bf
Compare
|
All the basic commands are now done. I made The output of There is one issue that needs to be solved: ❯ ls | first 2 | path expand name | get name | path split
0 [table 7 rows]
1 [table 7 rows]
❯ ls | first 2 | path expand name | path split name | get name
0 /
1 home
2 kubouch
3 git
4 forks
5 nushell
6 CODE_OF_CONDUCT.md
7 /
8 home
9 kubouch
10 git
11 forks
12 nushell
13 CONTRIBUTING.mdSeems like using column path somehow steps into the resulting table. Or the Still needs some polish: good error messages, example, tests, etc. |
|
I modified the
This should match better what a user would expect, IMO. The above applies when not operating by column path. Swapping table values by column path is still supported the same way as before. Here are some examples: So far, I like the result. It still needs some refactoring and there might still be some edge cases, but I would propose this functionality as final. |
db543ad to
960819d
Compare
This includes a slight refactor to all the path subcommand `action()` functions.
Structured path is implicitly joined at every patch subcommand call.
When the input is just a list of values, the `path split` command will split each value directly into the output stream, similar to `split-row`. Column path--specified values are still wrapped into a table so they can still be used to replace table fields.
When `path join` encounters a list of values, it attempts to join them,
instead of going one-by-one like the rest of the path commands. You can
still `each { echo $it | path join }` to join them one-by-one, if the
values are, e.g., tables.
Now, the behavior of `path split` and `path join` should match the
`split-row` and `str collect` counterparts and should hopefully align
better with user's expectations.
Also, doesn't collect input into vector unnecessarily.
* OsStr -> String encoding is now lossy, instead of throwing an error * The consequence is action() now always returns Value instead of Result * Removed redundant handle_value() call in `path join` * Fix possible incorrect error detection in `path split` * Applied rustfmt + clippy
The 'parent' column was required to be a path but didn't work with string.
Reducing code repetition
|
Lots of cool stuff in this one! |
First PR about representing paths as structured data. For more broad picture, motivation and examples, see #3219.
List of changes:
path parse: Splits a path into a table withparent,stemandextension. On Windows, there is an additionalprefixcolumn (see Rust's Prefix). On non-Windows, the prefix is always empty, so it's pointless to have the column.filestemandextensionsubcommands as these can be retrieved from the table.tar.gz) or ignore the extension (e.g.,conf.ddirectory)path joincommand to convert the path table back into a full path (i.e., reverse the effect ofpath parse)pathsubcommands to accept rows withparent,stemorextensioncolumns.path splitcommand that splits path by separatorTo fix:
Expected Tagged, found column path; solution:restarg needs to be always first)ls | path split name | get namevsls | get name | path split)path joinpanic when there is empty streamWe lose the following functionality:
path filestemAdditional TODO list:
Comments:
echo home/viking/spam.txt | path parse | update extension 0.9 | path join)/vs\in Windows tests (Windows seems to accept both\and/as a separator)