feat: add enums to args (#45)

This commit is contained in:
Jeroen Op 't Eynde 2023-02-16 19:57:15 +01:00 committed by GitHub
parent 5e45c19fbe
commit cf4ff4b950
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 8 deletions

View file

@ -119,11 +119,30 @@
'#argument': d.obj('Utilities for creating function arguments'),
argument:: {
'#new': d.fn('new creates a new function argument, taking the name, the type and optionally a default value', [d.arg('name', d.T.string), d.arg('type', d.T.string), d.arg('default', d.T.any)]),
new(name, type, default=null): {
'#new': d.fn(|||
`new` creates a new function argument, taking the `name`, the `type`. Optionally it
can take a `default` value and `enum`-erate potential values.
Examples:
```jsonnet
[
d.argument.new('foo', d.T.string),
d.argument.new('bar', d.T.string, default='loo'),
d.argument.new('baz', d.T.number, enums=[1,2,3]),
]
```
|||, [
d.arg('name', d.T.string),
d.arg('type', d.T.string),
d.arg('default', d.T.any),
d.arg('enums', d.T.array),
]),
new(name, type, default=null, enums=null): {
name: name,
type: type,
default: default,
enums: enums,
},
},
'#arg': self.argument['#new'] + self.func.withHelp('`arg` is a shorthand for `argument.new`'),