diff libervia/cli/base.py @ 4327:554a87ae17a6

plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks): - Former bookmarks implementation is now labeled as "legacy". - XEP-0402 is now used for bookmarks when relevant namespaces are found, and it fallbacks to legacy XEP-0048/XEP-0049 bookmarks otherwise. - CLI legacy bookmark commands have been moved to `bookmarks legacy` - CLI bookmarks commands now use the new XEP-0402 (with fallback to legacy one automatically used if necessary).
author Goffi <goffi@goffi.org>
date Wed, 20 Nov 2024 11:43:27 +0100
parents 0d7bb4df2343
children
line wrap: on
line diff
--- a/libervia/cli/base.py	Wed Nov 20 11:38:44 2024 +0100
+++ b/libervia/cli/base.py	Wed Nov 20 11:43:27 2024 +0100
@@ -16,27 +16,26 @@
 # 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/>.
 
+import argparse
 import asyncio
-from libervia.backend.core.i18n import _
-
-### logging ###
+from collections import OrderedDict
+from glob import iglob
+from importlib import import_module
+import inspect
 import logging as log
-
-log.basicConfig(level=log.WARNING, format="[%(name)s] %(message)s")
-###
-
-import sys
 import os
 import os.path
-import argparse
-import inspect
-import tty
+from pathlib import Path
+import sys
 import termios
-from pathlib import Path
-from glob import iglob
+import tty
 from typing import Optional, Set, Union
-from importlib import import_module
-from libervia.frontends.tools.jid import JID
+import xml.etree.ElementTree as ET
+
+from rich import console
+
+from libervia.backend.core import exceptions
+from libervia.backend.core.i18n import _
 from libervia.backend.tools import config
 from libervia.backend.tools.common import dynamic_import
 from libervia.backend.tools.common import uri
@@ -44,15 +43,17 @@
 from libervia.backend.tools.common import utils
 from libervia.backend.tools.common import data_format
 from libervia.backend.tools.common.ansi import ANSI as A
-from libervia.backend.core import exceptions
 import libervia.cli
+from libervia.cli.constants import Const as C
 from libervia.cli.loops import QuitException, get_libervia_cli_loop
-from libervia.cli.constants import Const as C
 from libervia.frontends.bridge.bridge_frontend import BridgeException
 from libervia.frontends.tools import aio, misc
-import xml.etree.ElementTree as ET  # FIXME: used temporarily to manage XMLUI
-from collections import OrderedDict
-from rich import console
+from libervia.frontends.tools.jid import JID
+
+log.basicConfig(level=log.WARNING, format="[%(name)s] %(message)s")
+###
+
+
 
 ## bridge handling
 # we get bridge name from conf and initialise the right class accordingly
@@ -90,6 +91,21 @@
 def date_decoder(arg):
     return date_utils.date_parse_ext(arg, default_tz=date_utils.TZ_LOCAL)
 
+def optional_bool_decoder(arg: str) -> bool:
+    """Decode an optional string to a boolean value.
+
+    @param value: The input string to decode.
+    @return: The decoded boolean value.
+    @raise ValueError: If the input string is not a valid boolean representation.
+    """
+    lower_arg = arg.lower()
+    if lower_arg in ['true', '1', 't', 'y', 'yes']:
+        return True
+    elif lower_arg in ['false', '0', 'f', 'n', 'no']:
+        return False
+    else:
+        raise ValueError(f"Invalid boolean value: {arg}")
+
 
 class LiberviaCli:
     """