Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Improvement: Refactor to individual modules per command #6

Open
mrzarquon opened this issue Oct 15, 2021 · 1 comment
Open

Improvement: Refactor to individual modules per command #6

mrzarquon opened this issue Oct 15, 2021 · 1 comment

Comments

@mrzarquon
Copy link
Contributor

Per: https://typer.tiangolo.com/tutorial/commands/context/

The POC phase left this codebase with all the logic inside the single cli.py file, as the features grow this should be broken up into individual modules for each command.

The main changes would be:
Move the remove the global data (watchlist / s) and replace with using contexts.
Instead of referencing this common data, just store and pass the arguments (or the parsed data?) as a context obj, which all the downstream modules would get. IE:

file: main.py

import typer
import subcommand

app.add_typer(subcommand.app, name="subcommand")

@app.callback(invoke_without_command=True)
def main(ctx: typer.Context, otherinput....):
  ctx.obj = parse(otherinput)

Then the subcommand, which only has one command itself:

file: subcommand.py
@app.callback(invoke_without_command=True)
def generate( ctx: typer.Context)
  parsed_configuration_from_main = ctx.obj

This doesn't make the subcommand stand alone, but would allow main.py --foo=bar subcommand to access foo in subcommand.py easily enough.

@mrzarquon
Copy link
Contributor Author

Models were split apart here: #14

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant