-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add multi-lang name overrides page
Signed-off-by: Vikram Vaswani <vikram@dagger.io>
- Loading branch information
1 parent
51b4f2a
commit 43aac09
Showing
8 changed files
with
116 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--- | ||
slug: /manuals/developer/name-overrides | ||
displayed_sidebar: "current" | ||
toc_max_heading_level: 2 | ||
title: "Name Overrides" | ||
--- | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
# Name Overrides | ||
|
||
:::important | ||
The information on this page is only applicable to the Python and TypeScript SDKs. Name overrides are not currently supported in the Go SDK. | ||
::: | ||
|
||
You can change the name of an exposed field or function to work around a reserved keyword or some other naming conflict, but still be able to expose the desired name in the Dagger API. For example, using `import_` in the language, but `import` in the Dagger API. | ||
|
||
<Tabs groupId="language"> | ||
<TabItem value="Python"> | ||
|
||
The [`@dagger.function`][@function] decorator and the | ||
[`dagger.field`][dag-field] descriptor have a `name` argument to provide | ||
an alternative name for the Dagger API. And for function arguments, | ||
[annotate][Annotated] with an additional [`dagger.Arg`][dag-arg] metadata. | ||
|
||
Here's an example with a renamed object attribute (and constructor argument), | ||
function and function argument: | ||
|
||
```python file=./snippets/name-overrides/main.py | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="TypeScript"> | ||
|
||
Add the name override (alias) as a parameter of the corresponding `@field()` or `@func()` decorators | ||
|
||
Here's an example with a renamed object attribute (and constructor argument), | ||
function and function argument: | ||
|
||
```typescript file=./snippets/name-overrides/typescript/index.ts | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
Confirm with `dagger call --help` that the names were overridden: | ||
|
||
``` | ||
FUNCTIONS | ||
def Definition | ||
import Import the specified image | ||
ARGUMENTS | ||
--def string Definition (default "latest") | ||
``` | ||
|
||
Confirm the same for the function argument, with `dagger call import --help`: | ||
|
||
``` | ||
ARGUMENTS | ||
--from string Image ref (default "alpine") | ||
``` | ||
|
||
[@function]: https://dagger-io.readthedocs.io/en/latest/module.html#dagger.function | ||
[dag-field]: https://dagger-io.readthedocs.io/en/latest/module.html#dagger.field | ||
[dag-arg]: https://dagger-io.readthedocs.io/en/latest/module.html#dagger.Arg | ||
[Annotated]: https://docs.python.org/3/library/typing.html#typing.Annotated |
47 changes: 0 additions & 47 deletions
47
docs/current_docs/manuals/developer/python/558732-name-overrides.mdx
This file was deleted.
Oops, something went wrong.
File renamed without changes.
33 changes: 33 additions & 0 deletions
33
docs/current_docs/manuals/developer/snippets/name-overrides/typescript/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { dag, Container, object, func, field } from "@dagger.io/dagger" | ||
|
||
@object() | ||
class MyModule { | ||
/** | ||
* Definition | ||
*/ | ||
@field("def") | ||
def_: string | ||
|
||
constructor( | ||
/** | ||
* Definition | ||
*/ | ||
def_: string = "latest" | ||
) { | ||
this.def_ = def_ | ||
} | ||
|
||
/** | ||
* Import the specified image | ||
*/ | ||
@func("import") | ||
import_( | ||
/** | ||
* Image ref | ||
*/ | ||
@field("from") | ||
from_: string = "alpine" | ||
): Container { | ||
return dag.container().withLabel("definition", this.def_).from(from_) | ||
} | ||
} |
26 changes: 0 additions & 26 deletions
26
docs/current_docs/manuals/developer/typescript/406314-aliases.mdx
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
docs/current_docs/manuals/developer/typescript/snippets/aliases/index.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters