--basic option to disable advanced output (UpToolCLI)

This commit is contained in:
JFronny 2020-08-31 19:56:10 +02:00
parent c5de2e6886
commit b2d353b0bb
2 changed files with 61 additions and 39 deletions

View File

@ -1,5 +1,7 @@
using System; using System;
using System.CommandLine; using System.CommandLine;
using System.CommandLine.Invocation;
using System.Linq;
using UpToolLib; using UpToolLib;
using UpToolLib.Tool; using UpToolLib.Tool;
@ -17,6 +19,8 @@ namespace UpToolCLI
XmlTool.FixXml(); XmlTool.FixXml();
ExternalFunctionalityManager.Init(Functions); ExternalFunctionalityManager.Init(Functions);
RootCommand rootCommand = new RootCommand(); RootCommand rootCommand = new RootCommand();
rootCommand.AddGlobalOption(new Option<bool>("--basic"));
UtLibFunctions.Basic = args.Contains("--basic");
PackageManagement.RegisterCommands(rootCommand); PackageManagement.RegisterCommands(rootCommand);
CacheManagement.RegisterCommands(rootCommand); CacheManagement.RegisterCommands(rootCommand);

View File

@ -10,6 +10,7 @@ namespace UpToolCLI
{ {
public class UtLibFunctions : IExternalFunctionality public class UtLibFunctions : IExternalFunctionality
{ {
public static bool Basic;
public Tuple<bool, byte[]> Download(Uri link) public Tuple<bool, byte[]> Download(Uri link)
{ {
using WebClient client = new WebClient(); using WebClient client = new WebClient();
@ -24,10 +25,13 @@ namespace UpToolCLI
finished = true; finished = true;
}; };
client.DownloadProgressChanged += (sender, e) => client.DownloadProgressChanged += (sender, e) =>
{
if (!Basic)
{ {
Console.Write( Console.Write(
$"{new string('=', e.ProgressPercentage / 10)}[{e.ProgressPercentage}]{new string('-', 10 - e.ProgressPercentage / 10)}"); $"{new string('=', e.ProgressPercentage / 10)}[{e.ProgressPercentage}]{new string('-', 10 - e.ProgressPercentage / 10)}");
Console.CursorLeft = 0; Console.CursorLeft = 0;
}
}; };
client.DownloadDataAsync(link); client.DownloadDataAsync(link);
while (!finished) while (!finished)
@ -46,6 +50,14 @@ namespace UpToolCLI
} }
public bool YesNoDialog(string text, bool defaultVal) public bool YesNoDialog(string text, bool defaultVal)
{
if (Basic)
{
Console.WriteLine(text);
Console.WriteLine("Selecting \"Yes\"");
return false;
}
else
{ {
bool choosing = true; bool choosing = true;
bool current = defaultVal; bool current = defaultVal;
@ -81,8 +93,13 @@ namespace UpToolCLI
Console.WriteLine($" Selecting: {current}"); Console.WriteLine($" Selecting: {current}");
return current; return current;
} }
}
public void OkDialog(string text) public void OkDialog(string text)
{
if (Basic)
Console.WriteLine(text);
else
{ {
Console.WriteLine(text); Console.WriteLine(text);
Console.BackgroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.White;
@ -90,6 +107,7 @@ namespace UpToolCLI
Console.ResetColor(); Console.ResetColor();
Console.ReadKey(); Console.ReadKey();
} }
}
public object GetDefaultIcon() => 0; public object GetDefaultIcon() => 0;