-
Notifications
You must be signed in to change notification settings - Fork 7.3k
ZOOKEEPER-4988: Add [-R] recursive option to getAcl cli command #2334
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,10 +38,11 @@ public class GetAclCommand extends CliCommand { | |
|
|
||
| static { | ||
| options.addOption("s", false, "stats"); | ||
| options.addOption("R", false, "recursive"); | ||
| } | ||
|
|
||
| public GetAclCommand() { | ||
| super("getAcl", "[-s] path"); | ||
| super("getAcl", "[-s] [-R] path"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think commons-cli, which it looks like ZK is using, can generate help documentation automatically. It shouldn't be necessary to maintain a description that is passed around. But, that's out of scope of this PR. I was just surprised to see a help document being manually updated in this PR. |
||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -65,21 +66,37 @@ public boolean exec() throws CliException { | |
| String path = args[1]; | ||
| Stat stat = new Stat(); | ||
| List<ACL> acl; | ||
| boolean recursive = cl.hasOption("R"); | ||
| try { | ||
| acl = zk.getACL(path, stat); | ||
| if (recursive) { | ||
| ZKUtil.visitSubTreeDFS(zk, path, false, (rc, path1, ctx, name) -> { | ||
| try { | ||
| out.println(path1); | ||
| printAcl(zk.getACL(path1, stat), stat); | ||
|
Comment on lines
+74
to
+75
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than print on separate lines, it would be better if these were formatted such that they could be on one line, so the output can be more easily parsed by somebody redirecting this elsewhere. Could the path be appended with something like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense to me, let me take a look. |
||
| } catch (KeeperException | InterruptedException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| }); | ||
| } else { | ||
| acl = zk.getACL(path, stat); | ||
| printAcl(acl, stat); | ||
| } | ||
| } catch (IllegalArgumentException ex) { | ||
| throw new MalformedPathException(ex.getMessage()); | ||
| } catch (KeeperException | InterruptedException ex) { | ||
| throw new CliWrapperException(ex); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private void printAcl(List<ACL> acl, Stat stat) { | ||
| for (ACL a : acl) { | ||
| out.println(a.getId() + ": " + ZKUtil.getPermString(a.getPerms())); | ||
| } | ||
|
|
||
| if (cl.hasOption("s")) { | ||
| new StatPrinter(out).print(stat); | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
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.
Why upper-case? Was lower-case already used? I guess it doesn't matter, but I'm curious.
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 be consistent with SetAclCommand