Example #1
0
        public string GetComposeVersion()
        {
            string version;

            var output = _cliCompose.Execute("-v");

            version = output.StandardOutput;

            return(version);
        }
        public void Commands_Model_InvalidMethodSignature_ManyArgs()
        {
            string[] args = { "C1" };

            Assert.Throws <InvalidModelException>(
                () => Cli.Execute <CommandModel_MethodSig_ManyArgs>(args));
        }
        public void Commands_Model_MultipleDefaults()
        {
            string[] args = new string[] { };

            Assert.Throws <InvalidModelException>(
                () => Cli.Execute <CommandModel_TwoDefaults>(args));
        }
        public void Commands_Model_DuplicateNames()
        {
            string[] args = new string[] { };

            Assert.Throws <InvalidModelException>(
                () => Cli.Execute <CommandModel_DuplicateNames>(args));
        }
Example #5
0
        private static void ExecuteCommand(IDictionary <string, ValueObject> param, StringBuilder batString, string command, Dictionary <string, string> tokens)
        {
            foreach (var token in tokens)
            {
                command = command.Replace(token.Key, token.Value);
            }


            if (param["--bat"] != null)
            {
                batString.AppendLine(command);
            }
            else
            {
                // Execute each batch

                using (var cli = new Cli("cmd"))
                {
                    var handler = new BufferHandler(
                        stdOutLine => Console.WriteLine(stdOutLine),
                        stdErrLine => Console.WriteLine(stdErrLine));

                    Console.WriteLine(string.Empty);

                    Console.WriteLineFormatted($@"Executing: ", Color.CadetBlue);
                    Console.WriteLineFormatted("    " + command, Color.White);
                    Console.WriteLine(string.Empty);

                    cli.Execute($@"/c ""{command}""", bufferHandler: handler);
                }
            }
        }
 protected override void Go(string[] args)
 {
     while (true)
     {
         _cli.Execute(Console.ReadLine());
     }
 }
        public void Commands_ExecuteCommand_NoDefaults()
        {
            string[] args = { "C1" };

            Assert.Throws <CommandExecutedException>(
                "C1",
                () => Cli.Execute <CommandModel_NoDefaults>(args));
        }
        public void Commands_ExecuteNothing_WithDefaults()
        {
            string[] args = { };

            Assert.Throws <CommandExecutedException>(
                "C2",
                () => Cli.Execute <CommandModel_Defaults>(args));
        }
        public void Commands_ExecuteHelp_OtherArgs()
        {
            string[] args = { "--help", "some", "other", "arguments" };

            Assert.Throws <CommandExecutedException>(
                "HELP",
                () => Cli.Execute <CommandModel_Help>(args));
        }
        public void Commands_ExecuteHelp()
        {
            string[] args = { "--help" };

            Assert.Throws <CommandExecutedException>(
                "HELP",
                () => Cli.Execute <CommandModel_Help>(args));
        }
        public void Commands_Model_ValidMethodSignature_CorrectArgs()
        {
            string[] args = { "C1" };

            Assert.Throws <CommandExecutedException>(
                "C1",
                () => Cli.Execute <CommandModel_NoDefaults>(args));
        }
Example #12
0
 public void Execute_Sleep_CancelLate_Test()
 {
     using (var cli = new Cli(_sleepBat))
         using (var cts = new CancellationTokenSource())
         {
             cts.CancelAfter(TimeSpan.FromSeconds(1));
             Assert.Throws <OperationCanceledException>(() => cli.Execute(cts.Token));
         }
 }
Example #13
0
        public void work_items_arg_should_launch_code_uri()
        {
            var cli = new Cli(vsts, adapter);

            var execute = cli.Execute(CommandName.Browse, CommandName.WorkItems);

            Assert.Equal(0, execute);
            A.CallTo(() => vsts.BrowseWorkItemsUri()).MustHaveHappened();
        }
Example #14
0
 public void Command_RequiredArguments_NotProvided()
 {
     string[] args =
     {
         "Main"
     };
     Assert.Throws <RequiredException>(
         () => Cli.Execute <CommandModel_RequiredOptions>(args));
 }
Example #15
0
 public void Command_RequiredArguments_HelpGenerator()
 {
     string[] args =
     {
         "Main", "--help"
     };
     Assert.Throws <Arguments.Helpers.HelpTriggeredSuccessException>(
         () => Cli.Execute <CommandModel_RequiredOptions>(args));
 }
Example #16
0
 public void Execute_Sleep_CancelEarly_Test()
 {
     using (var cli = new Cli(_sleepBat))
         using (var cts = new CancellationTokenSource())
         {
             cts.Cancel();
             Assert.Throws <OperationCanceledException>(() => cli.Execute(cts.Token));
         }
 }
        public void Commands_ExecuteUnknown_Options()
        {
            string[] args     = { "--option", "value", "operand1" };
            string[] expected = { "--option", "value", "operand1" };

            Assert.Throws <CommandExecutedException>(
                "C2 " + string.Join(" ", expected),
                () => Cli.Execute <CommandModel_Executable>(args));
        }
Example #18
0
        public void Execute_NeverEnding_CancelLate_Test()
        {
            var cli = new Cli(NeverEndingBat);

            var cts = new CancellationTokenSource();

            cts.CancelAfter(TimeSpan.FromSeconds(1));

            Assert.ThrowsException <OperationCanceledException>(() => cli.Execute(cts.Token));
        }
        public void CommandException_InspectStacktrace()
        {
            var e = Assert.Throws <DivideByZeroException>(
                () => Cli.Execute <CommandModel_ExceptionThrow>(new string[] { }));

            for (int i = 1; i <= 4; i++)
            {
                Assert.Contains($"Layer{i}", e.StackTrace, StringComparison.CurrentCultureIgnoreCase);
            }
        }
Example #20
0
        public void Execute_NeverEnding_CancelEarly_Test()
        {
            var cli = new Cli(NeverEndingBat);

            var cts = new CancellationTokenSource();

            cts.Cancel();

            Assert.ThrowsException <OperationCanceledException>(() => cli.Execute(cts.Token));
        }
Example #21
0
        public void CancelAll_AfterExecute_Sleep_Test()
        {
            using (var cli = new Cli(_sleepBat))
            {
                // Kill after some time
                Task.Delay(TimeSpan.FromSeconds(1)).ContinueWith(_ => cli.CancelAll());

                // Execute
                Assert.Throws <OperationCanceledException>(() => cli.Execute());
            }
        }
Example #22
0
        public void Command_RequiredArguments_OK()
        {
            string[] args =
            {
                "Main", "--my-option=true"
            };
            var e = Assert.Throws <CommandExecutedException>(
                () => Cli.Execute <CommandModel_RequiredOptions>(args));

            Assert.Equal(true.ToString(), e.ParamName);
        }
Example #23
0
        public void Execute_ThrowError_Test()
        {
            var cli = new Cli(ThrowErrorBat);

            var output = cli.Execute();
            var ex     = Assert.ThrowsException <StandardErrorException>(() => output.ThrowIfError());

            Assert.IsNotNull(output);
            Assert.AreEqual(14, output.ExitCode);
            Assert.AreEqual("", output.StandardOutput.TrimEnd());
            Assert.AreEqual("Hello world", output.StandardError.TrimEnd());
            Assert.AreEqual(output.StandardError, ex.StandardError);
        }
Example #24
0
        public void Execute_EchoStdin_Empty_Test()
        {
            var cli = new Cli(EchoStdinBat);

            var output = cli.Execute();

            output.ThrowIfError();

            Assert.IsNotNull(output);
            Assert.AreEqual(14, output.ExitCode);
            Assert.AreEqual("ECHO is off.", output.StandardOutput.TrimEnd());
            Assert.AreEqual("", output.StandardError.TrimEnd());
        }
Example #25
0
        public void Execute_EchoArgs_Test()
        {
            var cli = new Cli(EchoArgsBat);

            var output = cli.Execute("Hello world");

            output.ThrowIfError();

            Assert.IsNotNull(output);
            Assert.AreEqual(14, output.ExitCode);
            Assert.AreEqual("Hello world", output.StandardOutput.TrimEnd());
            Assert.AreEqual("", output.StandardError.TrimEnd());
        }
Example #26
0
 public string GetMp4FrameCount(string fileName)
 {
     using (var cli = new Cli("./ffprobe.exe"))
     {
         var output = cli.Execute($"-i {fileName} -show_streams -hide_banner");
         var sout   = output.StandardOutput;
         if (!string.IsNullOrEmpty(sout))
         {
             return(GetBeforeBr(sout, "nb_frames="));
         }
     }
     return(null);
 }
Example #27
0
        private void threadGenerate(object obj)
        {
            String selectedFileName = obj.ToString();


            Cli c = new Cli(this);

            if (string.IsNullOrEmpty(selectedFileName))
            {
                c.Execute(backupPrivateKeyPrefix + (System.DateTime.UtcNow.ToUniversalTime().Ticks / 10000000).ToString());
                c.Execute(nrfutilCommandGeneratePrivateKey);
            }


            c.Execute(nrfutilCommandGeneratePublicKey);

            Process proc = new Process();

            proc.StartInfo.FileName  = "explorer";
            proc.StartInfo.Arguments = @"/select," + System.Windows.Forms.Application.ExecutablePath;
            proc.Start();
        }
Example #28
0
        static void Main(string[] args)
        {
            var cli        = new Cli();
            var current_db = cli.GetCurrentDB();

            // byte[] bytearray = new byte[16];

            // var bitArray = new BitArray(bytearray);

            // Console.WriteLine($"bit 8 {bitArray.Get(8)}");
            // bitArray.Set(8, true);
            // Console.WriteLine($"bit 8 {bitArray.Get(8)}");

            //  ((ICollection)bitArray).CopyTo(bytearray, 0);

            //  bitArray = new BitArray(bytearray);

            // Console.WriteLine($"bit 8 {bitArray.Get(8)}");
            // Console.WriteLine($"bitArray length = {bitArray.Length}");

            // Console.WriteLine($"sizeof int {sizeof(int)} \nsizeof char {sizeof(char)} \nsizeof double {sizeof(double)}");

            Console.WriteLine($"--> {(Convert.ToByte(true)) == '\0'}");

            string input;

            string[] arguments;

            while (true)
            {
                Console.Write($"{current_db}>");
                input     = "";
                arguments = new string[] {};
                input     = Console.ReadLine();
                arguments = input.Split(' ');
                if (input.ToLower() == "exit")
                {
                    break;
                }
                else
                {
                    cli.Execute(arguments);
                    Console.WriteLine();
                    current_db = cli.GetCurrentDB();
                }
            }

            cli.Dispose();
            Console.WriteLine("Bye bye!");
        }
Example #29
0
        public void Execute_EchoStdin_Test()
        {
            var cli = new Cli(EchoStdinBat);

            var input  = new ExecutionInput(standardInput: "Hello world");
            var output = cli.Execute(input);

            output.ThrowIfError();

            Assert.IsNotNull(output);
            Assert.AreEqual(14, output.ExitCode);
            Assert.AreEqual("Hello world", output.StandardOutput.TrimEnd());
            Assert.AreEqual("", output.StandardError.TrimEnd());
        }
Example #30
0
        public void Execute_EchoStdinToStdout_Empty_Test()
        {
            using (var cli = new Cli(_echoStdinToStdoutBat))
            {
                var output = cli.Execute();
                output.ThrowIfError();

                Assert.That(output, Is.Not.Null);
                Assert.That(output.ExitCode, Is.EqualTo(TestExitCode));
                Assert.That(output.StandardOutput.TrimEnd(), Is.EqualTo("ECHO is off."));
                Assert.That(output.StandardError.TrimEnd(), Is.Empty);
                Assert.That(output.StartTime, Is.LessThanOrEqualTo(output.ExitTime));
                Assert.That(output.RunTime, Is.EqualTo(output.ExitTime - output.StartTime));
            }
        }