From 2c36c08ca0e9a42bf93ef4c22010bd43bfa4161b Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Wed, 4 Feb 2026 21:53:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=86=E5=88=86=E4=BB=A3=E7=A0=819?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/Commands/User/CpassCommand.cs | 10 ++++ shell/Commands/User/HostnameCommand.cs | 18 +++++++ shell/Commands/User/UserCommand.cs | 71 ++++++++++++++++++++++++++ shell/Shell.cs | 71 ++------------------------ 4 files changed, 102 insertions(+), 68 deletions(-) create mode 100644 shell/Commands/User/CpassCommand.cs create mode 100644 shell/Commands/User/HostnameCommand.cs create mode 100644 shell/Commands/User/UserCommand.cs diff --git a/shell/Commands/User/CpassCommand.cs b/shell/Commands/User/CpassCommand.cs new file mode 100644 index 0000000..3f08255 --- /dev/null +++ b/shell/Commands/User/CpassCommand.cs @@ -0,0 +1,10 @@ +namespace CMLeonOS.Commands.User +{ + public static class CpassCommand + { + public static void ProcessCpass(CMLeonOS.UserSystem userSystem) + { + userSystem.ChangePassword(); + } + } +} diff --git a/shell/Commands/User/HostnameCommand.cs b/shell/Commands/User/HostnameCommand.cs new file mode 100644 index 0000000..8851d8c --- /dev/null +++ b/shell/Commands/User/HostnameCommand.cs @@ -0,0 +1,18 @@ +using System; + +namespace CMLeonOS.Commands.User +{ + public static class HostnameCommand + { + public static void ProcessHostnameCommand(string args, CMLeonOS.UserSystem userSystem, Action showError) + { + if (string.IsNullOrEmpty(args)) + { + showError("Usage: hostname "); + return; + } + + userSystem.ProcessHostnameCommand(args); + } + } +} diff --git a/shell/Commands/User/UserCommand.cs b/shell/Commands/User/UserCommand.cs new file mode 100644 index 0000000..311c266 --- /dev/null +++ b/shell/Commands/User/UserCommand.cs @@ -0,0 +1,71 @@ +using System; + +namespace CMLeonOS.Commands.User +{ + public static class UserCommand + { + public static void ProcessUserCommand(string args, CMLeonOS.UserSystem userSystem, Action showError) + { + if (string.IsNullOrEmpty(args)) + { + showError("Error: Please specify a user command"); + showError("Please specify a user command"); + showError("user [args]"); + showError(" user add admin - Add admin user"); + showError(" user add user - Add regular user"); + showError(" user delete - Delete user"); + showError(" user list - List all users"); + return; + } + + string[] parts = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + if (parts.Length < 1) + { + showError("Error: Please specify a user command"); + showError("Usage: user [args]"); + return; + } + + string subCommand = parts[0].ToLower(); + + if (subCommand == "add") + { + if (parts.Length < 4) + { + showError("Error: Please specify user type and username and password"); + showError("Usage: user add admin "); + showError("Usage: user add user "); + return; + } + + string userType = parts[1].ToLower(); + string username = parts[2]; + string password = parts[3]; + bool isAdmin = userType == "admin"; + + userSystem.AddUser($"{username} {password}", isAdmin); + } + else if (subCommand == "delete") + { + if (parts.Length < 2) + { + showError("Error: Please specify username"); + showError("Usage: user delete "); + return; + } + + string username = parts[1]; + userSystem.DeleteUser(username); + } + else if (subCommand == "list") + { + userSystem.ListUsers(); + } + else + { + showError($"Error: Unknown user command '{subCommand}'"); + showError("Available commands: add, delete, list"); + } + } + } +} diff --git a/shell/Shell.cs b/shell/Shell.cs index 9dbc150..1c5fb5d 100644 --- a/shell/Shell.cs +++ b/shell/Shell.cs @@ -196,7 +196,7 @@ namespace CMLeonOS public void ProcessCpass() { - userSystem.ChangePassword(); + Commands.User.CpassCommand.ProcessCpass(userSystem); } public void ProcessBeep() @@ -460,77 +460,12 @@ namespace CMLeonOS public void ProcessHostnameCommand(string args) { - if (string.IsNullOrEmpty(args)) - { - ShowError("Usage: hostname "); - return; - } - - userSystem.ProcessHostnameCommand(args); + Commands.User.HostnameCommand.ProcessHostnameCommand(args, userSystem, ShowError); } public void ProcessUserCommand(string args) { - if (string.IsNullOrEmpty(args)) - { - ShowError("Error: Please specify a user command"); - ShowError("Please specify a user command"); - ShowError("user [args]"); - ShowError(" user add admin - Add admin user"); - ShowError(" user add user - Add regular user"); - ShowError(" user delete - Delete user"); - ShowError(" user list - List all users"); - return; - } - - string[] parts = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - if (parts.Length < 1) - { - ShowError("Error: Please specify a user command"); - ShowError("Usage: user [args]"); - return; - } - - string subCommand = parts[0].ToLower(); - - if (subCommand == "add") - { - if (parts.Length < 4) - { - ShowError("Error: Please specify user type and username and password"); - ShowError("Usage: user add admin "); - ShowError("Usage: user add user "); - return; - } - - string userType = parts[1].ToLower(); - string username = parts[2]; - string password = parts[3]; - bool isAdmin = userType == "admin"; - - userSystem.AddUser($"{username} {password}", isAdmin); - } - else if (subCommand == "delete") - { - if (parts.Length < 2) - { - ShowError("Error: Please specify username"); - ShowError("Usage: user delete "); - return; - } - - string username = parts[1]; - userSystem.DeleteUser(username); - } - else if (subCommand == "list") - { - userSystem.ListUsers(); - } - else - { - ShowError($"Error: Unknown user command '{subCommand}'"); - ShowError("Available commands: add, delete, list"); - } + Commands.User.UserCommand.ProcessUserCommand(args, userSystem, ShowError); } public void ProcessBransweCommand(string args)