docs/versioned_docs/version-0.16.3/api/enumerations.mdx
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
:::important The information on this page is only applicable to Go, Python and TypeScript SDKs. Enumerations are not currently supported in the PHP SDK. :::
Dagger supports custom enumeration (enum) types, which can be used to restrict possible values for a string argument. Enum values are strictly validated, preventing common mistakes like accidentally passing null, true, or false.
:::note Following the GraphQL specification, enums are represented as strings in the Dagger API GraphQL schema and follow these rules:
_.Here is an example of a Dagger Function that takes two arguments: an image reference and a severity filter. The latter is defined as an enum named Severity:
:::note
dagger.Enum is a convenience base class for defining documentation, but you can also use enum.Enum directly.
:::
</TabItem>
Enumeration choices will be displayed when calling --help on a Dagger Function:
dagger call scan --help
The result will be:
USAGE
dagger call scan [arguments]
ARGUMENTS
--ref string [required]
--severity UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL [required]
Here's an example of calling the Dagger Function with an invalid enum argument:
dagger call scan --ref=hello-world:latest --severity=FOO
This will result in an error that displays possible values, as follows:
Error: invalid argument "FOO" for "--severity" flag: value should be one of UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
Run 'dagger call scan --help' for usage.