From 12f7544885b7308bccb9bf76bcd6e417a97c51e2 Mon Sep 17 00:00:00 2001 From: jk2k <4025839+jk2k@users.noreply.github.com> Date: Mon, 1 Dec 2025 23:08:11 +0800 Subject: [PATCH] fix: replace TrueNAS with vendor name --- midcli/__main__.py | 14 +++++++++++--- midcli/context.py | 5 +++-- midcli/menu/items.py | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/midcli/__main__.py b/midcli/__main__.py index 2e7e954..6355bdd 100644 --- a/midcli/__main__.py +++ b/midcli/__main__.py @@ -6,6 +6,7 @@ import sys import threading import time +import json from prompt_toolkit import print_formatted_text as print from prompt_toolkit.application import run_in_terminal @@ -36,7 +37,7 @@ class CLI: default_prompt = '[%h]%_n> ' def __init__(self, url=None, user=None, password=None, timeout=None, command=None, interactive=None, menu=False, - menu_item=None, mode=None, pager=False, print_template=False, stacks=False): + menu_item=None, mode=None, pager=False, print_template=False, stacks=False, vendor="TrueNAS"): if command is None or interactive: editor = InteractiveEditor() elif print_template: @@ -48,7 +49,7 @@ def __init__(self, url=None, user=None, password=None, timeout=None, command=Non enable_pager() self.context = Context(self, url=url, user=user, password=password, timeout=timeout, - editor=editor, menu=menu, menu_item=menu_item, mode=mode, stacks=stacks) + editor=editor, menu=menu, menu_item=menu_item, mode=mode, stacks=stacks, vendor=vendor) self.command = command self.completer = MidCompleter(self.context) @@ -294,7 +295,14 @@ def main(): help='Display errors stack trace') args = parser.parse_args() - cli = CLI(**args.__dict__) + vendor = "TrueNAS" + try: + with open("/data/.vendor") as f: + vendor = json.loads(f.read()).get("name", "TrueNAS") + except Exception: + pass + + cli = CLI(vendor=vendor, **args.__dict__) cli.run() diff --git a/midcli/context.py b/midcli/context.py index f0ed706..9a855c4 100644 --- a/midcli/context.py +++ b/midcli/context.py @@ -185,12 +185,13 @@ def build_namespaces(self, client): class Context: - def __init__(self, cli, url, user, password, timeout, editor, menu, menu_item, mode, stacks): + def __init__(self, cli, url, user, password, timeout, editor, menu, menu_item, mode, stacks, vendor): self.cli = cli self.url = url self.user = user self.password = password self.timeout = timeout + self.vendor = vendor self.reload() with self.get_client() as c: self.methods = c.call('core.get_methods', None, 'CLI') @@ -266,7 +267,7 @@ def get_client(self): error = 'middleware is not responding' recoverable_error = True elif isinstance(e, ClientException) and e.errno == ClientException.ENOTAUTHENTICATED: - error = 'You are not authorized to use TrueNAS CLI' + error = f'You are not authorized to use {self.vendor} CLI' elif isinstance(e, ClientException) and e.error == 'Failed connection handshake': error = e.error recoverable_error = True diff --git a/midcli/menu/items.py b/midcli/menu/items.py index ca3d180..99c007b 100644 --- a/midcli/menu/items.py +++ b/midcli/menu/items.py @@ -131,7 +131,7 @@ def get_menu_items(context): menu_items.append(("Set up local administrator", manage_local_administrator_password)) menu_items += [ ("Reset configuration to defaults", reset_configuration), - ("Open TrueNAS CLI Shell", cli), + (f"Open {context.vendor} CLI Shell", cli), ("Open Linux Shell", shell), ("Reboot", reboot), ("Shutdown", shutdown),