LD4P / sinopia_acl

node.js based code to interact with WebACL data on sinopia server
Apache License 2.0
0 stars 0 forks source link

Create CLI for managing ACLs #16

Closed mjgiarlo closed 5 years ago

mjgiarlo commented 5 years ago

Includes

Question

Due to the way commander is tested—using another process per a recipe found on Google—none of the coverage added in this branch is picked up by static analysis. :unamused: But it's there! We can handle this in one of three ways:

  1. Don't check src/cli/commander.js for code coverage. Possibly defensible, since we shouldn't need to test the commander library in sinopia_acl.
  2. Resign ourselves to the low overall coverage.
  3. Use a different strategy for testing our commander usage.

I lean towards 1, for expediency's sake.

Notes

Note 1: I chose to use commander for the CLI since it's both featureful and maintained unlike some of the other libraries mentioned in #4.

Note 2: I considered using npm run instead of bin/... for this, but so far I'm preferring the bin/... approach to distinguish it from the developer experience of running stuff with npm run.

Design

Here's how the CLI looks from the user perspective.

Print help if no commands or options provided:

$ bin/acl
Usage: acl [options] [command]

Options:
  -v, --version          output the version number
  -h, --help             output usage information

Commands:
  users <group>          List users and access controls in a group
  groups                 List all groups
  add <user> <group>     Add user to group
  remove <user> <group>  Remove user from group

Print help when requested (also works with -h):

bin/acl --help
Usage: acl [options] [command]

Options:
  -v, --version          output the version number
  -h, --help             output usage information

Commands:
  users <group>          List users and access controls in a group
  groups                 List all groups
  add <user> <group>     Add user to group
  remove <user> <group>  Remove user from group

Print version of acl tool (taken from package.json):

$ bin/acl -v
0.0.1

Show all groups:

$ bin/acl groups
not implemented yet

Throw an error when required argument is missing:

$ bin/acl users
error: missing required argument `group'

List all users in a group:

$ bin/acl users http://foo.bar
list() called with http://foo.bar
[ 'http://sinopia.io/users/cmharlow' ]

Add a user to a group:

$ bin/acl add userURI groupURI
adding userURI to groupURI
not implemented yet

Remove a user from a group:

$ bin/acl remove userURI groupURI
removing userURI to groupURI
not implemented yet

fixes #4

mjgiarlo commented 5 years ago

I agree with option 1. Feel free to merge it yourself or to deal with coverage using option 1 and then merge it.

I will do the latter. Pls hold off on merging.

mjgiarlo commented 5 years ago

Chatted with @ndushay about the most recent commit in this branch and she's OK with my merging this given her prior approval. Merging now.