Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ public class GetAclCommand extends CliCommand {

static {
options.addOption("s", false, "stats");
options.addOption("R", false, "recursive");
Copy link
Member

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.

Copy link
Contributor Author

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

}

public GetAclCommand() {
super("getAcl", "[-s] path");
super("getAcl", "[-s] [-R] path");
Copy link
Member

Choose a reason for hiding this comment

The 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
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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 # /path/to/node?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}
}