Add info command
This commit is contained in:
36
src/kumacli/cmd/info.py
Normal file
36
src/kumacli/cmd/info.py
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from ..client import KumaClient
|
||||
|
||||
|
||||
class InfoCommands:
|
||||
def __init__(self, client: KumaClient):
|
||||
self.client = client
|
||||
|
||||
def get_info(self):
|
||||
"""Get server info"""
|
||||
try:
|
||||
info = self.client.api.info()
|
||||
if not info:
|
||||
print("No server info available")
|
||||
return
|
||||
|
||||
print("Server Information:")
|
||||
for key, value in info.items():
|
||||
print(f" {key}: {value}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error getting server info: {e}")
|
||||
|
||||
|
||||
def setup_info_parser(subparsers):
|
||||
"""Setup info command parser"""
|
||||
info_parser = subparsers.add_parser("info", help="Get server information")
|
||||
return info_parser
|
||||
|
||||
|
||||
def handle_info_command(args, client):
|
||||
"""Handle info command execution"""
|
||||
info_commands = InfoCommands(client)
|
||||
info_commands.get_info()
|
||||
return True
|
@@ -10,6 +10,7 @@ try:
|
||||
from .client import KumaClient
|
||||
from .cmd.monitor import setup_monitor_parser, handle_monitor_command
|
||||
from .cmd.maintenance import setup_maintenance_parser, handle_maintenance_command
|
||||
from .cmd.info import setup_info_parser, handle_info_command
|
||||
except ImportError:
|
||||
# Running directly, add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
@@ -19,6 +20,7 @@ except ImportError:
|
||||
setup_maintenance_parser,
|
||||
handle_maintenance_command,
|
||||
)
|
||||
from kumacli.cmd.info import setup_info_parser, handle_info_command
|
||||
|
||||
|
||||
def main():
|
||||
@@ -40,6 +42,7 @@ def main():
|
||||
# Setup command parsers
|
||||
monitor_parser = setup_monitor_parser(subparsers)
|
||||
maintenance_parser = setup_maintenance_parser(subparsers)
|
||||
info_parser = setup_info_parser(subparsers)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -69,6 +72,8 @@ def main():
|
||||
success = handle_monitor_command(args, client)
|
||||
elif args.resource == "maintenance":
|
||||
success = handle_maintenance_command(args, client)
|
||||
elif args.resource == "info":
|
||||
success = handle_info_command(args, client)
|
||||
else:
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
|
Reference in New Issue
Block a user