/// <summary> /// This method will process a single boolean /// command-line argument. /// </summary> /// <param name="option">The CommandLineOption object (boolean)</param> /// <param name="theArg">The single command-line argument</param> private void _ProcessBoolean(CommandLineOption <bool> option, string theArg) { // Since this is a boolean flag we only care that it's defined // It doesn't need to have any kind of value option.OptionValue = true; option.LoadError = false; }
/// <summary> /// This method will process a single number (integer) /// command-line argument. /// </summary> /// <param name="option">The CommandLineOption object (int)</param> /// <param name="theArg">The single command-line argument</param> private void _ProcessNumber(CommandLineOption <int> option, string theArg) { var valueFromArg = theArg.Split('=')[1]; var isRequired = IsPropertyMarkedAsRequired(option); if (isRequired) { option.LoadError = valueFromArg.Length == 0 ? true : false; } else { option.LoadError = false; } if (option.LoadError) { var msg = string.Format(Messages.Error_ErrorParsingOptionNoValueWasSet, new String(' ', 10), OptionPrefix + option.Name); LoadErrors.Add(msg); } option.OptionValue = Convert.ToInt32(valueFromArg); }
/// <summary> /// This method will process a single string /// command-line argument. /// </summary> /// <param name="option">The CommandLineOption object (string)</param> /// <param name="theArg">The single command-line argument</param> private void _ProcessString(CommandLineOption <string> option, string theArg) { var valueFromArg = theArg.Split('=')[1]; var isRequired = IsPropertyMarkedAsRequired(option); if (isRequired) { option.LoadError = valueFromArg.Length == 0 ? true : false; } else { option.LoadError = false; } if (option.LoadError) { var msg = string.Format(Messages.Error_ErrorParsingOptionNoValueWasSet, new String(' ', 10), OptionPrefix + option.Name); LoadErrors.Add(msg); } // Now, if this property is marked with the [IsExistingFolder] attribute, // ensure that the value is an actual existing folder. if (IsPropertyMarkedAsExistingFolder(option)) { // Only do this if the value of the argument // has a length > 0. // No sense in checking for a directory of zero length. // Zero length arguments were handled in the previous // code block :) if (valueFromArg.Length > 0) { var folder = valueFromArg.Trim(); if (!Directory.Exists(folder)) { // Error: folder doesn't exist option.LoadError = true; var msg = string.Format(Messages.Error_ErrorParsingOptionTheFolderDoesNotExist, new String(' ', 10), OptionPrefix + option.Name, folder); LoadErrors.Add(msg); } } } option.OptionValue = valueFromArg; }
/// <summary> /// The primary constructor /// </summary> /// <param name="appName">The name of the application</param> /// <param name="appVersion">The version number of the application</param> /// <param name="appCopyright">The copyright information for the application</param> /// <param name="buildDate">The string representation of the build date and time</param> /// <param name="buildYear">The string representation of the build year</param> /// <param name="args">The argument list passed in via the command-line</param> /// <param name="prefix">Optional: The prefix string used when specifying command-line arguments</param> public CommandLineOptions(string appName, string appVersion, string appCopyright, string buildDate, string buildYear, string[] args, string prefix = DEFAULT_PREFIX) { OptionPrefix = prefix; ApplicationName = appName; ApplicationVersion = appVersion; ApplicationCopyright = appCopyright; ApplicationBuildDate = buildDate; ApplicationBuildYear = buildYear; // If the argument array has only a single entry, then the // arguments list will likely have /r/n characters in it // so we need to replace these with spaces and create a // new arguments array rawArgList = args; cleanArgList = CleanupArguments(args); LoadErrors = new List <string>(); // Initialize the CommandLineOptions #region Create CommandLineOptions SolutionPath = new CommandLineOption <string>() { Name = "solutionpath", AliasList = new List <string>() { "s", "sol", "sp", "solution" }, Description = Messages.Msg_MicrosoftVisualStudioSolutionPath, OptionValue = "", ExampleValue = @"<path>" }; LoadOption(SolutionPath, cleanArgList); WebProjectPath = new CommandLineOption <string>() { Name = "webprojectpath", AliasList = new List <string>() { "p", "wpp", "projectpath" }, Description = Messages.Msg_MicrosoftVisualStudioSolutionWebProjectPath, OptionValue = "", ExampleValue = @"<path>" }; LoadOption(WebProjectPath, cleanArgList); MenuFilename = new CommandLineOption <string>() { Name = "menufilename", AliasList = new List <string>() { "m", "menu", "menufile" }, Description = Messages.Msg_Sage300MenuDefinitionFileName, OptionValue = "", ExampleValue = @"<name>" }; LoadOption(MenuFilename, cleanArgList); BuildProfile = new CommandLineOption <string>() { Name = "buildprofile", AliasList = new List <string>() { "b", "bp" }, Description = Messages.Msg_VisualStudioProjectBuildConfiguration, OptionValue = "Release", ExampleValue = @"<name>" }; LoadOption(BuildProfile, cleanArgList); DotNetFrameworkPath = new CommandLineOption <string>() { Name = "dotnetframeworkpath", AliasList = new List <string>() { "f", "dotnet", "dotnetframework", "netframework", "framework" }, Description = Messages.Msg_NetFrameworkPathContainingAspnetCompileDotExe, OptionValue = "", ExampleValue = @"<path>" }; LoadOption(DotNetFrameworkPath, cleanArgList); Mode = new CommandLineOption <int>() { Name = "mode", AliasList = new List <string>() { "md" }, Description = Messages.Msg_ApplicationModeOption, OptionValue = 0, ExampleValue = @"0" }; LoadOption(Mode, cleanArgList); Minify = new CommandLineOption <bool>() { Name = "minify", AliasList = new List <string>() { "min" }, Description = Messages.Msg_MinifyJavascriptFiles, OptionValue = false, ExampleValue = @"" }; LoadOption(Minify, cleanArgList); NoDeploy = new CommandLineOption <bool>() { Name = "nodeploy", AliasList = new List <string>() { "nd" }, Description = Messages.Msg_DoNotCopyAssetsToSage300installationDirectory, OptionValue = false, ExampleValue = @"" }; LoadOption(NoDeploy, cleanArgList); TestDeploy = new CommandLineOption <bool>() { Name = "testdeploy", AliasList = new List <string>() { "td" }, Description = Messages.Msg_SimulateCopyingOfAssetsTo, OptionValue = false, ExampleValue = @"" }; LoadOption(TestDeploy, cleanArgList); Log = new CommandLineOption <bool>() { Name = "log", AliasList = new List <string>() { "logging" }, Description = Messages.Msg_GenerateALogFileInTheCurrentWorkingFolder, OptionValue = false, ExampleValue = @"" }; LoadOption(Log, cleanArgList); ExtraResourceLanguages = new CommandLineOption <string>() { Name = "extraresourcelanguages", AliasList = new List <string>() { "extralanguages" }, Description = Messages.Msg_ExtraResourceLanguages, OptionValue = "", ExampleValue = @"fr-CA" }; LoadOption(ExtraResourceLanguages, cleanArgList); #endregion this.UsageMessage = BuildUsageMessage(); }