private static async Task RunHelpAsync(bool isHelp, string commandName, Dictionary <string, Func <IJobContext, Task> > pluginJobs) { if (isHelp || string.IsNullOrEmpty(commandName)) { var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); await Console.Out.WriteLineAsync($"Cli 命令行版本: {version.Substring(0, version.Length - 2)}"); await Console.Out.WriteLineAsync($"当前文件夹: {CliUtils.PhysicalApplicationPath}"); await Console.Out.WriteLineAsync($"Cli 命令行文件夹: {Assembly.GetExecutingAssembly().Location}"); await Console.Out.WriteLineAsync(); await CliUtils.PrintRowLine(); await CliUtils.PrintRow("Usage"); await CliUtils.PrintRowLine(); var backupJob = new BackupJob(); var installJob = new InstallJob(); var restoreJob = new RestoreJob(); var syncJob = new SyncJob(); var updateJob = new UpdateJob(); var versionJob = new VersionJob(); backupJob.PrintUsage(); installJob.PrintUsage(); restoreJob.PrintUsage(); syncJob.PrintUsage(); updateJob.PrintUsage(); versionJob.PrintUsage(); if (pluginJobs != null && pluginJobs.Count > 0) { Console.WriteLine($"插件命令: {TranslateUtils.ObjectCollectionToString(pluginJobs.Keys)}"); Console.WriteLine(); } await CliUtils.PrintRowLine(); await CliUtils.PrintRow(CloudUtils.Root.DocsCliUrl); await CliUtils.PrintRowLine(); Console.ReadLine(); } else { Console.WriteLine($"'{commandName}' is not a siteserver command. See 'sitserver --help'"); } }
private static async Task RunHelpAsync(bool isHelp, string commandName) { if (isHelp || string.IsNullOrEmpty(commandName)) { var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); await Console.Out.WriteLineAsync($"Cli 命令行版本: {version.Substring(0, version.Length - 2)}"); await Console.Out.WriteLineAsync($"当前文件夹: {CliUtils.PhysicalApplicationPath}"); await Console.Out.WriteLineAsync($"Cli 命令行文件夹: {Assembly.GetExecutingAssembly().Location}"); await Console.Out.WriteLineAsync(); await CliUtils.PrintRowLine(); await CliUtils.PrintRow("Usage"); await CliUtils.PrintRowLine(); BackupJob.PrintUsage(); InstallJob.PrintUsage(); RestoreJob.PrintUsage(); UpdateJob.PrintUsage(); VersionJob.PrintUsage(); await CliUtils.PrintRowLine(); await CliUtils.PrintRow("https://www.siteserver.cn/docs/cli"); await CliUtils.PrintRowLine(); Console.ReadLine(); } else { Console.WriteLine($"'{commandName}' is not a siteserver command. See 'sitserver --help'"); } }
private static void Main(string[] args) { try { Console.OutputEncoding = Encoding.GetEncoding(936); } catch { try { Console.OutputEncoding = Encoding.UTF8; } catch { // ignored } } if (!CliUtils.ParseArgs(Options, args)) { return; } var commandNames = new List <string>(); var commandArgs = new List <string>(); if (args.Length >= 1) { var isCommand = true; foreach (var arg in args) { if (isCommand && !StringUtils.StartsWith(arg, "-")) { commandNames.Add(StringUtils.Trim(arg)); } else { isCommand = false; commandArgs.Add(StringUtils.Trim(arg)); } } } CommandName = string.Join(" ", commandNames); CommandArgs = commandArgs.ToArray(); Console.WriteLine("欢迎使用 SiteServer Cli 命令行工具"); Console.WriteLine(); var backupJob = new BackupJob(); var installJob = new InstallJob(); var restoreJob = new RestoreJob(); var syncJob = new SyncJob(); var updateJob = new UpdateJob(); var versionJob = new VersionJob(); var testJob = new TestJob(); Jobs = new Dictionary <string, Func <IJobContext, Task> >(StringComparer.CurrentCultureIgnoreCase) { { BackupJob.CommandName, backupJob.Execute }, { InstallJob.CommandName, installJob.Execute }, { RestoreJob.CommandName, restoreJob.Execute }, { SyncJob.CommandName, syncJob.Execute }, { UpdateJob.CommandName, updateJob.Execute }, { VersionJob.CommandName, versionJob.Execute }, { TestJob.CommandName, testJob.Execute } }; PluginManager.LoadPlugins(CliUtils.PhysicalApplicationPath); var pluginJobs = PluginJobManager.GetJobs(); if (pluginJobs != null && pluginJobs.Count > 0) { foreach (var command in pluginJobs.Keys) { if (!Jobs.ContainsKey(command)) { Jobs.Add(command, pluginJobs[command]); } } } if (!Jobs.ContainsKey(CommandName)) { RunHelpAsync(IsHelp, CommandName, pluginJobs).GetAwaiter().GetResult(); } else if (!string.IsNullOrEmpty(Repeat)) { RunRepeatAsync(Repeat).GetAwaiter().GetResult(); } else { RunExecuteAsync(CommandName, CommandArgs, null).GetAwaiter().GetResult(); } }