Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter validation #662

Open
joe307bad opened this issue Nov 7, 2019 · 1 comment
Open

Parameter validation #662

joe307bad opened this issue Nov 7, 2019 · 1 comment
Labels
enhancement planned We intend to add this feature or refactor in the future.

Comments

@joe307bad
Copy link

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!

@jamonholmgren
Copy link
Member

Hey @joe307bad, I appreciate you asking! This has been a somewhat common feature request and we don't have anything built-in. There is this PR (#464) which has some context. Check that and see what you might be willing to work on!

@jamonholmgren jamonholmgren added planned We intend to add this feature or refactor in the future. enhancement labels Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement planned We intend to add this feature or refactor in the future.
Projects
None yet
Development

No branches or pull requests

2 participants