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

Add number type to options for input validation purposes #3

Closed
jacobdeichert opened this issue Jul 12, 2019 · 2 comments · Fixed by #35
Closed

Add number type to options for input validation purposes #3

jacobdeichert opened this issue Jul 12, 2019 · 2 comments · Fixed by #35
Labels
enhancement New feature or request

Comments

@jacobdeichert
Copy link
Owner

The port option below has type: number which would allow us to validate the input is correct.

Note that even though we can at least validate it, it still gets turned into an environment variable which is just a string. The benefit here is that the script can assume it's always a number and cast it as such.

## serve

**OPTIONS:**
* port
    * flags: -p --port
    * type: number
    * desc: Which port to serve on

~~~node
const port = Number(process.env.port);
console.log(port * 2)
~~~
@jacobdeichert jacobdeichert added the enhancement New feature or request label Jul 12, 2019
@lidongjies
Copy link

Can type be a URL or a regular expression?

@jacobdeichert
Copy link
Owner Author

We can definitely add other types for validation purposes. type: number would validate the input is a number... so type: url could validate the input is a correctly formatted url and type: path could also be handy.

Allowing type: /^some_regex$/ could be powerful but might be overkill if we can get away with mostly high-level types 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants