-
Notifications
You must be signed in to change notification settings - Fork 570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Add multi-lang name overrides page #7429
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
This file was deleted.
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes because in one case, def_ is a field, in the other he's an argument of the constructor. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I still didn't understand this. Are the TypeScript and Python snippets equivalent?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
*/ | ||
@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_) | ||
} | ||
} |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomChv please review this code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👆 @TomChv