static void Main(string[] args) { try { if (TurtleAppOptions.IsHelp(args)) { MainHelpScreen.Screen.WriteScreen(); } else { var options = ConverterHelper.ConvertToTurtleAppOptions(args); var boar = FileHelper.ImportSetting(options.PathSetting); var actions = FileHelper.ImportActions(options.PathActions); var result = BoardHelper.NextListActionResult(actions, boar); ListResultScreen.Screen.WriteScreen(result); } } catch (ListMessageException ex) when(ex.Errors?.Count > 1) { ListMessageErrorScreen.Screen.WriteScreen(ex.Errors); } catch (MessageException ex) { MessageErrorScreen.Screen.WriteScreen(ex.Message); } catch { UnexpectedErrorScreen.Screen.WriteScreen(); } Console.ReadLine(); }
public static TurtleAppOptions ConvertToTurtleAppOptions(IEnumerable <string> args) { string path; var options = new TurtleAppOptions(); var msgErrors = new List <string>(); var argQueue = new Queue <string>(args); while (argQueue.TryDequeue(out string param)) { try { switch (TurtleAppOptions.GetOptionType(param)) { case TurtleAppOptionType.PathSetting: if (GetArgPath(ref argQueue, out path)) { options.PathSetting = path; } else { msgErrors.Add($"Incorrect option format: It was provider {TurtleAppOptions.PATH_SETTING} but not a path."); } break; case TurtleAppOptionType.PathActions: if (GetArgPath(ref argQueue, out path)) { options.PathActions = path; } else { msgErrors.Add($"Incorrect option format: It was provider {TurtleAppOptions.PATH_ACTIONS} but not a path."); } break; default: msgErrors.Add($"The parameter {param} is unknown."); break; } } catch { msgErrors.Add("Something happen processing the parameters, please try again."); } } if (!options.HasPathActions) { msgErrors.Add($"You need to add {TurtleAppOptions.PATH_ACTIONS} with a path for the action file."); } if (!options.HasPathSetting) { msgErrors.Add($"You need to add {TurtleAppOptions.PATH_SETTING} with a path for the setting file."); } if (msgErrors.Any()) { throw new ListMessageException(msgErrors); } return(options); }
private static bool GetArgPath(ref Queue <string> argQueue, out string path) { var result = argQueue.TryPeek(out string tempPath) && TurtleAppOptions.GetOptionType(tempPath) == TurtleAppOptionType.UNKNOWN; path = result ? argQueue.Dequeue() : string.Empty; return(result); }