예제 #1
0
		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);
		}
예제 #2
0
        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);
        }
        public CommandLineApplication()
        {
            Application = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication(throwOnUnexpectedArg: false);
            Application.HelpOption("-? | -h | --help");

            _applicationRoot  = Application.Option("-s | --source", "Solution or directory for OmniSharp to point at (defaults to current directory).", CommandOptionType.SingleValue);
            _logLevel         = Application.Option("-l | --loglevel", "Level of logging (defaults to 'Information').", CommandOptionType.SingleValue);
            _verbose          = Application.Option("-v | --verbose", "Explicitly set 'Debug' log level.", CommandOptionType.NoValue);
            _hostPid          = Application.Option("-hpid | --hostPID", "Host process ID.", CommandOptionType.SingleValue);
            _zeroBasedIndices = Application.Option("-z | --zero-based-indices", "Use zero based indices in request/responses (defaults to 'false').", CommandOptionType.NoValue);
            _plugin           = Application.Option("-pl | --plugin", "Plugin name(s).", CommandOptionType.MultipleValue);
            _debug            = Application.Option("-d | --debug", "Wait for debugger to attach", CommandOptionType.NoValue);
        }
예제 #4
0
        static void Main(string[] args)
        {
            var app = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication
            {
                Name        = "VSS C# Project Tool",
                Description = "A tool to help with parsing a collection of C# projects, and filtering based on the contents."
            };

            app.HelpOption("-?|-h|--help");
            var directories = app.Option("-d|--directory", "Directories to search (allows multiple)", CommandOptionType.MultipleValue);
            var isRecursive = app.Option("-r|--recursive", "Recursive search, defaults to false", CommandOptionType.NoValue);

            app.OnExecute(() =>
            {
                app.ShowHelp();
                return(1);
            });

            TagsCommand(app, directories, isRecursive);

            ReferencesCommand(app, directories, isRecursive);

            app.Execute(args);
        }
예제 #5
0
        static int Main(string[] args)
        {
            var app     = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication();
            var cert    = app.Option("--cert", "cert file", CommandOptionType.SingleValue);
            var coreDll = app.Option("--core", "path to core dll", CommandOptionType.SingleValue);

            bool certExists()
            {
                return(File.Exists(cert.Value()));
            }

            bool coreExists()
            {
                return(File.Exists(coreDll.Value()));
            }

            bool verifyTopOptions()
            {
                return(!string.IsNullOrWhiteSpace(cert.Value()) &&
                       !string.IsNullOrWhiteSpace(coreDll.Value()) &&
                       certExists() && coreExists());
            }

            app.Command("interactive", config =>
            {
                string buff = "", licensetype = "", name = "", email = "", businessname = "";

                bool valid_guid = false, valid_installid = false;
                Guid guid       = new Guid(), installid = new Guid();

                config.OnExecute(() =>
                {
                    if (!verifyTopOptions())
                    {
                        if (!coreExists())
                        {
                            config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}");
                        }
                        if (!certExists())
                        {
                            config.Error.WriteLine($"Cant find certificate at: {cert.Value()}");
                        }

                        config.ShowHelp();
                        return(1);
                    }

                    WriteLine("Interactive license mode...");

                    while (licensetype == "")
                    {
                        WriteLine("What would you like to generate, a [u]ser license or an [o]rg license?");
                        buff = Console.ReadLine();

                        if (buff == "u")
                        {
                            licensetype = "user";
                            WriteLineOver("Okay, we will generate a user license.");

                            while (valid_guid == false)
                            {
                                WriteLine("Please provide the user's guid — refer to the Readme for details on how to retrieve this. [GUID]:");
                                buff = Console.ReadLine();

                                if (Guid.TryParse(buff, out guid))
                                {
                                    valid_guid = true;
                                }
                                else
                                {
                                    WriteLineOver("The user-guid provided does not appear to be valid.");
                                }
                            }
                        }
                        else if (buff == "o")
                        {
                            licensetype = "org";
                            WriteLineOver("Okay, we will generate an organization license.");

                            while (valid_installid == false)
                            {
                                WriteLine("Please provide your Bitwarden Install-ID — refer to the Readme for details on how to retrieve this. [Install-ID]:");
                                buff = Console.ReadLine();

                                if (Guid.TryParse(buff, out installid))
                                {
                                    valid_installid = true;
                                }
                                else
                                {
                                    WriteLineOver("The install-id provided does not appear to be valid.");
                                }
                            }

                            while (businessname == "")
                            {
                                WriteLineOver("Please enter a business name, default is BitBetter. [Business Name]:");
                                buff = Console.ReadLine();
                                if (buff == "")
                                {
                                    businessname = "BitBetter";
                                }
                                else if (checkBusinessName(buff))
                                {
                                    businessname = buff;
                                }
                            }
                        }
                        else
                        {
                            WriteLineOver("Unrecognized option \'" + buff + "\'. ");
                        }
                    }

                    while (name == "")
                    {
                        WriteLineOver("Please provide the username this license will be registered to. [username]:");
                        buff = Console.ReadLine();
                        if (checkUsername(buff))
                        {
                            name = buff;
                        }
                    }

                    while (email == "")
                    {
                        WriteLineOver("Please provide the email address for the user " + name + ". [email]");
                        buff = Console.ReadLine();
                        if (checkEmail(buff))
                        {
                            email = buff;
                        }
                    }

                    if (licensetype == "user")
                    {
                        WriteLineOver("Confirm creation of \"user\" license for username: \"" + name + "\", email: \"" + email + "\", User-GUID: \"" + guid + "\"? Y/n");
                        buff = Console.ReadLine();
                        if (buff == "" || buff == "y" || buff == "Y")
                        {
                            GenerateUserLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name, email, guid, null);
                        }
                        else
                        {
                            WriteLineOver("Exiting...");
                            return(0);
                        }
                    }
                    else if (licensetype == "org")
                    {
                        WriteLineOver("Confirm creation of \"organization\" license for business name: \"" + businessname + "\", username: \"" + name + "\", email: \"" + email + "\", Install-ID: \"" + installid + "\"? Y/n");
                        buff = Console.ReadLine();
                        if (buff == "" || buff == "y" || buff == "Y")
                        {
                            GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name, email, installid, businessname, null);
                        }
                        else
                        {
                            WriteLineOver("Exiting...");
                            return(0);
                        }
                    }

                    return(0);
                });
            });

            app.Command("user", config =>
            {
                var name      = config.Argument("Name", "your name");
                var email     = config.Argument("Email", "your email");
                var userIdArg = config.Argument("User ID", "your user id");
                var key       = config.Argument("Key", "your key id (optional)");
                var help      = config.HelpOption("--help | -h | -?");

                config.OnExecute(() =>
                {
                    if (!verifyTopOptions())
                    {
                        if (!coreExists())
                        {
                            config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}");
                        }
                        if (!certExists())
                        {
                            config.Error.WriteLine($"Cant find certificate at: {cert.Value()}");
                        }

                        config.ShowHelp();
                        return(1);
                    }
                    else if (string.IsNullOrWhiteSpace(name.Value) || string.IsNullOrWhiteSpace(email.Value))
                    {
                        config.Error.WriteLine($"Some arguments are missing: Name='{name.Value}' Email='{email.Value}'");
                        config.ShowHelp("user");
                        return(1);
                    }


                    if (string.IsNullOrWhiteSpace(userIdArg.Value) || !Guid.TryParse(userIdArg.Value, out Guid userId))
                    {
                        config.Error.WriteLine($"User ID not provided");
                        config.ShowHelp("user");
                        return(1);
                    }

                    GenerateUserLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name.Value, email.Value, userId, key.Value);

                    return(0);
                });
            });
            app.Command("org", config =>
            {
                var name         = config.Argument("Name", "your name");
                var email        = config.Argument("Email", "your email");
                var installId    = config.Argument("InstallId", "your installation id (GUID)");
                var businessName = config.Argument("BusinessName", "name For the organization (optional)");
                var key          = config.Argument("Key", "your key id (optional)");
                var help         = config.HelpOption("--help | -h | -?");

                config.OnExecute(() =>
                {
                    if (!verifyTopOptions())
                    {
                        if (!coreExists())
                        {
                            config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}");
                        }
                        if (!certExists())
                        {
                            config.Error.WriteLine($"Cant find certificate at: {cert.Value()}");
                        }

                        config.ShowHelp();
                        return(1);
                    }
                    else if (string.IsNullOrWhiteSpace(name.Value) ||
                             string.IsNullOrWhiteSpace(email.Value) ||
                             string.IsNullOrWhiteSpace(installId.Value))
                    {
                        config.Error.WriteLine($"Some arguments are missing: Name='{name.Value}' Email='{email.Value}' InstallId='{installId.Value}'");
                        config.ShowHelp("org");
                        return(1);
                    }

                    if (!Guid.TryParse(installId.Value, out Guid installationId))
                    {
                        config.Error.WriteLine("Unable to parse your installation id as a GUID");
                        config.Error.WriteLine($"Here's a new guid: {Guid.NewGuid()}");
                        config.ShowHelp("org");
                        return(1);
                    }

                    GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name.Value, email.Value, installationId, businessName.Value, key.Value);

                    return(0);
                });
            });

            app.OnExecute(() =>
            {
                app.ShowHelp();
                return(10);
            });

            app.HelpOption("-? | -h | --help");

            try
            {
                return(app.Execute(args));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Oops: {0}", e);
                return(100);
            }
        }
예제 #6
0
        static int Main(string[] args)
        {
            var app     = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication();
            var cert    = app.Option("--cert", "cert file", CommandOptionType.SingleValue);
            var coreDll = app.Option("--core", "path to core dll", CommandOptionType.SingleValue);

            bool certExists()
            {
                return(File.Exists(cert.Value()));
            }

            bool coreExists()
            {
                return(File.Exists(coreDll.Value()));
            }

            bool verifyTopOptions()
            {
                return(!string.IsNullOrWhiteSpace(cert.Value()) &&
                       !string.IsNullOrWhiteSpace(coreDll.Value()) &&
                       certExists() && coreExists());
            }

            app.Command("user", config =>
            {
                var name      = config.Argument("Name", "your name");
                var email     = config.Argument("Email", "your email");
                var userIdArg = config.Argument("User ID", "your user id");
                var key       = config.Argument("Key", "your key id (optional)");
                var help      = config.HelpOption("--help | -h | -?");

                config.OnExecute(() =>
                {
                    if (!verifyTopOptions())
                    {
                        if (!coreExists())
                        {
                            config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}");
                        }
                        if (!certExists())
                        {
                            config.Error.WriteLine($"Cant find certificate at: {cert.Value()}");
                        }

                        config.ShowHelp();
                        return(1);
                    }
                    else if (string.IsNullOrWhiteSpace(name.Value) || string.IsNullOrWhiteSpace(email.Value))
                    {
                        config.Error.WriteLine($"Some arguments are missing: Name='{name.Value}' Email='{email.Value}'");
                        config.ShowHelp("user");
                        return(1);
                    }


                    if (string.IsNullOrWhiteSpace(userIdArg.Value) || !Guid.TryParse(userIdArg.Value, out Guid userId))
                    {
                        config.Error.WriteLine($"User ID not provided");
                        config.ShowHelp("user");
                        return(1);
                    }

                    GenerateUserLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name.Value, email.Value, userId, key.Value);

                    return(0);
                });
            });
            app.Command("org", config =>
            {
                var name      = config.Argument("Name", "your name");
                var email     = config.Argument("Email", "your email");
                var installId = config.Argument("InstallId", "your installation id (GUID)");
                var key       = config.Argument("Key", "your key id (optional)");
                var help      = config.HelpOption("--help | -h | -?");

                config.OnExecute(() =>
                {
                    if (!verifyTopOptions())
                    {
                        if (!coreExists())
                        {
                            config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}");
                        }
                        if (!certExists())
                        {
                            config.Error.WriteLine($"Cant find certificate at: {cert.Value()}");
                        }

                        config.ShowHelp();
                        return(1);
                    }
                    else if (string.IsNullOrWhiteSpace(name.Value) ||
                             string.IsNullOrWhiteSpace(email.Value) ||
                             string.IsNullOrWhiteSpace(installId.Value))
                    {
                        config.Error.WriteLine($"Some arguments are missing: Name='{name.Value}' Email='{email.Value}' InstallId='{installId.Value}'");
                        config.ShowHelp("org");
                        return(1);
                    }

                    if (!Guid.TryParse(installId.Value, out Guid installationId))
                    {
                        config.Error.WriteLine("Unable to parse your installation id as a GUID");
                        config.Error.WriteLine($"Here's a new guid: {Guid.NewGuid()}");
                        config.ShowHelp("org");
                        return(1);
                    }

                    GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name.Value, email.Value, installationId, key.Value);

                    return(0);
                });
            });

            app.OnExecute(() =>
            {
                app.ShowHelp();
                return(10);
            });

            app.HelpOption("-? | -h | --help");

            try
            {
                return(app.Execute(args));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Oops: {0}", e);
                return(100);
            }
        }
예제 #7
0
        //<summary>
        //The constructor reads the arguments given to the program and checks if all the necesary ones are present before calling the connectNStream function.</summary>
        static void Main(string[] args)
        {
            var app = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication();

            app.Name = "";

            app.Description = "Exports the Logs to a json file.";
            app.HelpOption("-?|-h|--help");
            app.ExtendedHelpText = "following arguments are required -ApiKey, -LogId, -DateFrom and -DateTo";

            var apiKey = app.Option("-ApiKey|--ApiKey <ApiKey>",
                                    "Defines the API key. Ex \" -ApiKey 8890a01cdd9c403aac9a6f89829867f3\"",
                                    CommandOptionType.SingleValue);

            var filename = app.Option("-Filename|--Filename <Filename>",
                                      "Defines the path and filename of the file to export to. Ex \" -Filename C:\\myDirectory\\myFile.json\"",
                                      CommandOptionType.SingleValue);

            var logId = app.Option("-LogId|--LogId <LogId>",
                                   "Defines the log ID. Ex \" -LogId cfc710e7-06fb-4d30-be24-a96d5caf3d19\"",
                                   CommandOptionType.SingleValue);

            var dateFrom = app.Option("-DateFrom|--DateFrom <DateFrom>",
                                      "Defines the Date from which the logs start. Ex. \" -DateFrom 2017-10-24\"",
                                      CommandOptionType.SingleValue);

            var dateTo = app.Option("-DateTo|--DateTo <DateTo>",
                                    "Defines the Date to which the logs ends. Ex. \" -DateTo 2018-11-30\"",
                                    CommandOptionType.SingleValue);

            var query = app.Option("-Query|--Query <Query>",
                                   "Defines the query that is passed to the API",
                                   CommandOptionType.SingleValue);

            var includeHeadersOption = app.Option("-IncludeHeaders|--IncludeHeaders",
                                                  "Option for including the headers in output",
                                                  CommandOptionType.NoValue);

            app.OnExecute(() =>
            {
                int check = 0;
                if (apiKey.HasValue())
                {
                    check++;
                }
                else
                {
                    Console.WriteLine("You need to define an API key. Ex \" -ApiKey 8890a01cdd9c403aac9a6f89829867f3\"");
                }

                if (logId.HasValue())
                {
                    check++;
                }
                else
                {
                    Console.WriteLine("You need to define a log ID. Ex \" -LogId cfc710e7-06fb-4d30-be24-a96d5caf3d19\"");
                }

                if (check == 2)
                {
                    connectNStream(filename, apiKey.Value(), logId.Value(), dateFrom.Value(), dateTo.Value(), query.Value(), includeHeadersOption.HasValue());
                }

                return(0);
            });


            try
            {
                var result = app.Execute(args);
                Environment.Exit(result);
            }
            catch (CommandParsingException cpe)
            {
                Console.WriteLine("Couldn't pass your command try using -h to find out more");
                Console.WriteLine(cpe.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("An unexpected error occured try redefining your arguments or find help using -h");
                Console.WriteLine(e.Message);
            }
        }
예제 #8
0
        private static async Task MainAsync(string[] args)
        {
            var result = 0;

            Console.WriteLine("Message Sender Data Generator: usage: dotnet DataGenNetCore.dll sendmessages -t <default|telco> <slow|fast|faster|insane>");
            // docker background cannot handle the ESC
            //Console.WriteLine("Press ESC to stop");

            var app = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication(throwOnUnexpectedArg: false);

            app.Name = "Event Hub Data Generator";
            app.HelpOption("-? | -h | --help");

            var sendmessages = app.Command("sendmessages", s => {
                s.OnExecute(() => {
                    s.ShowHelp();                 //show help for sendmessages
                    return(1);                    //return error since we didn't do anything
                });
                s.HelpOption("-? | -h | --help"); //show help on --help
            });
            var optionMessageType = sendmessages.Option("-t | --message-type", "-t --message-type simple|telco", CommandOptionType.SingleValue);
            var optionVerbose     = sendmessages.Option("-v | --verbose", "-v --verbose", CommandOptionType.NoValue);

            sendmessages.Command("help", help => {
                help.Description = "get help!";
                help.OnExecute(() => {
                    sendmessages.ShowHelp("sendmessages");
                    return(1);
                });
            });
            sendmessages.Command("slow", slow => {
                slow.Description = "run message sending with 1 second thread sleep plus time of day delay (slow)";
                slow.HelpOption("-? | -h | --help");
                slow.OnExecute(async() => {
                    Console.WriteLine("using slow mode (1 message every ~five seconds, plus time of day delay, using thread.sleep)");
                    await sendMessages("slow", optionMessageType.Value(), optionVerbose.HasValue());
                    return(0);
                });
            });
            sendmessages.Command("fast", fast => {
                fast.Description = "run message sending with time of day delay only (fast)";
                fast.HelpOption("-? | -h | --help");
                fast.OnExecute(async() => {
                    Console.WriteLine("using fast mode (single thread, time of day delay)");
                    await sendMessages("fast", optionMessageType.Value(), optionVerbose.HasValue());
                    return(0);
                });
            });
            sendmessages.Command("faster", faster => {
                faster.Description = "run parallel for loop message sending (fastest)";
                faster.HelpOption("-? | -h | --help");
                faster.OnExecute(async() => {
                    Console.WriteLine("using faster mode (10 threads via parallel.for, time of day delay)");
                    await sendMessages("faster", optionMessageType.Value(), optionVerbose.HasValue());
                    return(0);
                });
            });
            sendmessages.Command("insane", insane => {
                insane.Description = "run parallel for loop message sending (insane)";
                insane.HelpOption("-? | -h | --help");
                insane.OnExecute(async() => {
                    Console.WriteLine("using insane mode (20 threads via parallel.for, no delay)");
                    await sendMessages("insane", optionMessageType.Value(), optionVerbose.HasValue());
                    return(0);
                });
            });



            try
            {
                var connectionStringBuilder = new EventHubsConnectionStringBuilder(secrets.EventHubConnectionString())
                {
                    EntityPath = secrets.EventHubPath()
                };

                hubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());
                app.Execute(args);
            }
            catch (Exception e)
            {
                app.HelpOption("-? | -h | --help");
                Console.WriteLine("Error occurred: {0}", e.Message);
            }
            Console.WriteLine("press any key to exit");
            Console.ReadKey();
            Environment.Exit(result);
        }
 public override void Configure(Microsoft.Extensions.CommandLineUtils.CommandLineApplication command)
 {
     base.Configure(command);
 }