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,73 +25,59 @@ 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'
|
|
||||||
description = __doc__.strip()
|
|
||||||
|
|
||||||
def run(self, args):
|
|
||||||
from wuttapos.app import run_app
|
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
|
Run the POS app as a web service
|
||||||
"""
|
"""
|
||||||
name = 'serve'
|
|
||||||
description = __doc__.strip()
|
|
||||||
|
|
||||||
def run(self, args):
|
|
||||||
import flet as ft
|
import flet as ft
|
||||||
from wuttapos.app import main
|
from wuttapos.app import main
|
||||||
|
|
||||||
|
config = ctx.parent.rattail_config
|
||||||
kw = {}
|
kw = {}
|
||||||
|
|
||||||
host = self.config.get('wuttapos', 'serve.host',
|
host = config.get('wuttapos', 'serve.host',
|
||||||
default='0.0.0.0')
|
default='0.0.0.0')
|
||||||
kw['host'] = host
|
kw['host'] = host
|
||||||
|
|
||||||
port = self.config.getint('wuttapos', 'serve.port',
|
port = config.getint('wuttapos', 'serve.port',
|
||||||
default=8332)
|
default=8332)
|
||||||
kw['port'] = port
|
kw['port'] = port
|
||||||
|
|
||||||
# TODO: we technically "support" this, in that we do pass the
|
# TODO: we technically "support" this, in that we do pass the
|
||||||
# value on to Flet, but in practice it does not work right
|
# 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:
|
if path:
|
||||||
path = path.strip('/') + '/'
|
path = path.strip('/') + '/'
|
||||||
kw['name'] = path
|
kw['name'] = path
|
||||||
|
@ -103,12 +89,11 @@ class Serve(commands.Subcommand):
|
||||||
**kw)
|
**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'
|
|
||||||
description = __doc__.strip()
|
|
||||||
|
|
||||||
def run(self, args):
|
|
||||||
print("TODO: show status")
|
print("TODO: show status")
|
||||||
|
|
Loading…
Reference in a new issue