static void Main(string[] args) { var app = new CLU.CommandLineApplication(); app.Name = "CreateHotfixFromMacroDeveloperToolOutput"; app.Description = ".Net Core console app. Reads a Protocol Sync SQL file containing output from the Macro Developer Tool split by a divider string, reorganises the SQL and outputs to a specified file."; var targetFileArgument = app.Argument("TargetFile", "The path and filename of the file containing the Macro Developer Tool output"); var outputFileArgument = app.Argument("OutputFile", "The path and filename of the file where output will be written to"); var dividerArgument = app.Argument("Divider", "String used to divide discrete blocks of SQL"); var overwriteOption = app.Option("-o|--overwrite", "Flag indicating that existing file matching the output file should be overwritten", CLU.CommandOptionType.NoValue); app.HelpOption("-?|-h|--help"); app.OnExecute(() => { int result = 0; if (string.IsNullOrEmpty(targetFileArgument.Value)) { Console.WriteLine("Error: A target file must be specified!"); result = 1; } else if (!File.Exists(targetFileArgument.Value)) { Console.WriteLine("Error: Target file not found!"); result = 1; } else if (string.IsNullOrEmpty(outputFileArgument.Value)) { Console.WriteLine("Error: An output file must be specified!"); result = 1; } else if (File.Exists(outputFileArgument.Value) && !overwriteOption.HasValue()) { Console.WriteLine("Error: File matching output file argument already exists and overwrite option has not been specified!"); result = 1; } else if (string.IsNullOrEmpty(dividerArgument.Value)) { Console.WriteLine("Error: The divider string must be specified!"); result = 1; } else { DoWork(targetFileArgument.Value, outputFileArgument.Value, dividerArgument.Value); } return(result); }); var result = app.Execute(args); }
static void Main(string[] args) { var app = new CLU.CommandLineApplication(); app.Name = "AppendDividerToFiles"; app.Description = ".Net Core console app. Appends a divider string to all files in a given directory."; var targetFolderArgument = app.Argument("TargetFolder", "The folder containing the files you wish to target"); var dividerOption = app.Option("-d|--divider", "The divider to append.", CLU.CommandOptionType.SingleValue); app.HelpOption("-?|-h|--help"); app.OnExecute(() => { int result = 0; if (string.IsNullOrEmpty(targetFolderArgument.Value)) { Console.WriteLine("Error: A target folder must be specified!"); result = 1; } else if (!Directory.Exists(targetFolderArgument.Value)) { Console.WriteLine("Error: Target folder not found!"); result = 1; } else { string divider = (dividerOption.HasValue()) ? dividerOption.Value() : DEFAULT_DIVIDER; DoWork(targetFolderArgument.Value, divider); } return result; }); var result = app.Execute(args); }