Exemple #1
0
        private static void ReadSwitchArguments(
            Action <LogType?, string[]> loggerCallback,
            IEnumerable <string> args,
            UserArguments userArguments,
            Queue <string> argsQueue
            )
        {
            foreach (var arg in args)
            {
                switch (arg)
                {
                case "verbose":
                case "v":
                    userArguments.Verbose = true;
                    break;

                case "image":
                case "i":
                    if (argsQueue.Count < 1)
                    {
                        UsageAndExit(loggerCallback, @"File switch wasn't provided a file name (ex: C:\gecko.bmp)");
                    }
                    userArguments.ImageFile = argsQueue.Dequeue();
                    break;

                case "fit":
                case "f":
                    if (argsQueue.Count < 1)
                    {
                        UsageAndExit(loggerCallback, "Visual Studio switch wasn't provided a version number (ex: 2017).");
                    }
                    var fit = argsQueue.Dequeue().ToLower();
                    userArguments.Style = fit switch
                    {
                        "fill" => Wallpaper.Style.Fill,
                        "fit" => Wallpaper.Style.Fit,
                        "stretch" => Wallpaper.Style.Stretch,
                        "center" => Wallpaper.Style.Center,
                        "span" => Wallpaper.Style.Span,
                        _ => Wallpaper.Style.Tile,
                    };
                    break;

                case "help":
                case "?":
                    UsageAndExit(loggerCallback);
                    break;

                default:
                    UsageAndExit(loggerCallback, $"Unknown argument: {arg}");
                    break;
                }
            }
        }
Exemple #2
0
        private static void ReadNonSwitchArgument(Action <LogType?, string[]> loggerCallback, ref UserArguments userArguments, string arg)
        {
            if (userArguments.ImageFile != null)
            {
                UsageAndExit(loggerCallback,
                             $"Only one image file argument is allowed. Two were provided: {userArguments.ImageFile}, {arg}");
            }

            if (!File.Exists(arg))
            {
                throw new FileNotFoundException($"File could not be found: {arg}");
            }

            userArguments.ImageFile = arg;
        }