core, doc, cli (forums): new forums set commands + doc:

- document the fact that if an empty `uri` is used, the forum node is created
  automatically
- new `forums/set` CLI commands and its documentation
This commit is contained in:
Goffi 2023-12-11 18:10:27 +01:00
commit b634e41ac0

View file

@ -18,11 +18,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
from . import base
from libervia.backend.core.i18n import _
from libervia.cli.constants import Const as C
from libervia.cli import common
from libervia.backend.tools.common.ansi import ANSI as A
from libervia.frontends.bridge.bridge_frontend import BridgeException
import codecs
import json
@ -82,7 +84,7 @@ class Edit(base.CommandBase, common.BaseEdit):
self.args.key,
self.profile,
)
except Exception as e:
except BridgeException as e:
if e.classname == "NotFound":
forums_json = ""
else:
@ -169,11 +171,51 @@ class Get(base.CommandBase):
self.host.quit(1)
forums = json.loads(forums_raw)
await self.output(forums)
class Set(base.CommandBase):
def __init__(self, host):
base.CommandBase.__init__(
self,
host,
"set",
use_pubsub=True,
help=_("set forums"),
)
def add_parser_options(self):
self.parser.add_argument(
"-k",
"--key",
default="",
help=_("forum key (DEFAULT: default forums)"),
)
async def start(self):
forums_raw = sys.stdin.read()
try:
json.loads(forums_raw)
except Exception as e:
self.parser.error(f"Invalid JSON, a valid JSON must be used as input: {e}")
try:
await self.host.bridge.forums_set(
forums_raw,
self.args.service,
self.args.node,
self.args.key,
self.profile,
)
except Exception as e:
self.disp(f"can't set forums: {e}", error=True)
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
else:
self.disp(_("forums have been set"))
self.host.quit()
class Forums(base.CommandBase):
subcommands = (Get, Edit)
subcommands = (Get, Set, Edit)
def __init__(self, host):
super(Forums, self).__init__(