예제 #1
0
        private static void Run(CommandLineApplication cmd, ILogger log)
        {
            cmd.Description = "Validate a feed.";

            var optionConfigFile = cmd.Option(Constants.ConfigOption, Constants.ConfigDesc,
                                              CommandOptionType.SingleValue);

            var sourceName = cmd.Option(Constants.SourceOption, Constants.SourceDesc,
                                        CommandOptionType.SingleValue);

            var verbose         = cmd.Option(Constants.VerboseOption, Constants.VerboseDesc, CommandOptionType.NoValue);
            var propertyOptions = cmd.Option(Constants.PropertyOption, Constants.PropertyDescription, CommandOptionType.MultipleValue);

            cmd.HelpOption(Constants.HelpOption);

            var required = new List <CommandOption>();

            cmd.OnExecute(async() =>
            {
                // Validate parameters
                CmdUtils.VerifyRequiredOptions(required.ToArray());

                // Init logger
                Util.SetVerbosity(log, verbose.HasValue());

                // Create a temporary folder for caching files during the operation.
                using (var cache = new LocalCache())
                {
                    // Load settings and file system.
                    var settings   = LocalSettings.Load(optionConfigFile.Value(), SettingsUtility.GetPropertyMappings(propertyOptions.Values));
                    var fileSystem = await Util.CreateFileSystemOrThrow(settings, sourceName.Value(), cache);

                    var success = await ValidateCommand.RunAsync(settings, fileSystem, log);

                    return(success ? 0 : 1);
                }
            });
        }
예제 #2
0
        public static async Task <bool> RunAsync(LocalSettings settings, ISleetFileSystem source, string tmpPath, bool force, ILogger log)
        {
            var success     = true;
            var cleanNupkgs = true;

            var        token      = CancellationToken.None;
            LocalCache localCache = null;

            // Use the tmp path if provided
            if (string.IsNullOrEmpty(tmpPath))
            {
                localCache = new LocalCache();
            }
            else
            {
                localCache = new LocalCache(tmpPath);
            }

            log.LogMinimal($"Reading feed {source.BaseURI.AbsoluteUri}");

            using (var feedLock = await SourceUtility.VerifyInitAndLock(settings, source, "Recreate", log, token))
            {
                if (!force)
                {
                    // Validate source
                    await UpgradeUtility.EnsureCompatibility(source, log : log, token : token);
                }

                // Read settings and persist them in the new feed.
                var feedSettings = await FeedSettingsUtility.GetSettingsOrDefault(source, log, token);

                try
                {
                    var downloadSuccess = await DownloadCommand.DownloadPackages(settings, source, localCache.Root.FullName, force, log, token);

                    if (!force && !downloadSuccess)
                    {
                        log.LogError("Unable to recreate the feed due to errors download packages. Use --force to skip this check.");
                        return(false);
                    }

                    var destroySuccess = await DestroyCommand.Destroy(settings, source, log, token);

                    if (!force && !destroySuccess)
                    {
                        log.LogError("Unable to completely remove the old feed before recreating. Use --force to skip this check.");
                        return(false);
                    }

                    var initSuccess = await InitCommand.InitAsync(settings, source, feedSettings, log, token);

                    if (!initSuccess)
                    {
                        cleanNupkgs = false;

                        log.LogError("Unable to initialize the new feed. The feed is currently broken and must be repaired manually.");
                        success = false;
                        return(false);
                    }

                    // Skip pushing for empty feeds
                    if (Directory.GetFiles(localCache.Root.FullName, "*.*", SearchOption.AllDirectories).Length > 0)
                    {
                        var pushSuccess = await PushCommand.PushPackages(settings, source, new List <string>() { localCache.Root.FullName }, force : true, skipExisting : true, log : log, token : token);

                        if (!pushSuccess)
                        {
                            cleanNupkgs = false;

                            log.LogError("Unable to push packages to the new feed. Try pushing the nupkgs again manually.");
                            success = false;
                            return(false);
                        }
                    }

                    var validateSuccess = await ValidateCommand.Validate(settings, source, log, token);

                    if (!validateSuccess)
                    {
                        cleanNupkgs = false;

                        log.LogError("Something went wrong when recreating the feed. Feed validation has failed.");
                        success = false;
                        return(false);
                    }
                }
                finally
                {
                    if (cleanNupkgs)
                    {
                        // Delete downloaded nupkgs
                        log.LogInformation($"Removing local nupkgs from {localCache.Root.FullName}");
                        localCache.Dispose();
                    }
                    else
                    {
                        var message = $"Encountered an error while recreating the feed. You may need to manually create the feed and push the nupkgs again. Nupkgs have been saved to: {localCache.Root.FullName}";

                        if (force)
                        {
                            log.LogWarning(message);
                        }
                        else
                        {
                            log.LogError(message);
                        }
                    }
                }

                log.LogMinimal("Feed recreation complete.");
            }

            return(success);
        }
예제 #3
0
 public static Task <int> RunCore(LocalSettings settings, ISleetFileSystem source, ILogger log)
 {
     return(ValidateCommand.RunCore(settings, source, log));
 }
예제 #4
0
        public static Task <int> MainCore(string[] args, ILogger log)
        {
#if DEBUG
            if (args.Contains("--debug"))
            {
                args = args.Skip(1).ToArray();
                while (!Debugger.IsAttached)
                {
                }

                Debugger.Break();
            }
#endif

            var app = new CommandLineApplication();
            app.Name     = "sleet";
            app.FullName = "Sleet";
            app.HelpOption("-h|--help");
            app.VersionOption("--version", Constants.SleetVersion.ToFullVersionString());

            InitCommand.Register(app, log);
            PushCommand.Register(app, log);
            DeleteCommand.Register(app, log);
            ValidateCommand.Register(app, log);
            StatsCommand.Register(app, log);
            CreateConfigCommand.Register(app, log);

            app.OnExecute(() =>
            {
                app.ShowHelp();
                return(0);
            });

            var exitCode = 0;

            try
            {
                exitCode = app.Execute(args);
            }
            catch (CommandParsingException ex)
            {
                ex.Command.ShowHelp();
            }
            catch (AggregateException ex)
            {
                exitCode = 1;

                foreach (var inner in ex.InnerExceptions)
                {
                    log.LogError(inner.Message);
                    log.LogDebug(inner.ToString());
                }
            }
            catch (Exception ex)
            {
                exitCode = 1;
                log.LogError(ex.Message);
                log.LogDebug(ex.ToString());
            }

            return(Task.FromResult(exitCode));
        }