core (launcher): Separate add_subparsers for exensibility:
`add_subparsers` is now in its own method to it can be extended by a subclass. Notably needed by web frontend to add its `local` command.
This commit is contained in:
parent
00c7f1b1a3
commit
e257600ad5
1 changed files with 18 additions and 4 deletions
|
|
@ -21,6 +21,7 @@
|
|||
import sys
|
||||
import os
|
||||
import argparse
|
||||
from argparse import _SubParsersAction
|
||||
from pathlib import Path
|
||||
|
||||
# We want to install asyncreactor before any import from twisted or Libervia to be sure
|
||||
|
|
@ -170,10 +171,25 @@ class Launcher:
|
|||
print(self.NOT_RUNNING_MSG)
|
||||
sys.exit(1)
|
||||
|
||||
def parse_args(self):
|
||||
def parse_args(self) -> argparse.Namespace:
|
||||
"""Parse command-line arguments and return the resulting namespace.
|
||||
|
||||
Subclasses can override to add custom subparsers before calling
|
||||
``parser.parse_args()``.
|
||||
|
||||
@return: The configured argument parser.
|
||||
"""
|
||||
parser = argparse.ArgumentParser(description=f"Launch {self.APP_NAME} backend")
|
||||
parser.set_defaults(cmd=self.cmd_no_subparser)
|
||||
subparsers = parser.add_subparsers()
|
||||
subparsers: _SubParsersAction = parser.add_subparsers()
|
||||
self.add_subparsers(subparsers)
|
||||
return parser.parse_args()
|
||||
|
||||
def add_subparsers(self, subparsers: _SubParsersAction) -> None:
|
||||
"""Add subparsers (bg, fg, debug, stop, status).
|
||||
|
||||
@param subparsers: The subparsers object from the argument parser.
|
||||
"""
|
||||
extra_help = f"arguments to pass to {self.APP_NAME} service"
|
||||
|
||||
bg_parser = subparsers.add_parser(
|
||||
|
|
@ -208,8 +224,6 @@ class Launcher:
|
|||
)
|
||||
status_parser.set_defaults(cmd=self.cmd_status)
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
def get_pid_file(self) -> Path:
|
||||
return self.config.common.pid_dir / f"{self.APP_NAME_FILE}.pid"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue