Various CLI improvements

- Show dialog before adding default repo
- Prevent edge-case where --basic is used later in a CLI command
- Fix RemoveRepo in basic mode
- Use default instead of true in basic YesNoDialog
This commit is contained in:
JFronny 2020-08-31 20:22:37 +02:00
parent b2d353b0bb
commit 0eccafa9ea
4 changed files with 17 additions and 16 deletions

View File

@ -16,11 +16,11 @@ namespace UpToolCLI
MutexLock.Lock();
try
{
XmlTool.FixXml();
ExternalFunctionalityManager.Init(Functions);
XmlTool.FixXml();
RootCommand rootCommand = new RootCommand();
rootCommand.AddGlobalOption(new Option<bool>("--basic"));
UtLibFunctions.Basic = args.Contains("--basic");
UtLibFunctions.Basic = args.Length > 0 && args[0] == "--basic";
PackageManagement.RegisterCommands(rootCommand);
CacheManagement.RegisterCommands(rootCommand);

View File

@ -76,19 +76,14 @@ namespace UpToolCLI
},
u => u.Element("Name").Value,
u => u.Element("Link").Value));
Console.WriteLine("Are you sure you want to delete them all? (y/n)");
ConsoleKey k;
do
k = Console.ReadKey().Key;
while (k != ConsoleKey.Y && k != ConsoleKey.N);
if (k == ConsoleKey.N || k != ConsoleKey.Y)
if (!Program.Functions.YesNoDialog("Are you sure you want to delete them all?", false))
return;
break;
}
for (int i = 0; i < sRepos.Length; i++)
foreach (XElement t in sRepos)
{
Console.WriteLine($"Removing {sRepos[i].Element("Name").Value}");
sRepos[i].Remove();
Console.WriteLine($"Removing {t.Element("Name").Value}");
t.Remove();
}
doc.Save(PathTool.InfoXml);
Console.WriteLine("Removed repo. Remember to update the cache using \"uptool update\"");

View File

@ -54,8 +54,8 @@ namespace UpToolCLI
if (Basic)
{
Console.WriteLine(text);
Console.WriteLine("Selecting \"Yes\"");
return false;
Console.WriteLine($"Selecting: {defaultVal}");
return defaultVal;
}
else
{

View File

@ -30,9 +30,15 @@ namespace UpToolLib.Tool
if (meta.Element("Repos") == null)
meta.Add(new XElement("Repos"));
if (meta.Element("Repos").Elements("Repo").Count() == 0)
meta.Element("Repos").Add(new XElement("Repo", new XElement("Name", "UpTool2 official Repo"),
new XElement("Link",
"https://gitlab.com/JFronny/UpTool2/snippets/1988600/raw")));
{
if (ExternalFunctionalityManager.Instance.YesNoDialog(
"No active repository was detected. Add the default repo?", false))
{
meta.Element("Repos").Add(new XElement("Repo", new XElement("Name", "UpTool2 official Repo"),
new XElement("Link",
"https://gitlab.com/JFronny/UpTool2/snippets/1988600/raw")));
}
}
meta.Element("Repos").Elements("Repo").Select(s => s.Element("Link"))
.Where(s => new[]
{