Exemple #1
0
        public override void Execute(IEnumerable <string> args)
        {
            string version = null;
            var    pm      = new PackageManager(Log);
            var    input   = new List <string>(
                new OptionSet {
                { "d=|directory=", value => pm.InstallDirectory = value },
                { "n=|version=", value => version = value },
                { "s=|source=", value => pm.Source = pm.GetSource(value) },
                { "f|force", value => pm.Force = true }
            }.Parse(args)
                .Paths("."));

            Feed.FilterPackageArguments(input, ref version, ref pm.Source);
            Log.StartAnimation();

            for (int i = 0; i < input.Count; i++)
            {
                var arg = input[i];

                // Look for .UPK files when wildcard is given
                if (arg.IndexOf('*') != -1)
                {
                    foreach (var f in new[] { arg }.Files("*.upk"))
                    {
                        pm.InstallFile(f);
                    }

                    continue;
                }

                if (Directory.Exists(arg))
                {
                    arg = arg.GetProjectFile();
                }

                if (File.Exists(arg))
                {
                    pm.InstallFile(arg);
                }
                else
                {
                    pm.Install(arg, version);
                }
            }

            if (!pm.Force && pm.InstallCount == 0)
            {
                throw new ArgumentException("No packages installed");
            }
        }
Exemple #2
0
        public override void Execute(IEnumerable <string> args)
        {
            string       version = null;
            IPackageFeed source  = null;
            var          force   = false;
            var          input   = new OptionSet {
                { "n=|version=", value => version = value },
                { "f|force", value => force = true }
            }.Parse(args);

            if (input.Count == 0)
            {
                throw new ArgumentException("No packages specified");
            }

            input.CheckArguments();
            Feed.FilterPackageArguments(input, ref version, ref source);

            var cache    = new PackageCache();
            var versions = new List <DirectoryInfo>();

            foreach (var package in input)
            {
                versions.AddRange(cache.EnumerateVersions(package, version));
            }

            if (versions.Count == 0)
            {
                if (force)
                {
                    return;
                }
                throw new ArgumentException("No packages found");
            }

            if (!force && versions.Count > 1)
            {
                foreach (var dir in versions)
                {
                    WriteLine(dir.FullName.ToRelativePath());
                }

                if (!Confirm("The search returned more than one package -- delete all of them?"))
                {
                    return;
                }
            }

            foreach (var dir in versions)
            {
                Disk.DeleteDirectory(dir.FullName, true);
            }

            // Delete any remaining empty directories
            foreach (var package in input)
            {
                foreach (var dir in cache.EnumeratePackages(package))
                {
                    if (dir.EnumerateFileSystemInfos().FirstOrDefault() == null)
                    {
                        Disk.DeleteDirectory(dir.FullName, true);
                    }
                }
            }
        }