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