Skip to content

Commit

Permalink
feat: 添加命令行参数 NoPause
Browse files Browse the repository at this point in the history
fix: 退出按两次
  • Loading branch information
Dissectum committed Sep 25, 2023
1 parent 6ddb5dd commit 0881696
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/MBA.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,31 @@ static int Main(string[] args)
if (!ResetConfig())
{
Log.Fatal("Failed to reset config.");
Console.WriteLine("请检查 配置输入 是否正确,按任意键关闭此窗口. . .");
Console.ReadKey();
Console.WriteLine("请检查 配置输入 是否正确");
TipPause();
return -1;
}

if (!ProcArgs(args))
{
Log.Fatal("Failed to parse args.");
Console.WriteLine("请检查 命令行参数 是否正确,按任意键关闭此窗口. . .");
Console.ReadKey();
Console.WriteLine("请检查 命令行参数 是否正确");
TipPause();
return -1;
}

if (!Config.Tasks.Any())
{
Log.Fatal("Task List is empty.");
Console.WriteLine("请检查 任务列表 是否为空,按任意键关闭此窗口. . .");
Console.ReadKey();
Console.WriteLine("请检查 任务列表 是否为空");
TipPause();
return -1;
}

Core.Main.Current.Start();

TipNewVersion();
Console.WriteLine("按任意键关闭此窗口. . .");
Console.ReadKey();
TipPause();
return 0;
}

Expand All @@ -73,13 +72,23 @@ private static void TipNewVersion()
Console.ForegroundColor = ConsoleColor.White;
}

private static void TipPause()
{
if (!s_pasue)
return;

Console.WriteLine("按任意键关闭此窗口. . .");
Console.ReadKey();
}

static string Greeting =>
$@"
MBA.Cli.exe [arg] ...
arg:
设备地址:端口号(e.g. 127.0.0.1:5555)
任务名(e.g. Tasks)
任务Id(e.g. 1)
完成后不暂停(NoPause)
也可以修改 config.json 来进行相关配置(命令行参数优先于 config.json)
通过命令行执行的任务是一次性的,将不会保存于 config.json
Expand All @@ -92,6 +101,8 @@ 也可以修改 config.json 来进行相关配置(命令行参数优先于 con
";

const int WaitTime = 3;
const string NoPause = "nopause";
private static bool s_pasue = true;

/// <summary>
/// 启动时重设配置
Expand Down Expand Up @@ -139,6 +150,12 @@ static bool ProcArgs(string[] args)
continue;
}

if (arg.ToLower() == NoPause)
{
s_pasue = false;
continue;
}

if (Enum.TryParse(arg, out TaskType task))
{
taskList.Add(task);
Expand Down
1 change: 1 addition & 0 deletions src/MBA.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"profiles": {
"MBA.Cli": {
"commandName": "Project",
"commandLineArgs": "NoPause",
"environmentVariables": {
"MBA_ENVIRONMENT": "Debug"
}
Expand Down

0 comments on commit 0881696

Please sign in to comment.