refactor: refactor cmd execution
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from . import pofile, render
|
||||
from .cli import parse, RcOpts, RcPotOpts, RcRenderOpts
|
||||
from .manifest import load_manifest
|
||||
from .cli import parse
|
||||
from .cmds import run
|
||||
|
||||
|
||||
def main() -> None:
|
||||
@@ -11,23 +9,7 @@ def main() -> None:
|
||||
opts = parse()
|
||||
|
||||
try:
|
||||
match opts.opts:
|
||||
case RcOpts() as rc_opts:
|
||||
match rc_opts.opts:
|
||||
case RcPotOpts() as rc_pot_opts:
|
||||
manifest = load_manifest(rc_pot_opts.in_manifest)
|
||||
pofile.generate_pot(manifest, rc_pot_opts.out_pot)
|
||||
case RcRenderOpts() as rc_rdr_opts:
|
||||
render.render(
|
||||
rc_rdr_opts.in_manifest,
|
||||
rc_rdr_opts.in_po,
|
||||
rc_rdr_opts.in_template,
|
||||
rc_rdr_opts.out_rc,
|
||||
)
|
||||
case _:
|
||||
raise RuntimeError(f"unhandled rc options: {rc_opts.opts!r}")
|
||||
case _:
|
||||
raise RuntimeError(f"unhandled options: {opts.opts!r}")
|
||||
run(opts)
|
||||
except Exception as e:
|
||||
logging.fatal("Runtime error: %s", e, exc_info=True)
|
||||
sys.exit(1)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
from ..cli import Opts, RcOpts
|
||||
from . import rc
|
||||
|
||||
def run(opts: Opts) -> None:
|
||||
match opts.opts:
|
||||
case RcOpts() as rc_opts:
|
||||
rc.run(rc_opts)
|
||||
case _:
|
||||
raise RuntimeError(f"unhandled options: {opts.opts!r}")
|
||||
@@ -0,0 +1,12 @@
|
||||
from ...cli import RcOpts, RcPotOpts, RcRenderOpts
|
||||
from . import pot, render
|
||||
|
||||
def run(opts: RcOpts) -> None:
|
||||
match opts.opts:
|
||||
case RcPotOpts() as pot_opts:
|
||||
pot.run(pot_opts)
|
||||
case RcRenderOpts() as render_opts:
|
||||
render.run(render_opts)
|
||||
case _:
|
||||
raise RuntimeError(f"unhandled rc options: {opts.opts!r}")
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
from ...cli import RcPotOpts
|
||||
from ...manifest import load_manifest
|
||||
from ...pofile import generate_pot
|
||||
|
||||
def run(opts: RcPotOpts) -> None:
|
||||
manifest = load_manifest(opts.in_manifest)
|
||||
generate_pot(manifest, opts.out_pot)
|
||||
@@ -0,0 +1,11 @@
|
||||
from ...cli import RcRenderOpts
|
||||
from ...render import render
|
||||
|
||||
|
||||
def run(opts: RcRenderOpts) -> None:
|
||||
render(
|
||||
opts.in_manifest,
|
||||
opts.in_po,
|
||||
opts.in_template,
|
||||
opts.out_rc,
|
||||
)
|
||||
Reference in New Issue
Block a user