示例#1
0
        private static bool ParseArgument(string[] args, ref int argIndex, ParameterSetter setter)
        {
            var name  = args[argIndex];
            var value = argIndex + 1 < args.Length ? args[argIndex + 1] : null;

            string?message = null;

            if (value != null && setter(value, out message))
            {
                argIndex++;
                return(true);
            }

            if (value == null || value.StartsWith("-") || ProcessingParameters.IsValueLikeToMkvFilePath(value))
            {
                Console.WriteLine("Invalid command-line arguments:");
                Console.WriteLine($"Option {name} must be followed by its value");
                return(false);
            }

            argIndex++;
            Console.WriteLine($"Invalid value \"{value}\" of command-line option {name}:");
            Console.WriteLine(message);
            return(false);
        }
示例#2
0
        private static ProcessingParameters?ParseCommandLineArguments(string[] args)
        {
            var parameters = new ProcessingParameters();

            for (var i = 0; i < args.Length; i++)
            {
                var arg = args[i].Trim();
                switch (arg.ToLowerInvariant())
                {
                case "-m":
                case "--mode":
                    if (!ParseArgument(args, ref i, parameters.TrySetCpuOnlyMode))
                    {
                        return(null);
                    }
                    break;

                case "-i":
                case "--implementation":
                    if (!ParseArgument(args, ref i, parameters.TrySetImplementation))
                    {
                        return(null);
                    }
                    break;

                case "-s":
                case "--startTime":
                    if (!ParseArgument(args, ref i, parameters.TrySetStartTime))
                    {
                        return(null);
                    }
                    break;

                case "-e":
                case "--endTime":
                    if (!ParseArgument(args, ref i, parameters.TrySetEndTime))
                    {
                        return(null);
                    }
                    break;

                default:
                    if (!parameters.TrySetMkvPath(arg, out var message))
                    {
                        Console.WriteLine($"Invalid command-line argument \"{arg}\":");
                        if (arg.StartsWith("-") && !ProcessingParameters.IsValueLikeToMkvFilePath(arg))
                        {
                            message = "Unknown option " + arg;
                        }
                        Console.WriteLine(message);
                        return(null);
                    }
                    break;
                }
            }

            return(parameters);
        }