Back to Dagger

Set Module Default

docs/current_docs/partials/cookbook/filesystems/_set-module-default.mdx

0.20.72.0 KB
Original Source

Set a module-wide default path

The following Dagger module uses a constructor to set a module-wide Directory argument and point it to a default path on the host. This eliminates the need to pass a common Directory argument individually to each Dagger Function in the module. If required, the default path can be overridden by specifying a different Directory value at call time.

<Tabs groupId="language" queryString="sdk"> <TabItem value="go" label="Go">
go
</TabItem> <TabItem value="python" label="Python">
python
</TabItem> <TabItem value="typescript" label="TypeScript">
typescript
</TabItem> <TabItem value="php" label="PHP">
php
</TabItem> </Tabs>

Examples

Call the Dagger Function without arguments. The default path (the current directory .) is used:

<Tabs groupId="shell">
<TabItem value="System shell">
```shell
dagger -c foo
```
</TabItem>
<TabItem value="Dagger Shell">
```shell title="First type 'dagger' for interactive mode."
foo
```
</TabItem>
<TabItem value="Dagger CLI">
```shell
dagger call foo
```
</TabItem>
</Tabs>

Call the Dagger Function with a constructor argument. The specified directory (/src/myapp) is used:

<Tabs groupId="shell">
<TabItem value="System shell">
```shell
dagger -c 'my-module --source $(host | directory /src/myapp) | foo'
```
</TabItem>
<TabItem value="Dagger Shell">
```shell title="First type 'dagger' for interactive mode."
my-module --source $(host | directory /src/myapp) | foo
```
</TabItem>
<TabItem value="Dagger CLI">
```shell
dagger call --source=/src/myapp foo
```
</TabItem>
</Tabs>