Example #1
0
        public void Execute(CommandContext context)
        {
            var args = context.Args;
            var config = context.Config;
            if(args.Length < 2)
            {
                Console.WriteLine("Expected 2 arguments, e.g. lu use .net 3.5");
                return;
            }
            string componentName = args[0];
            string versionName = args[1];
            var component = config.Components.SingleOrDefault(x => x.Name == componentName);
            if (component == null)
            {
                Console.WriteLine(@"WARNING: No component could be found with the name ""{0}""", componentName);
                return;
            }
            var version = component.Versions.SingleOrDefault(x => x.Name == versionName);
            if (version == null)
            {
                Console.WriteLine(@"WARNING: No version called ""{0}"" exists in component ""{1}""", versionName, componentName);
                return;
            }

            SaveOriginalPathInCommandLineSession(context);
            string newPath = PathMonkeyer.SetComponentVersion(component, version);

            SetNewPathInCommandLineSession(context, newPath);

            Console.WriteLine(@"INFO: Using path ""{0}"" for component ""{1}"", version ""{2}""", version.Path, component.Name, version.Name);
        }
Example #2
0
        private void ExecuteCommand(ICommand command)
        {
            var commandArgs = args.Skip(1).ToArray();
            var context = new CommandContext(config, commandArgs);
            command.Execute(context);

            WriteContentToFileExecutedByLauncherBatchFile(context.GetContentForFileExecutedByLauncherBatchFile());
        }
Example #3
0
 /// <summary>
 /// Sets an environment variable storing path before any changes have been made by LineUp
 /// </summary>
 /// <param name="context"></param>
 private static void SaveOriginalPathInCommandLineSession(CommandContext context)
 {
     bool originalPathAlreadySaved = !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(EnvironmentVariables.OriginalPath));
     if (!originalPathAlreadySaved)
     {
         var originalPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process) ?? "";
         string command = string.Format("set {0}={1}", EnvironmentVariables.OriginalPath, originalPath);
         context.AddLinesToFileExecutedByLauncherBatchFile(new[] { command });
     }
 }
Example #4
0
        public void Execute(CommandContext context)
        {
            string currentPathValue = Environment.GetEnvironmentVariable(EnvironmentVariables.Path,
                                                                         EnvironmentVariableTarget.Process);
            string originalPathValue = Environment.GetEnvironmentVariable(EnvironmentVariables.OriginalPath,
                                                                          EnvironmentVariableTarget.Process);

            bool revertRequired = !string.IsNullOrWhiteSpace(originalPathValue)
                && !new PathEnvironmentVariable(originalPathValue).IsEquivalentTo(currentPathValue);

            if (revertRequired)
            {
                RevertToOriginalPathInCommandLineSession(context, originalPathValue);
                Console.WriteLine(Resources.RevertCommand_RevertingToOriginalPath);
            }
            else
            {
                Console.WriteLine(Resources.RevertCommand_RevertNotRequired);
            }
        }
Example #5
0
 private static void RevertToOriginalPathInCommandLineSession(CommandContext context, string originalPath)
 {
     string restorePath = string.Format("set {0}={1}", EnvironmentVariables.Path, originalPath);
     string removeOriginal = string.Format("set {0}=", EnvironmentVariables.OriginalPath);
     context.AddLinesToFileExecutedByLauncherBatchFile(new[] {restorePath, removeOriginal});
 }
Example #6
0
 private static void SetNewPathInCommandLineSession(CommandContext context, string newPath)
 {
     string command = string.Format("set path={0}", newPath);
     context.AddLinesToFileExecutedByLauncherBatchFile(new[] { command });
 }