示例#1
0
文件: Program.cs 项目: ghuntley/cake
        /// <summary>
        /// The application entry point.
        /// </summary>
        /// <returns>The application exit code.</returns>
        public static int Main()
        {
            ICakeLog log = null;

            try
            {
                // Parse arguments.
                var args = ArgumentTokenizer
                           .Tokenize(Environment.CommandLine)
                           .Skip(1) // Skip executable.
                           .ToArray();

                var builder = new CakeContainerBuilder();
                builder.Registry.RegisterModule(new CakeModule());
                builder.Registry.RegisterModule(new CoreModule());
                builder.Registry.RegisterModule(new NuGetModule());

                // Build the container.
                using (var container = builder.Build())
                {
                    // Resolve the log.
                    log = container.Resolve <ICakeLog>();

                    // Parse the options.
                    var parser  = container.Resolve <IArgumentParser>();
                    var options = parser.Parse(args);

                    // Set verbosity.
                    log.Verbosity = options.Verbosity;

                    // Rebuild the container.
                    builder = new CakeContainerBuilder();
                    builder.Registry.RegisterModule(new ArgumentsModule(options));
                    builder.Registry.RegisterModule(new ConfigurationModule(container, options));
                    builder.Registry.RegisterModule(new ScriptingModule(options));
                    builder.Update(container);

                    // Load all modules.
                    var loader = container.Resolve <ModuleLoader>();
                    loader.LoadModules(container, options);

                    // Resolve and run the application.
                    var application = container.Resolve <CakeApplication>();
                    return(application.Run(options));
                }
            }
            catch (Exception ex)
            {
                log = log ?? new CakeBuildLog(new CakeConsole());
                if (log.Verbosity == Verbosity.Diagnostic)
                {
                    log.Error("Error: {0}", ex);
                }
                else
                {
                    log.Error("Error: {0}", ex.Message);
                }
                return(1);
            }
        }
示例#2
0
        /// <summary>
        /// The application entry point.
        /// </summary>
        /// <returns>The application exit code.</returns>
        public static int Main()
        {
            // Parse arguments.
            var args = ArgumentTokenizer
                       .Tokenize(Environment.CommandLine)
                       .Skip(1) // Skip executable.
                       .ToArray();

            // Are we running on Mono?
            var mono = Type.GetType("Mono.Runtime") != null;

            if (!mono)
            {
                // Not using the mono compiler, but do we want to?
                if (args.Contains("-mono"))
                {
                    mono = true;
                }
            }

            using (var container = CreateContainer(mono))
            {
                // Resolve and run the application.
                var application = container.Resolve <CakeApplication>();
                return(application.Run(args));
            }
        }
示例#3
0
            public void Should_Return_Zero_Results_If_Input_String_Is_Null()
            {
                // Given
                var input = string.Empty;

                // When
                var result = ArgumentTokenizer.Tokenize(input).ToArray();

                // Then
                Assert.Equal(0, result.Length);
            }
示例#4
0
            public void Should_Parse_Single_Quoted_Argument_With_Space_In_It()
            {
                // Given
                const string input = "\"C:\\cake walk\\cake.exe\"";

                // When
                var result = ArgumentTokenizer.Tokenize(input).ToArray();

                // Then
                Assert.Equal(1, result.Length);
                Assert.Equal("\"C:\\cake walk\\cake.exe\"", result[0]);
            }
示例#5
0
            public void Should_Parse_Multiple_Quoted_Arguments()
            {
                // Given
                const string input = "\"C:\\cake-walk\\cake.exe\" \"build.cake\" \"-dryrun\"";

                // When
                var result = ArgumentTokenizer.Tokenize(input).ToArray();

                // Then
                Assert.Equal(3, result.Length);
                Assert.Equal("\"C:\\cake-walk\\cake.exe\"", result[0]);
                Assert.Equal("\"build.cake\"", result[1]);
                Assert.Equal("\"-dryrun\"", result[2]);
            }
示例#6
0
            public void Should_Parse_Part_That_Contains_Quotes_With_Space_In_It()
            {
                // Given
                const string input = @"cake.exe build.cake -target=""te st""";

                // When
                var result = ArgumentTokenizer.Tokenize(input).ToArray();

                // Then
                Assert.Equal(3, result.Length);
                Assert.Equal("cake.exe", result[0]);
                Assert.Equal("build.cake", result[1]);
                Assert.Equal("-target=\"te st\"", result[2]);
            }
示例#7
0
            public void Should_Parse_Multiple_Mixed_Arguments()
            {
                // Given
                const string input = "\"C:\\cake-walk\\cake.exe\" build.cake -verbosity \"diagnostic\"";

                // When
                var result = ArgumentTokenizer.Tokenize(input).ToArray();

                // Then
                Assert.Equal(4, result.Length);
                Assert.Equal("\"C:\\cake-walk\\cake.exe\"", result[0]);
                Assert.Equal("build.cake", result[1]);
                Assert.Equal("-verbosity", result[2]);
                Assert.Equal("\"diagnostic\"", result[3]);
            }