Esempio n. 1
0
        public CompositionRoot(ScriptCsArgs args)
        {
            Guard.AgainstNullArgument("args", args);

            _debug = args.Debug;
            _logLevel = args.LogLevel;
            _shouldInitDrirectoryCatalog = ShouldInitDrirectoryCatalog(args);
        }
Esempio n. 2
0
        public static Config Create(ScriptCsArgs commandArgs)
        {
            Guard.AgainstNullArgument("commandArgs", commandArgs);

            return(new Config()
                   .Apply(ConfigMask.ReadGlobalOrDefault())
                   .Apply(commandArgs.Config == null ? ConfigMask.ReadLocalOrDefault() : ConfigMask.Read(commandArgs.Config))
                   .Apply(ConfigMask.Create(commandArgs)));
        }
Esempio n. 3
0
        public static Config Create(ScriptCsArgs commandArgs)
        {
            Guard.AgainstNullArgument("commandArgs", commandArgs);

            return new Config()
                .Apply(ConfigMask.ReadGlobalOrDefault())
                .Apply(commandArgs.Config == null ? ConfigMask.ReadLocalOrDefault() : ConfigMask.Read(commandArgs.Config))
                .Apply(ConfigMask.Create(commandArgs));
        }
        public static IScriptServicesBuilder Create(ScriptCsArgs commandArgs, string[] scriptArgs)
        {
            Guard.AgainstNullArgument("commandArgs", commandArgs);
            Guard.AgainstNullArgument("scriptArgs", scriptArgs);

            IConsole console = new ScriptConsole();

            if (!string.IsNullOrWhiteSpace(commandArgs.Output))
            {
                console = new FileConsole(commandArgs.Output, console);
            }
            var logLevel     = commandArgs.LogLevel ?? LogLevel.Info;
            var configurator = new LoggerConfigurator(logLevel);

            configurator.Configure(console);
            var logger = configurator.GetLogger();
            var initializationServices = new InitializationServices(logger);

            initializationServices.GetAppDomainAssemblyResolver().Initialize();

            var scriptServicesBuilder = new ScriptServicesBuilder(console, logger, null, null, initializationServices)
                                        .Cache(commandArgs.Cache)
                                        .Debug(commandArgs.Debug)
                                        .LogLevel(logLevel)
                                        .ScriptName(commandArgs.ScriptName)
                                        .Repl(commandArgs.Repl);

            var modules = commandArgs.Modules == null
                ? new string[0]
                : commandArgs.Modules.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            var extension = Path.GetExtension(commandArgs.ScriptName);

            if (string.IsNullOrWhiteSpace(extension) && !commandArgs.Repl)
            {
                // No extension was given, i.e we might have something like
                // "scriptcs foo" to deal with. We activate the default extension,
                // to make sure it's given to the LoadModules below.
                extension = ".csx";

                if (!string.IsNullOrWhiteSpace(commandArgs.ScriptName))
                {
                    // If the was in fact a script specified, we'll extend it
                    // with the default extension, assuming the user giving
                    // "scriptcs foo" actually meant "scriptcs foo.csx". We
                    // perform no validation here thought; let it be done by
                    // the activated command. If the file don't exist, it's
                    // up to the command to detect and report.

                    commandArgs.ScriptName += extension;
                }
            }

            return(scriptServicesBuilder.LoadModules(extension, modules));
        }
        public static IScriptServicesBuilder Create(ScriptCsArgs commandArgs, string[] scriptArgs)
        {
            Guard.AgainstNullArgument("commandArgs", commandArgs);
            Guard.AgainstNullArgument("scriptArgs", scriptArgs);

            IConsole console = new ScriptConsole();
            if (!string.IsNullOrWhiteSpace(commandArgs.Output))
            {
                console = new FileConsole(commandArgs.Output, console);
            }

            var configurator = new LoggerConfigurator(commandArgs.LogLevel);
            configurator.Configure(console);
            var logger = configurator.GetLogger();
            var initializationServices = new InitializationServices(logger);
            initializationServices.GetAppDomainAssemblyResolver().Initialize();

            var scriptServicesBuilder = new ScriptServicesBuilder(console, logger, null, null, initializationServices)
                .Cache(commandArgs.Cache)
                .Debug(commandArgs.Debug)
                .LogLevel(commandArgs.LogLevel)
                .ScriptName(commandArgs.ScriptName)
                .Repl(commandArgs.Repl);

            var modules = commandArgs.Modules == null
                ? new string[0]
                : commandArgs.Modules.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            var extension = Path.GetExtension(commandArgs.ScriptName);

            if (string.IsNullOrWhiteSpace(extension) && !commandArgs.Repl)
            {
                // No extension was given, i.e we might have something like
                // "scriptcs foo" to deal with. We activate the default extension,
                // to make sure it's given to the LoadModules below.
                extension = ".csx";

                if (!string.IsNullOrWhiteSpace(commandArgs.ScriptName))
                {
                    // If the was in fact a script specified, we'll extend it
                    // with the default extension, assuming the user giving
                    // "scriptcs foo" actually meant "scriptcs foo.csx". We
                    // perform no validation here thought; let it be done by
                    // the activated command. If the file don't exist, it's
                    // up to the command to detect and report.

                    commandArgs.ScriptName += extension;
                }
            }

            return scriptServicesBuilder.LoadModules(extension, modules);
        }
Esempio n. 6
0
        private static int Main(string[] args)
        {
            ScriptCsArgs commandArgs;

            const string unexpectedArgumentMessage = "Unexpected Argument: ";
            try
            {
                commandArgs = Args.Parse<ScriptCsArgs>(args);
            }
            catch (ArgException ex)
            {
                commandArgs = new ScriptCsArgs();

                if (ex.Message.StartsWith(unexpectedArgumentMessage))
                {
                    var token = ex.Message.Substring(unexpectedArgumentMessage.Length);
                    Console.WriteLine("Parameter \"{0}\" is not supported!", token);
                }
                else
                {
                    Console.WriteLine(ex.Message);
                }
            }

            var debug = commandArgs.DebugFlag;
            var compositionRoot = new CompositionRoot(debug);
            compositionRoot.Initialize();
            var scriptServiceRoot = compositionRoot.GetServiceRoot();

            var commandFactory = new CommandFactory(scriptServiceRoot);
            var command = commandFactory.CreateCommand(commandArgs);

            var result = command.Execute();

            switch (result)
            {
                case CommandResult.Success:
                    return 0;
                default:
                    return -1;
            }
        }
Esempio n. 7
0
        private static int Main(string[] args)
        {
            ProfileOptimizationShim.SetProfileRoot(Path.GetDirectoryName(typeof(Program).Assembly.Location));
            ProfileOptimizationShim.StartProfile(typeof(Program).Assembly.GetName().Name + ".profile");

            var nonScriptArgs = args.TakeWhile(arg => arg != "--").ToArray();
            var scriptArgs    = args.Skip(nonScriptArgs.Length + 1).ToArray();

            ScriptCsArgs commandArgs;

            try
            {
                commandArgs = ScriptCsArgs.Parse(nonScriptArgs);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ScriptCsArgs.GetUsage());
                return(1);
            }

            if (commandArgs.Help)
            {
                Console.WriteLine(ScriptCsArgs.GetUsage());
                return(0);
            }

            if (commandArgs.Version)
            {
                VersionWriter.Write();
                return(0);
            }

            if (commandArgs.Config != null && !File.Exists(commandArgs.Config))
            {
                Console.WriteLine("The specified config file does not exist.");
                return(1);
            }

            return(Application.Run(Config.Create(commandArgs), scriptArgs));
        }
Esempio n. 8
0
        public static ConfigMask Create(ScriptCsArgs args)
        {
            Guard.AgainstNullArgument("args", args);

            return new ConfigMask
            {
                AllowPreRelease = args.AllowPreRelease ? (bool?)true : null,
                Cache = args.Cache ? (bool?)true : null,
                Clean = args.Clean ? (bool?)true : null,
                Debug = args.Debug ? (bool?)true : null,
                Global = args.Global ? (bool?)true : null,
                Install = args.Install,
                LogLevel = args.LogLevel,
                Modules = args.Modules,
                Output = args.Output,
                PackageVersion = args.PackageVersion,
                Repl = args.Repl ? (bool?)true : null,
                Save = args.Save ? (bool?)true : null,
                ScriptName = args.ScriptName,
                Watch = args.Watch ? (bool?)true : null,
            };
        }
Esempio n. 9
0
        public static ConfigMask Create(ScriptCsArgs args)
        {
            Guard.AgainstNullArgument("args", args);

            return(new ConfigMask
            {
                AllowPreRelease = args.AllowPreRelease ? (bool?)true : null,
                Cache = args.Cache ? (bool?)true : null,
                Clean = args.Clean ? (bool?)true : null,
                Debug = args.Debug ? (bool?)true : null,
                Global = args.Global ? (bool?)true : null,
                Install = args.Install,
                LogLevel = args.LogLevel,
                Modules = args.Modules,
                Output = args.Output,
                PackageVersion = args.PackageVersion,
                Repl = args.Repl ? (bool?)true : null,
                Save = args.Save ? (bool?)true : null,
                ScriptName = args.ScriptName,
                Watch = args.Watch ? (bool?)true : null,
            });
        }
Esempio n. 10
0
        private static int Main(string[] args)
        {
            string[] scriptArgs;
            ScriptCsArgs.SplitScriptArgs(ref args, out scriptArgs);

            var commandArgs  = ParseArguments(args);
            var configurator = new LoggerConfigurator(commandArgs.LogLevel);
            var console      = new ScriptConsole();

            configurator.Configure(console);
            var logger = configurator.GetLogger();

            var scriptServicesBuilder = new ScriptServicesBuilder(console, logger).
                                        Debug(commandArgs.Debug).
                                        LogLevel(commandArgs.LogLevel).
                                        ScriptName(commandArgs.ScriptName).
                                        Repl(commandArgs.Repl);

            var modules   = GetModuleList(commandArgs.Modules);
            var extension = Path.GetExtension(commandArgs.ScriptName);

            if (extension != null)
            {
                extension = extension.Substring(1);
            }

            scriptServicesBuilder.LoadModules(extension, modules);
            var scriptServiceRoot = scriptServicesBuilder.Build();

            var commandFactory = new CommandFactory(scriptServiceRoot);
            var command        = commandFactory.CreateCommand(commandArgs, scriptArgs);

            var result = command.Execute();

            return(result == CommandResult.Success ? 0 : -1);
        }
Esempio n. 11
0
 private static bool ShouldInitDrirectoryCatalog(ScriptCsArgs args)
 {
     return args.Repl || !string.IsNullOrWhiteSpace(args.ScriptName);
 }
Esempio n. 12
0
 private static bool ShouldInitDrirectoryCatalog(ScriptCsArgs args)
 {
     return(args.Repl || !string.IsNullOrWhiteSpace(args.ScriptName));
 }
Esempio n. 13
0
 public CompositionRoot(ScriptCsArgs args)
 {
     _debug    = args.Debug;
     _logLevel = args.LogLevel;
     _shouldInitDrirectoryCatalog = ShouldInitDrirectoryCatalog(args);
 }
Esempio n. 14
0
 public CompositionRoot(ScriptCsArgs args)
 {
     _debug = args.Debug;
     _logLevel = args.LogLevel;
     _shouldInitDrirectoryCatalog = ShouldInitDrirectoryCatalog(args);
 }