-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kvs: add flux kvs ls subcommand #1172
Conversation
Restarted three tests; two write errors, one hydra test failure (can't really be related). |
Codecov Report
@@ Coverage Diff @@
## master #1172 +/- ##
==========================================
+ Coverage 77.64% 77.73% +0.09%
==========================================
Files 158 158
Lines 29088 29265 +177
==========================================
+ Hits 22586 22750 +164
- Misses 6502 6515 +13
|
Rebased after merge of #1171 |
src/cmd/flux-kvs.c
Outdated
* if -C, or 1 if not. | ||
* N.B. A width of 0 means "unlimited", while a width of 1 effectively | ||
* forces one entry per line since entries are never broken across lines. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To match ls
should get_window_width()
also check COLUMNS
env var? From GNU ls(1)
:
‘-w cols’
‘--width=cols’
Assume the screen is cols columns wide. The default is taken from the terminal settings if possible; otherwise the environment variable COLUMNS is used if it is set; otherwise the default is 80. With a cols value of ‘0’, there is no limit on the length of the output line, and that single output line will be delimited with spaces, not tabs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I did not read that carefully in the ls(1) page. Will fix.
I know the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't checked out code and played with it yet, but just a few nits I saw.
src/cmd/flux-kvs.c
Outdated
@@ -116,6 +143,13 @@ static struct optparse_subcommand subcommands[] = { | |||
0, | |||
dir_opts | |||
}, | |||
{ "ls", | |||
"[-R] [-d] [-w COLS] [-1] [-W] [-C] [key...]", | |||
"List directory", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the -W
iss probably supposed to be -F
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, thanks.
src/cmd/flux-kvs.c
Outdated
@@ -116,6 +143,13 @@ static struct optparse_subcommand subcommands[] = { | |||
0, | |||
dir_opts | |||
}, | |||
{ "ls", | |||
"[-R] [-d] [-w COLS] [-1] [-W] [-C] [key...]", | |||
"List directory", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also noticed the manpage is [-R] [-d] [-C] [-1|-C] [-w COLS] [-F]
, should this match up together (most notably [-1|-C]
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed.
src/cmd/flux-kvs.c
Outdated
|
||
/* List keys, arranging in columns so that they fit within 'win_width', | ||
* and using a custom column width selected based on the longest entry name. | ||
* The keys are popped off the list and freed we go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
freed we go
, just "freed"? Or had another thought but didn't finish?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freed as we go, but I'll go with "freed".
I may have misrepresented the way columns are selected by ls(1), and thought -C was needed to get columns when output is not a tty. I think we could just drop it actually. |
Ah, ok that is what I figured. I see you already removed it, but I would have been fine with keeping |
One missing --- a/src/cmd/flux-kvs.c
+++ b/src/cmd/flux-kvs.c
@@ -976,6 +976,7 @@ static void list_kvs_dir (flux_t *h, const char *key, optpar
free (nkey);
}
}
+ kvsitr_destroy (itr);
kvsdir_destroy (dir);
}
done: |
I did poke at this and it seemed to work great! One thing I did notice is that |
Hmm, yeah, ls(1) allows Good catch on the |
One catch will be that Nice work, |
I noticed this a long time ago and just accepted it as the way flux kvs worked, but it does seem like it should be supported. The behavior should also be in
Presumably, the error should be identical. This could be a different issue and maybe we should just open a issue on it. In fact, the solution may have to come inside the flux kvs module as that is what is returning some of these error codes. |
I'm fine with fixing this holistically in another PR |
Good point @chu11 - want to open that issue? |
One thing I noticed when messing with this branch
Do we want entries sorted before it is output? Because |
We could just use the Sounds like a good idea. |
src/cmd/flux-kvs.c
Outdated
bool require_directory = false; | ||
|
||
if (!(nkey = malloc (strlen (key) + 2))) // room for deocration char + null | ||
log_err_exit ("malloc"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo, "decoration" :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops :-/
Output is sorted now. Shall I squash this down or is it still useful for review purposes to see the incremental work? |
I think it's ok to squash now. One nit, the |
Heading out for a bit so having addressed the recent travis failures, I'm going to go ahead and squash. |
t/t1000-kvs.t
Outdated
test_expect_success 'kvs: ls key. fails if key is not a directory' ' | ||
flux kvs unlink -Rf $DIR && | ||
flux kvs put $DIR.a=42 && | ||
! flux kvs ls -d $DIR.a. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a general comment, no reason to fix it here and now
Instead of ! command
to indicate expected (required) failure, it might be more correct to use either test_must_fail
or test_expect_code
. See sharness docs here
I'll go ahead and address the unnecessary sort and the use of |
Thanks, LGTM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with only 1 nit on a unit test for bad input on kvsitr_create()
.
|
||
if (!dir) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a unit test for NULL input to kvsitr_create()
now that it's checking for NULL input?
if (itr->iter) { | ||
name = json_object_iter_key (itr->iter); | ||
itr->iter = json_object_iter_next (itr->dirdata, itr->iter); | ||
if (itr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possibly a unit test for bad input here as well? although it might not be necessary coverage wise for this one.
Sure, I'll do that. |
Change the kvsitr_t implementation to create a list of keys from the directory object and sort it, then access the list in order.
Add new subcommand: flux kvs ls [-R] [-d] [-w COLS] [-1|-C] [-F] [key...] This subcommand mimics ls(1) behavior and options, as discussed in flux-framework#1158.
I added the tests you suggested to the commit that modified the |
LGTM, if no complaints will hit button. |
This adds a
flux kvs ls
subcommand that behaves similar to ls(1), as discussed in #1158.