Exemplo n.º 1
0
#pragma warning restore CC0052 // Make field readonly

        #endregion

        #region Constructors

        public CommandLineArgs()
        {
            CommandLine cmdLine = new(false);

            cmdLine.AddSwitch(nameof(this.Build), string.Empty, value => this.build = value);
            cmdLine.AddSwitch(nameof(this.Exit), string.Empty, value => this.exit   = value);
            cmdLine.AddValueHandler((value, errors) =>
            {
                this.project = TextUtility.StripQuotes(value);
                if (File.Exists(this.project))
                {
                    // Expand a short file name into a long one since the file name will be displayed in the title bar.
                    this.project = FileUtility.ExpandFileName(this.project);
                }
                else
                {
                    this.project = string.Empty;
                }
            });
            CommandLineParseResult parseResult = cmdLine.Parse();

            // Check for some invalid combinations
            if (parseResult != CommandLineParseResult.Valid ||
                (string.IsNullOrEmpty(this.project) && (this.build || this.exit)) ||
                (this.exit && !this.build))
            {
                this.showHelp = true;

                // If the arguments are stunk up, then reset all the data.
                this.project = string.Empty;
                this.build   = false;
                this.exit    = false;
            }
        }
        public void CLPR002()
        {
            // arrange
            // act
            var result = CommandLineParseResult.Failure("Error message");

            // assert
            result.IsFailure.Should().BeTrue();
            result.IsSuccess.Should().BeFalse();
            result.Error.Should().Be("Error message");
        }
Exemplo n.º 3
0
        public CommandLineArguments(string[] arguments)
        {
            _parser.Arguments.Add(_verboseArgument);
            _parser.Arguments.Add(_debugArgument);
            _parser.Arguments.Add(_cleanArgument);
            _parser.Arguments.Add(_consolelogArgument);
            _parser.Arguments.Add(_helpArgument);
            _parser.Arguments.Add(_quitArgument);
            _parser.Arguments.Add(_quitWaitArgument);
            _parser.Arguments.Add(_versionArgument);

            _parseResult = _parser.Parse(arguments);
        }
Exemplo n.º 4
0
        public void ParseHelpTest()
        {
            TestData               data    = new();
            CommandLine            cmdLine = CreateTester(data);
            CommandLineParseResult result  = cmdLine.Parse(new[] { "/?" });

            Assert.AreEqual(CommandLineParseResult.HelpRequested, result);
            string message = GetMessage(cmdLine);

            Assert.IsNotNull(message);
            Assert.IsTrue(message.StartsWith("Copies a source file to one or more target locations."), "Starts with 'Copies...'");
            Assert.IsTrue(message.EndsWith(Environment.NewLine), "Ends with newline.");
        }
Exemplo n.º 5
0
        public void ParseInvalidTest()
        {
            TestData               data    = new();
            CommandLine            cmdLine = CreateTester(data);
            CommandLineParseResult result  = cmdLine.Parse(new[] { "/Binary" });

            Assert.AreEqual(CommandLineParseResult.Invalid, result);
            string message = GetMessage(cmdLine);

            Assert.IsNotNull(message);
            Assert.IsTrue(message.Contains("A source file is required."), "Contains 'A source file is required.'");
            Assert.IsTrue(message.Contains("/Target"), "Contains '/Target'");
        }
        public void CLPR001()
        {
            // arrange
            var command = new Command("test");

            // act
            var result = CommandLineParseResult.Success(command, new ParameterValue[0], new ParameterValue[0]);

            // assert
            result.IsFailure.Should().BeFalse();
            result.IsSuccess.Should().BeTrue();
            result.Command.Should().BeSameAs(command);
        }
Exemplo n.º 7
0
        public void ParseValidTest()
        {
            TestData               data    = new();
            CommandLine            cmdLine = CreateTester(data);
            CommandLineParseResult result  = cmdLine.Parse(new[] { "/Prompt", "/V", "/bin", @"C:\Input.txt",
                                                                   @"/t:D:\ColonSeparated.txt", @"/Target", @"E:\SpaceSeparated.txt", @"/Targ=F:\EqualSeparated.txt" });

            Assert.AreEqual(CommandLineParseResult.Valid, result);
            Assert.AreEqual(true, data.prompt);
            Assert.AreEqual(true, data.verify);
            Assert.AreEqual(true, data.isBinary);
            Assert.AreEqual(@"C:\Input.txt", data.source);
            Assert.IsTrue(data.targets.Contains(@"D:\ColonSeparated.txt"), "Contains ColonSeparated");
            Assert.IsTrue(data.targets.Contains(@"E:\SpaceSeparated.txt"), "Contains SpaceSeparated");
            Assert.IsTrue(data.targets.Contains(@"F:\EqualSeparated.txt"), "Contains EqualSeparated");
        }
        public void SaveApplicationLegacyOptions()
        {
            var parsingResult = new CommandLineParseResult();

            var bamFolder = TestPaths.SharedBamDirectory;
            var applicationOptionsFile = Path.Combine(TestPaths.LocalScratchDirectory, "SomaticVariantCallerOptions1.used.json");

            if (File.Exists(applicationOptionsFile))
            {
                File.Delete(applicationOptionsFile);
            }

            var commandLine1   = string.Format("-minvq 40 -minbq 40 -BAMpaths {0} -t 1000 -g {1} -vqfilter 40", bamFolder, _existingGenome);
            var optionsParser1 = GetParsedAndValidatedApplicationOptions(commandLine1);

            optionsParser1.Options.Save(applicationOptionsFile);
            Assert.True(File.Exists(applicationOptionsFile));
        }
        public void SaveApplicationOptions()
        {
            var bamFolder = TestPaths.SharedBamDirectory;
            var applicationOptionsFile = Path.Combine(TestPaths.LocalScratchDirectory, "SomaticVariantCallerOptions2.used.json");

            if (File.Exists(applicationOptionsFile))
            {
                File.Delete(applicationOptionsFile);
            }

            var parsingResult = new CommandLineParseResult();
            var commandLine1  = string.Format("-MinVariantQScore 40 -MinBaseCallQuality 40 -BAMPaths {0} -MaxNumThreads 1000 -GenomePaths {1} -VariantQualityFilter 40", bamFolder, _existingGenome);

            var options = GetParsedOptions(commandLine1);

            options.Save(applicationOptionsFile);

            Assert.True(File.Exists(applicationOptionsFile));
        }
Exemplo n.º 10
0
        private int RunInternal(string[] args)
        {
            _log.Trace("Application starting.");

            // Parses command line without sanity checks.
            CommandLineParseResult parseResult = _parser.Parse(args);

            if (!parseResult.IsCorrect || !parseResult.Verb.HasValue)
            {
                _log.Error("Command line arguments incorrect.");
                return(1);
            }

            IVerbRunner verbRunner = CreateVerbRunner(parseResult.Verb.Value, parseResult.VerbOptions);

            verbRunner.Run();

            return(0);
        }
Exemplo n.º 11
0
        public CommandLineArgs(string[] args, IDock dock)
        {
            CommandLine parser = new CommandLine(false);

            parser.AddHeader("Usage: GizmoDock /asm Assembly.dll /type GizmoType [/inst InstanceName] [/ShowInTaskbar]");

            string assemblyName = null;

            parser.AddSwitch(
                new[] { "Assembly", "Asm" },
                "The name of the assembly.",
                (value, errors) =>
            {
                if (File.Exists(value))
                {
                    assemblyName = value;
                }
                else
                {
                    errors.Add("The specified assembly could not be found.");
                }
            });

            string typeName = null;

            parser.AddSwitch(
                "Type",
                "The Gizmo-derived class to load.",
                (value, errors) => typeName = value);

            string instanceName = null;

            parser.AddSwitch(
                "Instance",
                "The name for this Gizmo instance.",
                (value, errors) => instanceName = value);

            parser.AddSwitch(
                nameof(this.ShowInTaskbar),
                "Whether the gizmo should show in the Windows taskbar.  Defaults to false.",
                value => this.ShowInTaskbar = value);

            parser.AddSwitch(nameof(this.CloseAll), "Closes all running GizmoDock instances.  Defaults to false.", value => this.CloseAll = value);

            parser.AddFinalValidation(errors =>
            {
                if (!string.IsNullOrEmpty(assemblyName) && !string.IsNullOrEmpty(typeName))
                {
                    this.Gizmo = Gizmo.Create(dock, assemblyName, typeName, instanceName, errors);
                }
            });

            CommandLineParseResult parseResult = parser.Parse(args);

            if (parseResult != CommandLineParseResult.Valid)
            {
                // Clean up any gizmo we've already created because we're going to replace it with a MessageGizmo.
                if (this.Gizmo is IDisposable disposable)
                {
                    disposable.Dispose();
                }

                // Pass an empty array so Gizmo.Create can't add any errors to it.  It should never need to.
                MessageGizmo messageGizmo = (MessageGizmo)Gizmo.Create(dock, typeof(MessageGizmo), null, CollectionUtility.EmptyArray <string>());
                messageGizmo.Message        = parser.CreateMessage().Trim();
                messageGizmo.IsErrorMessage = parseResult != CommandLineParseResult.HelpRequested;
                this.Gizmo = messageGizmo;
            }
            else if (this.Gizmo == null && !this.CloseAll)
            {
                // If there were no errors, no gizmo, and the command line was valid, then the command line
                // was probably empty, so we'll show the ShortcutCreator gizmo as the default.
                this.Gizmo         = Gizmo.Create(dock, typeof(ShortcutCreatorGizmo), null, CollectionUtility.EmptyArray <string>());
                this.ShowInTaskbar = true;
            }
        }
Exemplo n.º 12
0
 public static CommandLineParseResultAssertions  Should(this CommandLineParseResult value) => new CommandLineParseResultAssertions(value);