示例#1
0
        public void Run(params string[] args)
        {
            try
            {
                // Initialize
                Console.WriteLine();
                Console.WriteLine("EvolutionNet Project Generator");
                Console.WriteLine();

                // Create the command argument
                var command = new ArgumentCommand("project", "Project to be created.", CreateProject);
                // Create the options arguments
                var options = new List <ArgumentOption>();
                var basePathOptionArguments = new List <ArgumentInternal>();
                basePathOptionArguments.Add(new ArgumentInternal("path", "Absolute path."));
                var basePathOption = new ArgumentOption("basepath", "b", "Base path for project creation.", basePathOptionArguments, SetBasePathOption);
                options.Add(basePathOption);
                // Create the CommandLineHelper (for processing the arguments)
                commandLineHelper = new CommandLineHelper(command, options, ShowHelp, GetProjectName);
                commandLineHelper.Process(args);

                // Finalize
                Console.WriteLine("SUCCESS: Project(s) created!");
            }
            catch (Exception ex)
            {
                // Write errors to screen
                Console.WriteLine("ERRORS:");
                Console.WriteLine("{0}", ex.Message);
                Console.WriteLine();
            }
            finally
            {
                Console.Write("Press any key to continue");
                Console.ReadKey();
            }
        }
示例#2
0
        public bool InitializeFromCommandLine(string[] args)
        {
            currentOption = null;

            foreach (string arg in args)
            {
                ArgumentOption nextOption = getOptionHandler(arg);
                if (nextOption != null)
                {
                    currentOption = nextOption;

                    if (currentOption.activator != null)
                        currentOption.activator(this);

                    continue;
                }

                if (currentOption == null)
                {
                    PrintShortUsage(true);
                    return false;
                }

                if (currentOption.handler != null)
                {
                    currentOption.handler(this, arg);
                }
                else
                {
                    throw new SettingsException("Unexpected argument for option '" + currentOption.key + "'");
                }
            }

            if (settingsFile != null)
            {
                ReadSettingsFile();
            }
            else if (generateSettingsFileName != null)
            {
                GenerateSettingsFile();
                return false;
            }
            bool showShort = true;
            if (printLongHelp)
            {
                showShort = false;
                PrintVersion();
                PrintShortUsage(false);
                PrintLongUsage();
            }
            else if (printVersion)
            {
                PrintVersion();
            }

            if (!string.IsNullOrEmpty(TargetPath))
                return true;

            if (showShort)
            {
                PrintShortUsage(true);
            }
            return false;
        }
示例#3
0
        public bool InitializeFromCommandLine(string[] args)
        {
            currentOption = null;

            foreach (string arg in args)
            {
                ArgumentOption nextOption = getOptionHandler(arg);
                if (nextOption != null)
                {
                    currentOption = nextOption;

                    if (currentOption.activator != null)
                    {
                        currentOption.activator(this);
                    }

                    continue;
                }

                if (currentOption == null)
                {
                    PrintShortUsage(true);
                    return(false);
                }

                if (currentOption.handler != null)
                {
                    currentOption.handler(this, arg);
                }
                else
                {
                    throw new SettingsException("Unexpected argument for option '" + currentOption.key + "'");
                }
            }

            if (settingsFile != null)
            {
                ReadSettingsFile();
            }
            else if (generateSettingsFileName != null)
            {
                GenerateSettingsFile();
                return(false);
            }
            bool showShort = true;

            if (printLongHelp)
            {
                showShort = false;
                PrintVersion();
                PrintShortUsage(false);
                PrintLongUsage();
            }
            else if (printVersion)
            {
                PrintVersion();
            }

            if (!string.IsNullOrEmpty(TargetPath))
            {
                return(true);
            }

            if (showShort)
            {
                PrintShortUsage(true);
            }
            return(false);
        }
示例#4
0
        private static void AnalyzeArguments(string[] arguments)
        {
            ArgumentOption option = ArgumentOption.Initial;

            string arg;

            foreach (string argument in arguments)
            {
                if (option != ArgumentOption.Fractal)
                {
                    arg = argument.ToUpperInvariant();
                }
                else
                {
                    arg = argument;
                }

                switch (option)
                {
                case ArgumentOption.Initial:
                {
                    switch (arg.ToUpperInvariant())
                    {
                    case "-ASYNC":
                        option = ArgumentOption.Async;
                        break;

                    case "-CIMAG":
                        option = ArgumentOption.CImaginary;
                        break;

                    case "-CREAL":
                        option = ArgumentOption.CReal;
                        break;

                    case "-DEPTH":
                        option = ArgumentOption.Depth;
                        break;

                    case "-FRACTAL":
                        option = ArgumentOption.Fractal;
                        break;

                    case "-HEIGHT":
                        option = ArgumentOption.Height;
                        break;

                    case "-H":
                    case "-HELP":
                        Log.HelpAndExit();
                        break;

                    case "-ITERATIONS":
                        option = ArgumentOption.MaxIterations;
                        break;

                    case "-LIGHT":
                        option = ArgumentOption.Light;
                        break;

                    case "-MIX":
                        option = ArgumentOption.MixPaletteFile;
                        break;

                    case "-OUTPUT":
                        option = ArgumentOption.OutputFile;
                        break;

                    case "-PALETTE":
                        option = ArgumentOption.PaletteFile;
                        break;

                    case "-RADIUS":
                        option = ArgumentOption.Radius;
                        break;

                    case "-WIDTH":
                        option = ArgumentOption.Width;
                        break;

                    case "-XCENTER":
                        option = ArgumentOption.XCenter;
                        break;

                    case "-YCENTER":
                        option = ArgumentOption.YCenter;
                        break;

                    case "-ZOOM":
                        option = ArgumentOption.Zoom;
                        break;

                    default:
                        throw new ArgumentException($"Unrecognized option: {arg}");
                    }

                    break;
                }

                case ArgumentOption.Async:
                {
                    TryParseBool("Async", arg, out bool b);
                    Async  = b;
                    option = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.CImaginary:
                {
                    TryParseDouble("C imaginary", arg, out double d);
                    CImaginary = d;
                    option     = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.CReal:
                {
                    TryParseDouble("C real", arg, out double d);
                    CReal  = d;
                    option = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.Depth:
                {
                    Depth = arg switch
                    {
                        "8" => Depths.Bits8,
                        "24" => Depths.Bits24,
                        "32" => Depths.Bits32,
                        _ => throw new ArgumentException($"The passed Depth value is not supported: {arg}."),
                    };
                    option = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.Fractal:
                {
                    if (!Enum.TryParse(arg, out FractalVariations f) || f == FractalVariations.Unspecified)
                    {
                        throw new ArgumentException($"The passed Fractal Variation value is not supported: {arg}.");
                    }
                    FractalVariation = f;
                    option           = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.Height:
                {
                    TryParseInt("Height", arg, out int i);
                    if (i <= 0)
                    {
                        throw new ArgumentException($"The passed Height value should be greater than zero: {arg}.");
                    }
                    Height = i;
                    option = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.MaxIterations:
                {
                    TryParseULong("Iterations", arg, out ulong i);
                    if (i <= 0)
                    {
                        throw new ArgumentException($"The passed Iterations value should be greater than zero: {arg}.");
                    }
                    MaxIterations = i;
                    option        = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.Light:
                {
                    TryParseDouble("Light", arg, out double d);
                    if (d < 0.0 || d > 1.0)
                    {
                        throw new ArgumentException($"The passed Light value should be greater than zero and less than 1: {arg}.");
                    }
                    Light  = d;
                    option = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.MixPaletteFile:
                {
                    string path = Path.Combine(AbsolutePathPalettes, arg);
                    if (!File.Exists(path))
                    {
                        throw new ArgumentException($"The passed Mix Palette File does not exist: {path}.");
                    }
                    if (PaletteFileName == arg)
                    {
                        throw new ArgumentException($"The passed Mix Palette File ({arg}) cannot be the same as the Palette File ({PaletteFileName}).");
                    }
                    MixPaletteFileName = arg;
                    option             = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.OutputFile:
                {
                    if (string.IsNullOrWhiteSpace(arg))
                    {
                        throw new ArgumentException("The passed Output File Name cannot be empty.");
                    }
                    OutputFileName = arg;
                    option         = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.PaletteFile:
                {
                    string path = Path.Combine(AbsolutePathPalettes, arg);
                    if (!File.Exists(path))
                    {
                        throw new ArgumentException($"The passed Palette File does not exist: {path}");
                    }
                    if (MixPaletteFileName != string.Empty)
                    {
                        if (MixPaletteFileName == arg)
                        {
                            throw new ArgumentException($"The passed Palette File ({arg}) cannot be the same as the Mixed Palette File ({MixPaletteFileName}).");
                        }
                    }
                    PaletteFileName = arg;
                    option          = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.Radius:
                {
                    TryParseDouble("Radius", arg, out double d);
                    Radius = d;
                    option = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.Width:
                {
                    TryParseInt("Width", arg, out int d);
                    if (d <= 0)
                    {
                        throw new ArgumentException($"The passed Width value should be greater than zero: {d}");
                    }
                    Width  = d;
                    option = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.XCenter:
                {
                    TryParseDouble("X Center", arg, out double d);
                    XCenter = d;
                    option  = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.YCenter:
                {
                    TryParseDouble("Y Center", arg, out double d);
                    YCenter = d;
                    option  = ArgumentOption.Initial;
                    break;
                }

                case ArgumentOption.Zoom:
                {
                    TryParseDouble("Zoom", arg, out double d);
                    Zoom   = (d != 0.0) ? d : throw new ArgumentException("Cannot set zoom to zero.");
                    option = ArgumentOption.Initial;
                    break;
                }
                }
            }

            if (option != ArgumentOption.Initial)
            {
                throw new ArgumentException($"An argument was specified without a value.");
            }
        }