docs/current_docs/extending/modules/enumerations.mdx
:::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>
:::note
Please note the @Enum annotation that is required for Dagger to recognize the enum.
:::
Enumeration choices will be displayed when calling --help or .help on a Dagger Function:
The result will be:
<Tabs groupId="shell"> <TabItem value="System shell"> ```shell USAGE scan <ref> <severity>REQUIRED ARGUMENTS ref string severity MyModuleSeverity (possible values: UNKNOWN, LOW, MEDIUM, HIGH, CRITICAL)
RETURNS string - Primitive type.
</TabItem>
<TabItem value="Dagger Shell">
```shell
USAGE
scan <ref> <severity>
REQUIRED ARGUMENTS
ref string
severity MyModuleSeverity (possible values: UNKNOWN, LOW, MEDIUM, HIGH, CRITICAL)
RETURNS
string - Primitive type.
ARGUMENTS --ref string [required] --severity UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL [required]
</TabItem>
</Tabs>
Here's an example of calling the Dagger Function with an invalid enum argument:
<Tabs groupId="shell">
<TabItem value="System shell">
```shell
dagger -c 'scan hello-world:latest FOO'
This will result in an error that displays possible values, as follows:
<Tabs groupId="shell"> <TabItem value="System shell"> ```shell ! function "scan": invalid argument "FOO" for "--severity" flag: value should be one of UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL ! Usage: scan <ref> <severity> ``` </TabItem> <TabItem value="Dagger Shell"> ```shell ! function "scan": invalid argument "FOO" for "--severity" flag: value should be one of UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL ! Usage: scan <ref> <severity> ``` </TabItem> <TabItem value="Dagger CLI"> ```shell Error: invalid argument "FOO" for "--severity" flag: value should be one of UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL Run 'dagger call scan --help' for usage. ``` </TabItem> </Tabs>