Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions midcli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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()


Expand Down
5 changes: 3 additions & 2 deletions midcli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion midcli/menu/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down