Exemplo n.º 1
0
        public void RegisterCommandT_ShouldPassEnvironmentVariableToExecute_IfEnvironemntVariableIsSet()
        {
            var testEnvironment = new TestEnvironment()
                                  .SetEnvironmentVariable("NFLAG_TEST_OPTION1", "54")
                                  .SetEnvironmentVariable("NFLAG_TEST_FLAG1", "false")
                                  .SetEnvironmentVariable("NFLAG_TEST_PARAMETER2", "89");

            ArgumentsType a = null;

            Cli
            .Configure(c => c
                       .SetDialect(Dialect.Gnu)
                       .SetEnvironment(testEnvironment)
                       )
            .Root <ArgumentsType>(c => c
                                  .RegisterCommand <ArgumentsType>("sub", "sub command ", rc => rc
                                                                   .SetExecute((args, output) =>
            {
                a = args;
            }))
                                  .SetExecute((type, output) => { })
                                  )
            .Run(new[] { "sub" });

            Assert.Equal(54, a.Option1);
            Assert.Equal("asd", a.Option2);
            Assert.False(a.Flag1);
            Assert.False(a.Flag2);
            Assert.Equal(1.1, a.Parameter1);
            Assert.Equal(89, a.Parameter2);
            Assert.Empty(a.ParameterSeries);
        }
Exemplo n.º 2
0
        public void RegisterCommandT_ShouldPassDefaultValuesToExecute()
        {
            ArgumentsType a = null;

            Cli
            .Configure(c => c
                       .SetDialect(Dialect.Gnu)
                       )
            .Root <ArgumentsType>(c => c
                                  .RegisterCommand <ArgumentsType>("sub", "sub command ", rc => rc
                                                                   .SetExecute((args, output) =>
            {
                a = args;
            }))
                                  .SetExecute((type, output) => { })
                                  )
            .Run(new[] { "sub" });

            Assert.Equal(1, a.Option1);
            Assert.Equal("asd", a.Option2);
            Assert.True(a.Flag1);
            Assert.False(a.Flag2);
            Assert.Equal(1.1, a.Parameter1);
            Assert.Equal(1, a.Parameter2);
            Assert.Empty(a.ParameterSeries);
        }
Exemplo n.º 3
0
        private void ReadArgumentsFile()
        {
            if (ArgumentsType == null)
            {
                Arguments = new WorkerArguments();
                return;
            }

            if (CurrentLogWriter != null)
            {
                CurrentLogWriter.DebugFormat("Reading Arguments");
            }

            var settings   = ArgumentsType.GetSharpSerializerXmlSettings(WorkerArguments.ArgumentsFileRootName);
            var serializer = new SharpSerializer(settings);

            Arguments = (WorkerArguments)serializer.Deserialize(Path.Combine(ArgumentDirectoryPath, ArgumentFileName));
        }
Exemplo n.º 4
0
        public void RegisterCommandT_ShouldNotReadFlagEnvironmentVariable_IfSetAfterInitialization()
        {
            var testEnvironment = new TestEnvironment();

            ArgumentsType commandArgs = null;

            Cli
            .Configure(c => c
                       .SetDialect(Dialect.Gnu)
                       .SetEnvironment(testEnvironment)
                       )
            .Root <ArgumentsType>(c => c
                                  .SetExecute((args, output) => { commandArgs = args; })
                                  )
            .Run(new string[0]);

            testEnvironment
            .SetEnvironmentVariable("NFLAG_TEST_FLAG1", "false");

            Assert.True(commandArgs.Flag1);
        }
Exemplo n.º 5
0
        public void RegisterCommandT_ShouldNotReadParameterEnvironmentVariable_IfSetAfterInitialization()
        {
            var testEnvironment = new TestEnvironment();

            ArgumentsType commandArgs = null;

            Cli
            .Configure(c => c
                       .SetDialect(Dialect.Gnu)
                       .SetEnvironment(testEnvironment)
                       )
            .Root <ArgumentsType>(c => c
                                  .SetExecute((args, output) => { commandArgs = args; })
                                  )
            .Run(new string[0]);

            testEnvironment
            .SetEnvironmentVariable("NFLAG_TEST_PARAMETER2", "env_p");

            Assert.Equal(1, commandArgs.Parameter2);
        }
Exemplo n.º 6
0
        public void RegisterCommandT_ShouldPassValuesToExecute()
        {
            ArgumentsType a = null;

            Cli
            .Configure(c => c
                       .SetDialect(Dialect.Gnu)
                       )
            .Root <ArgumentsType>(c => c
                                  .RegisterCommand <ArgumentsType>("sub", "sub command ", rc => rc
                                                                   .SetExecute((args, output) =>
            {
                a = args;
            }))
                                  .SetExecute((type, output) => { })
                                  )
            .Run(new[]
            {
                "sub",
                "--flag1",
                "-f2",
                "--option1",
                "3",
                "-o2",
                "xyz",
                2.53.ToString(CultureInfo.CurrentCulture),
                "5",
                "6",
                "7"
            });

            Assert.Equal(3, a.Option1);
            Assert.Equal("xyz", a.Option2);
            Assert.False(a.Flag1);
            Assert.True(a.Flag2);
            Assert.Equal(2.53, a.Parameter1);
            Assert.Equal(5, a.Parameter2);
            Assert.Equal(new[] { 6, 7 }, a.ParameterSeries);
        }