private void ReadCharsFromConsole(string passwordContext, Action <char, int> appendChar, Action <int> removeChar) { _userOutput.WriteLine(passwordContext); var inputLength = 0; while (true) { var keyInfo = _userInput.ReadKey(); if (keyInfo.Key == ConsoleKey.Enter) { _userOutput.WriteLine(string.Empty); break; } if (keyInfo.Key == ConsoleKey.Backspace) { if (inputLength == 0) { continue; } removeChar(inputLength - 1); inputLength--; _userOutput.Write(@" "); continue; } appendChar(keyInfo.KeyChar, inputLength); inputLength++; _userOutput.Write(@"*"); if (inputLength != MaxLength) { continue; } _userOutput.WriteLine($"Max password length reached ({MaxLength})"); break; } }
private static void ParseCommand(string[] args) { var interactive = args.Length == 0; if (interactive) { _userOutput.WriteLine($"___________________________________________________________{'\n'}"); _userOutput.Write("Enter Command: "); } var commandArgs = interactive ? Console.ReadLine()?.Split(" ") : args; if (commandArgs == null) { return; } if (commandArgs[0].Equals("exit", StringComparison.InvariantCultureIgnoreCase)) { Environment.Exit(0); return; } var parsedCommand = _commands.FirstOrDefault(command => command.CommandName.Equals(commandArgs[0], StringComparison.InvariantCultureIgnoreCase)); var commandExists = parsedCommand != null; if (commandExists) { var parserResult = Parser.Default.ParseArguments(commandArgs, parsedCommand.OptionType); if (parserResult.Tag == ParserResultType.NotParsed) { return; } parserResult.WithParsed(options => parsedCommand.ParseOption(NetworkType.Devnet, options)); //@TODO can't hard code this return; } var types = _commands.Select(command => command.OptionType).ToArray(); Parser.Default.ParseArguments(commandArgs, types); }