/// <summary> /// Handler for param array arguments /// </summary> /// <param name="argument"><see cref="ArgumentData"/></param> /// <param name="value">Value of argument</param> /// <returns>True if it was successfully handled</returns> private bool HandleParamArray(ArgumentData argument, string value) { // Param is specified as key:value or key=value if (!string.IsNullOrWhiteSpace(value)) { return(Result.TrySetPropertyValue(argument.Property, value.Split(SplitChars))); } // Value should be the next argumentKey IList <string> array = new List <string>(); while (++Position < Arguments.Length) { Tuple <string, string> nextParam = ArgumentParserUtils.ParseParam(Arguments[Position]); if (nextParam != null) { Position--; break; } array.Add(Arguments[Position]); } if (array.Count > 0) { return(Result.TrySetPropertyValue(argument.Property, array)); } LogHelper.LogError("No values specified for array '{0}'", argument.Key); return(false); }
/// <summary> /// Internal helper method for parsing arguments /// </summary> /// <returns>True if all arguments were successfully parsed</returns> internal bool Parse() { while (++Position < Arguments.Length) { Tuple <string, string> param = ArgumentParserUtils.ParseParam(Arguments[Position]); if (param == null || !Data.ContainsKey(param.Item1)) { if (Arguments[Position].Equals("/?")) { NeedHelp = true; return(false); } LogHelper.LogError("Unrecogized parameter '{0}'.", Arguments[Position]); return(false); } if (param.Item1.Equals("h", StringComparison.OrdinalIgnoreCase) || param.Item1.Equals("help", StringComparison.OrdinalIgnoreCase)) { NeedHelp = true; return(false); } ArgumentData argumentData = Data[param.Item1]; if (argumentData.Seen) { LogHelper.LogError("Argument '{0}' re-defined with value '{1}'.", param.Item1, param.Item2); return(false); } argumentData.Seen = true; if (!HandleArgument(argumentData, param.Item2)) { return(false); } } foreach (ArgumentData argumentData in Data.Values.Where(d => !d.Seen)) { if (!argumentData.Optional) { LogHelper.LogError("Argument [{0}] is required.", argumentData.Name); return(false); } if (!HandleDefaultValue(argumentData)) { return(false); } } return(true); }
/// <summary> /// Handler for single param arguments /// </summary> /// <param name="argument"><see cref="ArgumentData"/></param> /// <param name="value">Value of argument</param> /// <returns>True if it was successfully handled</returns> private bool HandleParam(ArgumentData argument, string value) { // Param is specified as key:value or key=value if (!string.IsNullOrWhiteSpace(value)) { return(Result.TrySetPropertyValue(argument.Property, value)); } // Value should be the next argumentKey if (++Position < Arguments.Length) { Tuple <string, string> nextParam = ArgumentParserUtils.ParseParam(Arguments[Position]); if (nextParam == null) { return(Result.TrySetPropertyValue(argument.Property, Arguments[Position])); } } Position--; LogHelper.LogError("Value for parameter '{0}' not specified", argument.Key); return(false); }