shell icon indicating copy to clipboard operation
shell copied to clipboard

Flag/Argument Transformations

Open coreybutler opened this issue 5 years ago • 0 comments

I want a transformer to process arguments/flags passed to the CLI utility. For example:

my cmd -i ./local/path
flags: {
  input: {
    alias: 'i',
    description: 'The input source directory.',
    type: 'string',
    transform (value) {
      return path.resolve(value)
    }
  }
}

In the case above, the resulting "input" flag would have a value of /users/cbutler/local/path instead of ./local/path because the transformer modifies the data before it is used within a command.

This could be used for sanitizing inputs of any kind, or normalizing data (such as case sensitivity, typos, etc). It would be better to do this where the flag is defined, instead of requiring each and every command handler to do this. Currently, middleware is the only way to handle this, but that's less intuitive than a transformer.

coreybutler avatar Oct 21 '20 17:10 coreybutler