nickthecook / ops

The operations team for your project.
GNU General Public License v3.0
50 stars 1 forks source link

Add argument checking #15

Closed nickthecook closed 4 years ago

nickthecook commented 4 years ago

ops can be used to run scripts, e.g. in a bin/ directory, passing command-line arguments to the script. It would be useful if ops could also perform some checks on arguments.

The minimum check would be checking number of arguments. It could also perform some validation of the argument values.

With the action definition

actions:
  hello:
    command: echo "Hello, "
    arguments:
      name:
        optional: false
        description: says 'hello' to the given name

, ops could infer that the required number of arguments is one. ops hello would print:

ops: Usage: hello <name>

says 'hello' to the given name

and exit with the existing syntax error status code.

ops help hello could print the same message, but exit with 0.

actions:
  copy:
    command: scp -i key/id_rsa
    arguments:
      sources:
        optional: false
        multiple: true
        description: a list of locations to copy files from; must be all local paths or all remote paths
      destination:
        optional: false
        description: the location to which to copy files; can be a local or remote file

From this action definition, ops copy file host: would execute the command. ops copy file1 file2 host would execute the command. ops copy or ops help copy would print:

ops: Usage: copy <sources> <destination>

sources: a list of locations to copy files from; must be all local paths or all remote paths
desintations: the location to which to copy files; can be a local or remote file

Should more than one multiple: true argument be allowed? Can ops perform syntax checking in this case? Does this add too much complexity for the value it delivers? ops will be less of a pleasure to use if users feel that because this feature exists they must now document parameters. It does, however, help users document the scripts they use in their project. Does it make sense for ops to do this? Scripts can be called outside of ops, and ops should never assume otherwise. Argument checking would be better in the script itself.

nickthecook commented 4 years ago

Since scripts can be called directly, bypassing ops, argument-checking should be done in the script.