Example #1
0
        public static BootstrapperOptions ParseArgumentsAndConfigurations(IEnumerable <string> arguments, NameValueCollection appSettings, IDictionary envVariables)
        {
            var options = new BootstrapperOptions();

            var commandArgs = arguments.ToList();

            if (commandArgs.Contains(CommandArgs.PreferNuget) || appSettings.GetKey(AppSettingKeys.PreferNugetAppSettingsKey).ToLowerSafe() == "true")
            {
                options.PreferNuget = true;
                commandArgs.Remove(CommandArgs.PreferNuget);
            }
            if (commandArgs.Contains(CommandArgs.ForceNuget) || appSettings.GetKey(AppSettingKeys.ForceNugetAppSettingsKey).ToLowerSafe() == "true")
            {
                options.ForceNuget = true;
                commandArgs.Remove(CommandArgs.ForceNuget);
            }
            if (commandArgs.Contains(CommandArgs.Silent))
            {
                options.Silent = true;
                commandArgs.Remove(CommandArgs.Silent);
            }
            if (commandArgs.Contains(CommandArgs.Help))
            {
                options.ShowHelp = true;
                commandArgs.Remove(CommandArgs.Help);
            }

            commandArgs = EvaluateDownloadOptions(options.DownloadArguments, commandArgs, appSettings, envVariables).ToList();

            options.UnprocessedCommandArgs = commandArgs;
            return(options);
        }
Example #2
0
        private static void FillOptionsFromAppSettings(BootstrapperOptions options, NameValueCollection appSettings)
        {
            if (appSettings.IsTrue(AppSettingKeys.PreferNuget))
            {
                options.PreferNuget = true;
            }
            if (appSettings.IsTrue(AppSettingKeys.ForceNuget))
            {
                options.ForceNuget = true;
            }
            var latestVersion = appSettings.GetKey(AppSettingKeys.PaketVersion);

            if (latestVersion != null)
            {
                options.DownloadArguments.LatestVersion = latestVersion;
            }
            if (appSettings.IsTrue(AppSettingKeys.Prerelease))
            {
                options.DownloadArguments.IgnorePrerelease = false;
            }
            var nugetSource = appSettings.GetKey(AppSettingKeys.NugetSource);

            if (nugetSource != null)
            {
                options.DownloadArguments.NugetSource = nugetSource;
            }
        }
Example #3
0
        private static void FillNonRunOptionsFromArguments(BootstrapperOptions options, List <string> commandArgs)
        {
            if (commandArgs.Contains(CommandArgs.PreferNuget))
            {
                options.PreferNuget = true;
                commandArgs.Remove(CommandArgs.PreferNuget);
            }
            if (commandArgs.Contains(CommandArgs.ForceNuget))
            {
                options.ForceNuget = true;
                commandArgs.Remove(CommandArgs.ForceNuget);
            }
            while (commandArgs.Contains(CommandArgs.Silent))
            {
                options.Verbosity -= 1;
                commandArgs.Remove(CommandArgs.Silent);
            }
            while (commandArgs.Contains(CommandArgs.Verbose))
            {
                options.Verbosity += 1;
                commandArgs.Remove(CommandArgs.Verbose);
            }
            if (commandArgs.Contains(CommandArgs.Help))
            {
                options.ShowHelp = true;
                commandArgs.Remove(CommandArgs.Help);
            }

            FillDownloadOptionsFromArguments(options.DownloadArguments, commandArgs);
        }
Example #4
0
        public static BootstrapperOptions ParseArgumentsAndConfigurations(IEnumerable<string> arguments, NameValueCollection appSettings, IDictionary envVariables)
        {
            var options = new BootstrapperOptions();

            var commandArgs = arguments.ToList();

            if (commandArgs.Contains(CommandArgs.PreferNuget) || appSettings.GetKey(AppSettingKeys.PreferNugetAppSettingsKey).ToLowerSafe() == "true")
            {
                options.PreferNuget = true;
                commandArgs.Remove(CommandArgs.PreferNuget);
            }
            if (commandArgs.Contains(CommandArgs.ForceNuget) || appSettings.GetKey(AppSettingKeys.ForceNugetAppSettingsKey).ToLowerSafe() == "true")
            {
                options.ForceNuget = true;
                commandArgs.Remove(CommandArgs.ForceNuget);
            }
            if (commandArgs.Contains(CommandArgs.Silent))
            {
                options.Silent = true;
                commandArgs.Remove(CommandArgs.Silent);
            }
            if (commandArgs.Contains(CommandArgs.Help))
            {
                options.ShowHelp = true;
                commandArgs.Remove(CommandArgs.Help);
            }

            commandArgs = EvaluateDownloadOptions(options.DownloadArguments, commandArgs, appSettings, envVariables).ToList();

            options.UnprocessedCommandArgs = commandArgs;
            return options;
        }
Example #5
0
        public static BootstrapperOptions ParseArgumentsAndConfigurations(IEnumerable <string> arguments, NameValueCollection appSettings, IDictionary envVariables, IFileSystemProxy fileSystem, IEnumerable <string> argumentsInDependenciesFile)
        {
            var options              = new BootstrapperOptions();
            var commandArgs          = arguments.ToList();
            var magicMode            = GetIsMagicMode(fileSystem);
            var transparentMagicMode = magicMode && commandArgs.IndexOf(CommandArgs.Run) == -1;

            FillTarget(options.DownloadArguments, magicMode, fileSystem);

            // 1 - AppSettings
            FillOptionsFromAppSettings(options, appSettings);

            // 2 - paket.dependencies
            FillNonRunOptionsFromArguments(options, argumentsInDependenciesFile.ToList());

            // 3 - Environment variables
            FillOptionsFromEnvVariables(options, envVariables);

            // 4 - Command line
            if (transparentMagicMode)
            {
                // Transparent magic mode mean that we're renamed 'paket.exe' and --run wasn't passed

                // Virtually add a '-s'
                options.Verbosity -= 1;

                // Assume --run and that all arguments are for the real paket binary
                options.Run     = true;
                options.RunArgs = new List <string>(commandArgs);
                commandArgs.Clear();

                // Don't check more than twice a day
                //  - Except if we want pre-releases as we're living on the bleeding edge
                //  - Or if we specify a fixed version because it will never check anyway
                //  - Or if the user specified any other value via 'paket.dependencies'
                if (options.DownloadArguments.IgnorePrerelease &&
                    string.IsNullOrEmpty(options.DownloadArguments.LatestVersion) &&
                    options.DownloadArguments.MaxFileAgeInMinutes == null)
                {
                    options.DownloadArguments.MaxFileAgeInMinutes = 60 * 12;
                }
            }
            else
            {
                FillRunOptionsFromArguments(options, commandArgs);
                FillNonRunOptionsFromArguments(options, commandArgs);
            }

            if (!options.DownloadArguments.IgnorePrerelease &&
                !string.IsNullOrEmpty(options.DownloadArguments.LatestVersion))
            {
                // PreRelease + specific version -> we prefer the specific version
                options.DownloadArguments.IgnorePrerelease = true;
            }

            options.UnprocessedCommandArgs = commandArgs;

            return(options);
        }
Example #6
0
        public static BootstrapperOptions ParseArgumentsAndConfigurations(IEnumerable<string> arguments, NameValueCollection appSettings, IDictionary envVariables, IFileSystemProxy fileSystem, IEnumerable<string> argumentsInDependenciesFile)
        {
            var options = new BootstrapperOptions();
            var commandArgs = arguments.ToList();
            var magicMode = GetIsMagicMode(fileSystem);
            var transparentMagicMode = magicMode && commandArgs.IndexOf(CommandArgs.Run) == -1;

            FillTarget(options.DownloadArguments, magicMode, fileSystem);

            // 1 - AppSettings
            FillOptionsFromAppSettings(options, appSettings);

            // 2 - paket.dependencies
            FillNonRunOptionsFromArguments(options, argumentsInDependenciesFile.ToList());

            // 3 - Environment variables
            FillOptionsFromEnvVariables(options, envVariables);

            // 4 - Command line
            if (transparentMagicMode)
            {
                // Transparent magic mode mean that we're renamed 'paket.exe' and --run wasn't passed

                // Virtually add a '-s'
                options.Verbosity -= 1;

                // Assume --run and that all arguments are for the real paket binary
                options.Run = true;
                options.RunArgs = new List<string>(commandArgs);
                commandArgs.Clear();

                // Don't check more than twice a day
                //  - Except if we want pre-releases as we're living on the bleeding edge
                //  - Or if we specify a fixed version because it will never check anyway
                //  - Or if the user specified any other value via 'paket.dependencies'
                if (options.DownloadArguments.IgnorePrerelease
                    && string.IsNullOrEmpty(options.DownloadArguments.LatestVersion)
                    && options.DownloadArguments.MaxFileAgeInMinutes == null)
                {
                    options.DownloadArguments.MaxFileAgeInMinutes = 60*12;
                }
            }
            else
            {
                FillRunOptionsFromArguments(options, commandArgs);
                FillNonRunOptionsFromArguments(options, commandArgs);
            }

            if (!options.DownloadArguments.IgnorePrerelease &&
                !string.IsNullOrEmpty(options.DownloadArguments.LatestVersion))
            {
                // PreRelease + specific version -> we prefer the specific version
                options.DownloadArguments.IgnorePrerelease = true;
            }

            options.UnprocessedCommandArgs = commandArgs;

            return options;
        }
Example #7
0
 private static void FillOptionsFromEnvVariables(BootstrapperOptions options, IDictionary envVariables)
 {
     var latestVersion = envVariables.GetKey(EnvArgs.PaketVersionEnvPosix) ?? envVariables.GetKey(EnvArgs.PaketVersionEnv) ;
     if (latestVersion != null)
     {
         options.DownloadArguments.LatestVersion = latestVersion;
     }
 }
Example #8
0
 private static void FillRunOptionsFromArguments(BootstrapperOptions options, List<string> commandArgs)
 {
     var runIndex = commandArgs.IndexOf(CommandArgs.Run);
     if (runIndex != -1)
     {
         options.Run = true;
         options.RunArgs = commandArgs.GetRange(runIndex + 1, commandArgs.Count - runIndex - 1);
         commandArgs.RemoveRange(runIndex, commandArgs.Count - runIndex);
     }
 }
 private static void ApplyAppSettings(NameValueCollection appSettings, BootstrapperOptions options)
 {
     if (appSettings.IsTrue(AppSettingKeys.PreferNuget))
     {
         options.PreferNuget = true;
     }
     if (appSettings.IsTrue(AppSettingKeys.ForceNuget))
     {
         options.ForceNuget = true;
     }
 }
Example #10
0
 private static void ApplyAppSettings(NameValueCollection appSettings, BootstrapperOptions options)
 {
     if (appSettings.IsTrue(AppSettingKeys.PreferNuget))
     {
         options.PreferNuget = true;
     }
     if (appSettings.IsTrue(AppSettingKeys.ForceNuget))
     {
         options.ForceNuget = true;
     }
 }
Example #11
0
        public static BootstrapperOptions ParseArgumentsAndConfigurations(IEnumerable <string> arguments, NameValueCollection appSettings, IDictionary envVariables, bool magicMode)
        {
            var options = new BootstrapperOptions();

            var commandArgs = arguments.ToList();

            ApplyAppSettings(appSettings, options);

            var runIndex = commandArgs.IndexOf(CommandArgs.Run);

            if (magicMode && runIndex == -1)
            {
                options.Silent  = true;
                options.Run     = true;
                options.RunArgs = commandArgs;
                EvaluateDownloadOptions(options.DownloadArguments, new string[0], appSettings, envVariables, true);
                return(options);
            }

            if (runIndex != -1)
            {
                options.Run     = true;
                options.RunArgs = commandArgs.GetRange(runIndex + 1, commandArgs.Count - runIndex - 1);
                commandArgs.RemoveRange(runIndex, commandArgs.Count - runIndex);
            }

            if (commandArgs.Contains(CommandArgs.PreferNuget))
            {
                options.PreferNuget = true;
                commandArgs.Remove(CommandArgs.PreferNuget);
            }
            if (commandArgs.Contains(CommandArgs.ForceNuget))
            {
                options.ForceNuget = true;
                commandArgs.Remove(CommandArgs.ForceNuget);
            }
            if (commandArgs.Contains(CommandArgs.Silent))
            {
                options.Silent = true;
                commandArgs.Remove(CommandArgs.Silent);
            }
            if (commandArgs.Contains(CommandArgs.Help))
            {
                options.ShowHelp = true;
                commandArgs.Remove(CommandArgs.Help);
            }

            commandArgs = EvaluateDownloadOptions(options.DownloadArguments, commandArgs, appSettings, envVariables, magicMode).ToList();

            options.UnprocessedCommandArgs = commandArgs;
            return(options);
        }
        public static BootstrapperOptions ParseArgumentsAndConfigurations(IEnumerable<string> arguments, NameValueCollection appSettings, IDictionary envVariables, bool magicMode)
        {
            var options = new BootstrapperOptions();

            var commandArgs = arguments.ToList();

            ApplyAppSettings(appSettings, options);

            var runIndex = commandArgs.IndexOf(CommandArgs.Run);
            if (magicMode && runIndex == -1)
            {
                options.Silent = true;
                options.Run = true;
                options.RunArgs = commandArgs;
                EvaluateDownloadOptions(options.DownloadArguments, new string[0], appSettings, envVariables, true);
                return options;
            }

            if (runIndex != -1)
            {
                options.Run = true;
                options.RunArgs = commandArgs.GetRange(runIndex + 1, commandArgs.Count - runIndex - 1);
                commandArgs.RemoveRange(runIndex, commandArgs.Count - runIndex);
            }

            if (commandArgs.Contains(CommandArgs.PreferNuget))
            {
                options.PreferNuget = true;
                commandArgs.Remove(CommandArgs.PreferNuget);
            }
            if (commandArgs.Contains(CommandArgs.ForceNuget))
            {
                options.ForceNuget = true;
                commandArgs.Remove(CommandArgs.ForceNuget);
            }
            if (commandArgs.Contains(CommandArgs.Silent))
            {
                options.Silent = true;
                commandArgs.Remove(CommandArgs.Silent);
            }
            if (commandArgs.Contains(CommandArgs.Help))
            {
                options.ShowHelp = true;
                commandArgs.Remove(CommandArgs.Help);
            }

            commandArgs = EvaluateDownloadOptions(options.DownloadArguments, commandArgs, appSettings, envVariables, magicMode).ToList();

            options.UnprocessedCommandArgs = commandArgs;
            return options;
        }
Example #13
0
 private static void OnSuccessfulDownload(BootstrapperOptions options)
 {
     if (options.Run && File.Exists(options.DownloadArguments.Target))
     {
         Console.CancelKeyPress -= CancelKeyPressed;
         try
         {
             var exitCode = PaketRunner.Run(options.DownloadArguments.Target, options.RunArgs);
             Environment.Exit(exitCode);
         }
         catch (Exception e)
         {
             ConsoleImpl.WriteError("Running paket failed with: {0}", e);
         }
     }
 }
Example #14
0
 private static void FillOptionsFromAppSettings(BootstrapperOptions options, NameValueCollection appSettings)
 {
     if (appSettings.IsTrue(AppSettingKeys.PreferNuget))
     {
         options.PreferNuget = true;
     }
     if (appSettings.IsTrue(AppSettingKeys.ForceNuget))
     {
         options.ForceNuget = true;
     }
     var latestVersion = appSettings.GetKey(AppSettingKeys.PaketVersion);
     if (latestVersion != null)
     {
         options.DownloadArguments.LatestVersion = latestVersion;
     }
     if (appSettings.IsTrue(AppSettingKeys.Prerelease))
     {
         options.DownloadArguments.IgnorePrerelease = false;
     }
 }
Example #15
0
        public static BootstrapperOptions ParseArgumentsAndConfigurations(IEnumerable <string> arguments, NameValueCollection appSettings, IDictionary envVariables, IFileSystemProxy fileSystem, IEnumerable <string> argumentsInDependenciesFile)
        {
            var options              = new BootstrapperOptions();
            var commandArgs          = arguments.ToList();
            var magicMode            = GetIsMagicMode(fileSystem);
            var transparentMagicMode = magicMode && commandArgs.IndexOf(CommandArgs.Run) == -1;

            var outputDirArg = commandArgs.SingleOrDefault(x => x.StartsWith(CommandArgs.OutputDir));

            if (outputDirArg != null)
            {
                commandArgs.Remove(outputDirArg);
                var folder = outputDirArg.Substring(CommandArgs.OutputDir.Length);
                var target = Path.Combine(folder, "paket.exe");

                options.DownloadArguments.Target = target;
                options.DownloadArguments.Folder = Path.GetDirectoryName(target);
            }
            else
            {
                FillTarget(options.DownloadArguments, magicMode, fileSystem);
            }

            var configFileArg = commandArgs.SingleOrDefault(x => x.StartsWith(CommandArgs.ConfigFile));

            if (configFileArg != null)
            {
                commandArgs.Remove(configFileArg);
                var configFilePath = configFileArg.Substring(CommandArgs.ConfigFile.Length);
                var newSettings    = ReadSettings(configFilePath);
                appSettings = newSettings;
            }

            // 1 - AppSettings
            FillOptionsFromAppSettings(options, appSettings);

            // 2 - paket.dependencies
            FillNonRunOptionsFromArguments(options, argumentsInDependenciesFile.ToList());

            // 3 - Environment variables
            FillOptionsFromEnvVariables(options, envVariables);

            // 4 - Command line
            if (transparentMagicMode)
            {
                // Transparent magic mode mean that we're renamed 'paket.exe' and --run wasn't passed

                // Virtually add a '-s'
                options.Verbosity -= 1;

                // Assume --run and that all arguments are for the real paket binary
                options.Run     = true;
                options.RunArgs = new List <string>(commandArgs);
                commandArgs.Clear();

                // Don't check more than twice a day
                //  - Except if we want pre-releases as we're living on the bleeding edge
                //  - Or if we specify a fixed version because it will never check anyway
                //  - Or if the user specified any other value via 'paket.dependencies'
                if (options.DownloadArguments.IgnorePrerelease &&
                    string.IsNullOrEmpty(options.DownloadArguments.LatestVersion) &&
                    options.DownloadArguments.MaxFileAgeInMinutes == null)
                {
                    options.DownloadArguments.MaxFileAgeInMinutes = 60 * 12;
                }
            }
            else
            {
                FillRunOptionsFromArguments(options, commandArgs);
                FillNonRunOptionsFromArguments(options, commandArgs);
            }

            if (!options.DownloadArguments.IgnorePrerelease &&
                !string.IsNullOrEmpty(options.DownloadArguments.LatestVersion))
            {
                // PreRelease + specific version -> we prefer the specific version
                options.DownloadArguments.IgnorePrerelease = true;
            }

            options.UnprocessedCommandArgs = commandArgs;

            if ("true" == Environment.GetEnvironmentVariable("PAKET_BOOTSTRAPPER_TRACE"))
            {
                options.Verbosity = Verbosity.Trace;
            }

#if PAKET_BOOTSTRAP_WORKAROUND_MSBUILD_URLS
            if (!String.IsNullOrEmpty(options.DownloadArguments.NugetSource))
            {
                string url = options.DownloadArguments.NugetSource;
                string fixedUrl;
                if (url.StartsWith("http://") || url.StartsWith("https://"))
                {
                    fixedUrl = url;
                }
                else
                {
                    fixedUrl = url.Replace("http:/", "http://").Replace("https:/", "https://");
                }
                options.DownloadArguments.NugetSource = fixedUrl;
            }
#endif

            return(options);
        }
Example #16
0
        private static void FillNonRunOptionsFromArguments(BootstrapperOptions options, List<string> commandArgs)
        {
            if (commandArgs.Contains(CommandArgs.PreferNuget))
            {
                options.PreferNuget = true;
                commandArgs.Remove(CommandArgs.PreferNuget);
            }
            if (commandArgs.Contains(CommandArgs.ForceNuget))
            {
                options.ForceNuget = true;
                commandArgs.Remove(CommandArgs.ForceNuget);
            }
            if (commandArgs.Contains(CommandArgs.Silent))
            {
                options.Silent = SilentMode.Silent;
                commandArgs.Remove(CommandArgs.Silent);
            }
            if (commandArgs.Contains(CommandArgs.Help))
            {
                options.ShowHelp = true;
                commandArgs.Remove(CommandArgs.Help);
            }

            FillDownloadOptionsFromArguments(options.DownloadArguments, commandArgs);
        }
Example #17
0
 private static void FillOptionsFromEnvVariables(BootstrapperOptions options, IDictionary envVariables)
 {
     var latestVersion = envVariables.GetKey(EnvArgs.PaketVersionEnv);
     if (latestVersion != null)
     {
         options.DownloadArguments.LatestVersion = latestVersion;
     }
 }
Example #18
0
 private static void FillRunOptionsFromArguments(BootstrapperOptions options, List<string> commandArgs)
 {
     var runIndex = commandArgs.IndexOf(CommandArgs.Run);
     if (runIndex != -1)
     {
         options.Run = true;
         options.RunArgs = commandArgs.GetRange(runIndex + 1, commandArgs.Count - runIndex - 1);
         commandArgs.RemoveRange(runIndex, commandArgs.Count - runIndex);
     }
 }
Example #19
0
 private static void OnSuccessfulDownload(BootstrapperOptions options)
 {
     if (options.Run && File.Exists(options.DownloadArguments.Target))
     {
         Console.CancelKeyPress -= CancelKeyPressed;
         try
         {
             var exitCode = PaketRunner.Run(options.DownloadArguments.Target, options.RunArgs);
             Environment.Exit(exitCode);
         }
         catch (Exception e)
         {
             ConsoleImpl.WriteError("Running paket failed with: {0}", e);
         }
     }
 }