cli (base): Add instance isolation options:
- New ``-i``/``--isolation`` argument is added, it must be used before first positional argument (i.e., first comamnd). - The new `entry.py` module is now the entry point, so it can set the `LIBERVIA_ISOLATION` environment variable before the backend read it.
This commit is contained in:
parent
c6ea6ea27b
commit
995200a978
3 changed files with 68 additions and 3 deletions
|
|
@ -596,6 +596,12 @@ class LiberviaCli:
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
self.parser.add_argument(
|
||||||
|
"-i",
|
||||||
|
"--isolation",
|
||||||
|
metavar="NAME",
|
||||||
|
help=("use the isolated instance NAME (must be used before the command)"),
|
||||||
|
)
|
||||||
|
|
||||||
def register_output(self, type_, name, callback, description="", default=False):
|
def register_output(self, type_, name, callback, description="", default=False):
|
||||||
if type_ not in C.OUTPUT_TYPES:
|
if type_ not in C.OUTPUT_TYPES:
|
||||||
|
|
|
||||||
59
libervia/cli/entry.py
Normal file
59
libervia/cli/entry.py
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# Libervia: an XMPP client
|
||||||
|
# Copyright (C) 2009-2026 Jérôme Poisson (goffi@goffi.org)
|
||||||
|
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""Entry point for the Libervia CLI frontends."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def extract_isolation_arg(argv: list[str]) -> str | None:
|
||||||
|
"""Extract the isolation argument.
|
||||||
|
|
||||||
|
Only arguments used before the first command are considered, avoiding conflicts with
|
||||||
|
sub-commands.
|
||||||
|
|
||||||
|
@param argv: The command line arguments, without the program name
|
||||||
|
@return: The isolation name, or None if the argument is not used
|
||||||
|
"""
|
||||||
|
for i, arg in enumerate(argv):
|
||||||
|
if arg in ("-i", "--isolation"):
|
||||||
|
if i + 1 >= len(argv):
|
||||||
|
return None
|
||||||
|
return argv[i + 1]
|
||||||
|
if arg.startswith("-i") and len(arg) > 2:
|
||||||
|
# combined short option, e.g. "-iname"
|
||||||
|
return arg[2:]
|
||||||
|
if arg.startswith("--isolation="):
|
||||||
|
return arg.split("=", 1)[1]
|
||||||
|
if not arg.startswith("-"):
|
||||||
|
# first positional argument (the command), we stop here
|
||||||
|
break
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
"""Run the Libervia CLI."""
|
||||||
|
# The backend reads the environment variable at import time, we have to process the
|
||||||
|
# isolation argument here, before first "libervia.backend" import.
|
||||||
|
isolation = extract_isolation_arg(sys.argv[1:])
|
||||||
|
if isolation is not None:
|
||||||
|
os.environ["LIBERVIA_ISOLATION"] = isolation
|
||||||
|
from libervia.cli.base import LiberviaCli
|
||||||
|
|
||||||
|
LiberviaCli.run()
|
||||||
|
|
@ -169,10 +169,10 @@ docs = [
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
# Legacy name, will be removed in future version
|
# Legacy name, will be removed in future version
|
||||||
jp = "libervia.cli.base:LiberviaCli.run"
|
jp = "libervia.cli.entry:main"
|
||||||
li = "libervia.cli.base:LiberviaCli.run"
|
li = "libervia.cli.entry:main"
|
||||||
libervia-backend = "libervia.backend.core.launcher:Launcher.run"
|
libervia-backend = "libervia.backend.core.launcher:Launcher.run"
|
||||||
libervia-cli = "libervia.cli.base:LiberviaCli.run"
|
libervia-cli = "libervia.cli.entry:main"
|
||||||
libervia-tui = "libervia.tui.base:LiberviaTUIApp.run"
|
libervia-tui = "libervia.tui.base:LiberviaTUIApp.run"
|
||||||
# Legacy name, will be removed in future version
|
# Legacy name, will be removed in future version
|
||||||
primitivus = "libervia.tui.base:LiberviaTUIApp.run"
|
primitivus = "libervia.tui.base:LiberviaTUIApp.run"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue