Skip to content

Shared args #159

Answered by DanCardin
Tobi-De asked this question in Q&A
Oct 24, 2024 · 1 comments · 7 replies
Discussion options

You must be logged in to vote

I assume the primary_host is not a static/env var? (if so, it could be a default on the cappa class itself)

So the super().__call__(host) would need to be in the Exec impl in order to work properly, as written. at which point it seems to yield the behavior i'd think you would expect.

I would probably personally write it like this:

from dataclasses import dataclass
from functools import cache
from typing import Annotated, ClassVar
import cappa

@dataclass(frozen=True)
class Config:
    primary_host = "primary"
    hosts: ClassVar = {"foo": "foo"}


ConfigDep = Annotated[Config, cappa.Dep(Config)]


@dataclass(frozen=True)
class BaseCommand:
    _host: Annotated[str | None, cappa.Arg(long="…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@DanCardin
Comment options

@Tobi-De
Comment options

@DanCardin
Comment options

@Tobi-De
Comment options

@DanCardin
Comment options

Answer selected by Tobi-De
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants