Implements the IParameters interface by parsing the command line
Наследование: IParameters
Пример #1
0
 public void NoArgs()
 {
     var ps = new ConsoleParameters(new string[0]);
     ps.Command.Should().Be("help"); // default command
     ps.CommandParameters.Should().BeEmpty();
     ps.VerboseOutput.Should().BeFalse();
     ps.Goal.Should().BeNull(); // default goal
 }
Пример #2
0
 public void SimpleCommandWithoutArgs()
 {
     var ps = new ConsoleParameters(new[] { "cmd"});
     ps.Command.Should().Be("cmd"); // default command
     ps.CommandParameters.Should().BeEmpty();
     ps.VerboseOutput.Should().BeFalse();
     ps.Goal.Should().BeNull(); // default goal
 }
Пример #3
0
 public void CommandWithArgsAndVerboseSwitchAndGoalSpec2()
 {
     var ps = new ConsoleParameters(new[] { "/v", "/target", "goal", "cmd", "1", "2", "3" });
     ps.Command.Should().Be("cmd"); // default command
     ps.CommandParameters.Should().BeEquivalentTo(new[] { "1", "2", "3" });
     ps.VerboseOutput.Should().BeTrue();
     ps.Goal.Should().Be("goal");
 }
Пример #4
0
 public void CommandWithArgsAndVerboseSwitch()
 {
     var ps = new ConsoleParameters(new[] { "-v", "cmd", "1", "2", "3" });
     ps.Command.Should().Be("cmd"); // default command
     ps.CommandParameters.Should().BeEquivalentTo(new[] { "1", "2", "3" });
     ps.VerboseOutput.Should().BeTrue();
     ps.Goal.Should().BeNull(); // default goal
 }
Пример #5
0
 public void CommandWithArgs()
 {
     var ps = new ConsoleParameters(new[] { "cmd", "1", "2", "3" });
     ps.Command.Should().Be("cmd"); // default command
     ps.CommandParameters.Should().BeEquivalentTo(new[] {"1", "2", "3"});
     ps.VerboseOutput.Should().BeFalse();
     ps.Goal.Should().Be("debug"); // default goal
 }
Пример #6
0
        static int Main(string[] args)
        {
            var consoleParams = new ConsoleParameters(args);
            if (consoleParams.VerboseOutput)
                EnableConsoleDebugLog();

            var root = Kernel.Root;

            // Binding UI interfaces
            root.Bind<IUserOutput>().To<ConsoleUserInterface>().InSingletonScope();
            root.Bind<IParameters>().ToConstant(consoleParams).InSingletonScope();

            // Binding special directories
            var suiteRoot = new LocalFileSystemDirectory(Environment.CurrentDirectory);
            root.Bind<IFileSystemDirectory>()
                .ToConstant(suiteRoot)
                .WhenTargetHas<SuiteRootAttribute>();
            root.Bind<IFileSystemDirectory>()
                .ToConstant(suiteRoot.GetChildDirectory("target", createIfMissing: true))
                .WhenTargetHas<TargetRootAttribute>();

            // Binding core services
            Kernel.RegisterCoreBindings();

            // Binding default cache
            var cacheDir = suiteRoot.GetChildDirectory("cache", createIfMissing: true)
                                    .GetChildDirectory(consoleParams.Goal, createIfMissing: true);
            root.Bind<IFileSystemDirectory>()
                .ToConstant(cacheDir)
                .WhenTargetHas<CacheRootAttribute>();
            root.Bind<IBuildCache>().To<FileBuildCache>();            

            // Loading fix plugins
            root.Load(GetOrderedModuleList(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Bari.Plugins.*.dll"));

            // Initializing the cache cleaner
            root.Bind<ICleanExtension>().ToConstant(new CacheCleaner(cacheDir, root.Get<IBuilderEnumerator>()));

            var process = root.Get<MainProcess>();
            try
            {
                if (process.Run())
                    return 0;
                else
                    return 1;
            }
            catch (Exception ex)
            {
                System.Console.ForegroundColor = ConsoleColor.Red;
                System.Console.WriteLine(ex.ToString());
                System.Console.ForegroundColor = ConsoleColor.Gray;

                return 2;
            }
        }
Пример #7
0
        static int Main(string[] args)
        {
            var consoleParams = new ConsoleParameters(args);
            if (consoleParams.VerboseOutput)
                EnableConsoleDebugLog();

            var root = Kernel.Root;

            // Binding UI interfaces
            root.Bind<IUserOutput>().To<ConsoleUserInterface>().InSingletonScope();
            root.Bind<IParameters>().ToConstant(consoleParams).InSingletonScope();

            // Binding special directories
            var suiteRoot = new LocalFileSystemDirectory(Environment.CurrentDirectory);
            root.Bind<IFileSystemDirectory>()
                .ToConstant(suiteRoot)
                .WhenTargetHas<SuiteRootAttribute>();
            root.Bind<IFileSystemDirectory>()
                .ToConstant(suiteRoot.GetChildDirectory("target", createIfMissing: true))
                .WhenTargetHas<TargetRootAttribute>();

            // Binding core services
            Kernel.RegisterCoreBindings();

            // Binding default cache
            var cacheDir = new Lazy<IFileSystemDirectory>(() =>
                suiteRoot.GetChildDirectory("cache", createIfMissing: true)
                         .GetChildDirectory(root.Get<Suite>().ActiveGoal.Name, createIfMissing: true));
            root.Bind<Lazy<IFileSystemDirectory>>()
                .ToConstant(cacheDir)
                .WhenTargetHas<CacheRootAttribute>();
            root.Bind<IBuildCache>().To<FileBuildCache>();

            // Loading fix plugins
            var pluginLoader = root.Get<IPluginLoader>();
            foreach (var module in GetOrderedModuleList(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Bari.Plugins.*.dll"))
                pluginLoader.Load(module);

            // Initializing builder store
            Kernel.InitializeBuilderStore();

            // Initializing the cache cleaner
            root.Bind<ICleanExtension>().ToConstant(new CacheCleaner(cacheDir, root.Get<IBuilderEnumerator>(), () => root.Get<ISoftCleanPredicates>()));

            var process = root.Get<MainProcess>();
            try
            {
                if (process.Run())
                    return 0;
                else
                    return 1;
            }
            catch (Exception ex)
            {
                var output = root.Get<IUserOutput>();
                output.Error(ex.ToString());

                return 2;
            }
        }