Hey there, I am building a CLI tool with Gluegun and I was wondering if there is any best practice around validating parameters. Right now I am implementing something like this:
export const enum VALIDATOR {
string = 0,
required = 1
}
export type TCommandValidators = { [key: string]: [string, VALIDATOR[]][] }
const deployCommandValidators: TCommandValidators =
{
arguments: [
[
'filePath',
[
VALIDATOR.string,
VALIDATOR.required
]
]
]
};
const deploy: GluegunCommand = {
name: 'deploy',
alias: 'd',
run: toolbox => validator(
deployCommandValidators,
toolbox
)((toolbox: Toolbox) => {
const {print} = toolbox;
const {filePath, fileName} = toolbox.parameters.options;
new CdnDeploy()
.upload(filePath, fileName)
.then(response => print.info(response[1]))
.catch(error => print.error(error));
})
};
And validator is a function that loops through the given validators and produces a collection of errors to display to the user.
Questions:
- Should I build an extension for this?
- Is there any built in parameter validation for Gluegun?
Thanks! I love the project!
Hey there, I am building a CLI tool with Gluegun and I was wondering if there is any best practice around validating parameters. Right now I am implementing something like this:
And
validatoris a function that loops through the givenvalidatorsand produces a collection of errors to display to the user.Questions:
Thanks! I love the project!