Skip to content

subparsers with configuration file #347

Closed Answered by anoduck
anoduck asked this question in Q&A
Discussion options

You must be logged in to vote

AND, I worked it out, finally. Dataclass Program was missing the execute function, and then all execute functions for dataclasses needed both 'args' (prog & cfg) passed back to them. So, in short, the last block looked something like this.

@dataclass
class Program:
	command: Union[Whisper, Belch, TomlConfig]
	tofile: bool = False  # Should the phrase be written to file.
	txtfile: Path = Path('somefile.txt')  # File to write phrase to.

    def execute(self, prog, cfg):
        return self.command.execute(prog, cfg)


def main(args=None) -> None:
    ap = ArgumentParser(
        add_config_path_arg=True, config_path="belch.toml"
    )
    ap.add_arguments(Program, dest='prog')
    ap.add_a…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@lebrice
Comment options

@anoduck
Comment options

@anoduck
Comment options

Answer selected by lebrice
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