Advtools.ADVpki.ProgramOptions.ParseCommandLine C# (CSharp) Метод

ParseCommandLine() публичный Метод

Parse the command-line arguments
public ParseCommandLine ( string args ) : bool
args string Command-line arguments
Результат bool
        public bool ParseCommandLine(string[] args)
        {
            try
            {
                // Parse the command-line arguments (thanks NDesk!)
                List<string> extra = options_.Parse(args);
                // If there are some arguments not parsed, no name of pipe or an invalid port number, show the help
                if(extra.Count > 0)
                {
                    Console.WriteLine("Unknow parameter: {0}", extra[0]);
                    Console.WriteLine();
                    ShowUsage();
                    return false; // Do not continue the application
                }
            }
            catch(OptionException e)
            {
                // Something wrong with the arguments
                Console.WriteLine(e.Message);
                Console.WriteLine("Try 'ADVpki --help' for more information.");
                return false;
            }

            // Show the help?
            if(Help)
            {
                ShowUsage();
                return false;
            }

            // Continue the application
            return true;
        }

Usage Example

Пример #1
0
        private static ProgramOptions ParseCommandLine(string[] args)
        {
            ProgramOptions options = new ProgramOptions();
            if(!options.ParseCommandLine(args))
                return null;

            if(string.IsNullOrWhiteSpace(options.AuthorityName) && options.Usage != CertificatesAuthority.Usage.Authority)
            {
                Console.WriteLine("Invalid name of the certificate authority");
                Console.WriteLine();
                options.ShowUsage();
                return null;
            }

            if(string.IsNullOrWhiteSpace(options.CertificateName) && string.IsNullOrWhiteSpace(options.Pkcs10File))
            {
                Console.WriteLine("Please provide a name for the certificate or the name of a PKCS#10 file");
                Console.WriteLine();
                options.ShowUsage();
                return null;
            }

            if(!string.IsNullOrWhiteSpace(options.CertificateName) && !string.IsNullOrWhiteSpace(options.Pkcs10File))
            {
                Console.WriteLine("Please provide either a name for the certificate or the name of a PKCS#10 file but not both");
                Console.WriteLine();
                options.ShowUsage();
                return null;
            }

            return options;
        }
All Usage Examples Of Advtools.ADVpki.ProgramOptions::ParseCommandLine