mirror of
https://github.com/Stone-Red-Code/HyperbolicDownloader.git
synced 2026-09-04 09:06:10 +02:00
Add support for command line arguments
This commit is contained in:
@@ -22,7 +22,7 @@ internal class InputHandler
|
||||
ClientCommands clientCommands = new ClientCommands();
|
||||
LogCommands logCommands = new LogCommands();
|
||||
|
||||
_ = commander.Register(input => commander.PrintHelp(input), "help");
|
||||
_ = commander.Register(input => commander.PrintHelp(input), (HelpText)"Lists all commands.", "help", "h", "?");
|
||||
_ = commander.Register(_ => Console.Clear(), (HelpText)"Clears the console.", "clear", "cls");
|
||||
_ = commander.Register(_ => exit = true, (HelpText)"Exits the application.", "exit", "quit");
|
||||
_ = commander.Register(clientCommands.ShowInfo, (HelpText)"Displays the private and public IP address.", "info", "inf");
|
||||
@@ -66,13 +66,18 @@ internal class InputHandler
|
||||
Console.CursorVisible = true;
|
||||
|
||||
string input = Console.ReadLine()?.Trim() ?? string.Empty;
|
||||
ExecuteInput(input);
|
||||
}
|
||||
}
|
||||
|
||||
public void ExecuteInput(string input)
|
||||
{
|
||||
Console.CursorVisible = false;
|
||||
try
|
||||
{
|
||||
if (!commander.Execute(input, out _))
|
||||
{
|
||||
ConsoleExt.WriteLine("Unknown command!", ConsoleColor.Red);
|
||||
ConsoleExt.WriteLine("Unknown command! Use `help` to list all commands.", ConsoleColor.Red);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -80,5 +85,4 @@ internal class InputHandler
|
||||
ConsoleExt.WriteLine($"An unexpected error occurred! {ex}", ConsoleColor.Red);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,12 +53,15 @@ internal static class Program
|
||||
{
|
||||
HyperbolicDownloaderApi.Commands.DownloadCommands downloadCommands = new HyperbolicDownloaderApi.Commands.DownloadCommands(apiManager.HostsManager, apiManager.FilesManager);
|
||||
downloadCommands.GetFileFrom(args[0]);
|
||||
Console.WriteLine("Do you want to continue using this instance? [y/N]");
|
||||
if (char.ToLower(Console.ReadKey().KeyChar) != 'y')
|
||||
{
|
||||
_ = Console.ReadLine();
|
||||
return;
|
||||
}
|
||||
else if (args.Length > 0)
|
||||
{
|
||||
ConsoleExt.WriteLine("Warning! You are using command line arguments, which can lead to unexpected behavior with some commands.", ConsoleColor.Yellow);
|
||||
Console.WriteLine();
|
||||
inputHandler.ExecuteInput(string.Join(' ', args));
|
||||
return;
|
||||
}
|
||||
|
||||
await Initialize();
|
||||
|
||||
Reference in New Issue
Block a user