Migrate commands to use 'typer' framework
This commit is contained in:
parent
f18e0d3c3c
commit
2b2703ea4e
|
@ -27,6 +27,7 @@ install_requires =
|
|||
flet
|
||||
psycopg2
|
||||
rattail[db]
|
||||
typer
|
||||
|
||||
packages = find:
|
||||
include_package_data = True
|
||||
|
@ -36,12 +37,7 @@ include_package_data = True
|
|||
[options.entry_points]
|
||||
|
||||
console_scripts =
|
||||
wuttapos = wuttapos.commands:main
|
||||
wuttapos = wuttapos.commands:wuttapos_typer
|
||||
|
||||
rattail.config.extensions =
|
||||
wuttapos = wuttapos.config:WuttaConfigExtension
|
||||
|
||||
wuttapos.subcommands =
|
||||
open = wuttapos.commands:Open
|
||||
serve = wuttapos.commands:Serve
|
||||
status = wuttapos.commands:Status
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# WuttaPOS -- Pythonic Point of Sale System
|
||||
# Copyright © 2023 Lance Edgar
|
||||
# Copyright © 2023-2024 Lance Edgar
|
||||
#
|
||||
# This file is part of WuttaPOS.
|
||||
#
|
||||
|
@ -25,73 +25,59 @@ WuttaPOS commands
|
|||
"""
|
||||
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from rattail import commands
|
||||
import typer
|
||||
|
||||
from rattail.files import resource_path
|
||||
|
||||
from wuttapos import __version__
|
||||
from rattail.commands.typer import typer_callback
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def main(*args):
|
||||
"""
|
||||
Main entry point for WuttaPOS command system
|
||||
"""
|
||||
args = list(args or sys.argv[1:])
|
||||
cmd = Command()
|
||||
cmd.run(*args)
|
||||
wuttapos_typer = typer.Typer(
|
||||
callback=typer_callback,
|
||||
help="WuttaPOS (point of sale)"
|
||||
)
|
||||
|
||||
|
||||
class Command(commands.Command):
|
||||
"""
|
||||
Top-level command for WuttaPOS
|
||||
"""
|
||||
name = 'wuttapos'
|
||||
version = __version__
|
||||
description = "WuttaPOS (point of sale)"
|
||||
long_description = ''
|
||||
|
||||
|
||||
class Open(commands.Subcommand):
|
||||
@wuttapos_typer.command('open')
|
||||
def typer_open(
|
||||
ctx: typer.Context,
|
||||
):
|
||||
"""
|
||||
Open the Point of Sale app
|
||||
"""
|
||||
name = 'open'
|
||||
description = __doc__.strip()
|
||||
|
||||
def run(self, args):
|
||||
from wuttapos.app import run_app
|
||||
|
||||
run_app(self.config)
|
||||
config = ctx.parent.rattail_config
|
||||
run_app(config)
|
||||
|
||||
|
||||
class Serve(commands.Subcommand):
|
||||
@wuttapos_typer.command()
|
||||
def serve(
|
||||
ctx: typer.Context,
|
||||
):
|
||||
"""
|
||||
Run the POS app as a web service
|
||||
"""
|
||||
name = 'serve'
|
||||
description = __doc__.strip()
|
||||
|
||||
def run(self, args):
|
||||
import flet as ft
|
||||
from wuttapos.app import main
|
||||
|
||||
config = ctx.parent.rattail_config
|
||||
kw = {}
|
||||
|
||||
host = self.config.get('wuttapos', 'serve.host',
|
||||
host = config.get('wuttapos', 'serve.host',
|
||||
default='0.0.0.0')
|
||||
kw['host'] = host
|
||||
|
||||
port = self.config.getint('wuttapos', 'serve.port',
|
||||
port = config.getint('wuttapos', 'serve.port',
|
||||
default=8332)
|
||||
kw['port'] = port
|
||||
|
||||
# TODO: we technically "support" this, in that we do pass the
|
||||
# value on to Flet, but in practice it does not work right
|
||||
path = self.config.get('wuttapos', 'serve.path', default='')
|
||||
path = config.get('wuttapos', 'serve.path', default='')
|
||||
if path:
|
||||
path = path.strip('/') + '/'
|
||||
kw['name'] = path
|
||||
|
@ -103,12 +89,11 @@ class Serve(commands.Subcommand):
|
|||
**kw)
|
||||
|
||||
|
||||
class Status(commands.Subcommand):
|
||||
@wuttapos_typer.command()
|
||||
def status(
|
||||
ctx: typer.Context,
|
||||
):
|
||||
"""
|
||||
Show status of the POS lane
|
||||
"""
|
||||
name = 'status'
|
||||
description = __doc__.strip()
|
||||
|
||||
def run(self, args):
|
||||
print("TODO: show status")
|
||||
|
|
Loading…
Reference in a new issue