Beispiel #1
0
        private static void Run(CommandLineApplication cmd, ILogger log)
        {
            cmd.Description = "Read or modify feed settings stored in sleet.settings.json for the 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);

            cmd.HelpOption(Constants.HelpOption);

            var unsetAll        = cmd.Option("--unset-all", "Clear all feed settings.", CommandOptionType.NoValue);
            var unset           = cmd.Option("--unset", "Remove a feed setting. May be specified multiple times.", CommandOptionType.MultipleValue);
            var setSetting      = cmd.Option("--set", "Add a feed setting. Value must be in the form {key}:{value}  May be specified multiple times.", CommandOptionType.MultipleValue);
            var getSetting      = cmd.Option("--get", "Display a feed setting. May be specified multiple times.", CommandOptionType.MultipleValue);
            var getAll          = cmd.Option("--get-all", "Diplay all feed settings.", CommandOptionType.NoValue);
            var propertyOptions = cmd.Option(Constants.PropertyOption, Constants.PropertyDescription, CommandOptionType.MultipleValue);

            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 = Util.CreateFileSystemOrThrow(settings, sourceName.Value(), cache);

                    var success = await FeedSettingsCommand.RunAsync(
                        settings,
                        fileSystem,
                        unsetAll.HasValue(),
                        getAll.HasValue(),
                        getSetting.Values,
                        unset.Values,
                        setSetting.Values,
                        log,
                        CancellationToken.None);

                    return(success ? 0 : 1);
                }
            });
        }
Beispiel #2
0
        public static Task <int> MainCore(string[] args, ILogger log)
        {
            CmdUtils.LaunchDebuggerIfSet(ref args, log);

            var app = new CommandLineApplication()
            {
                Name     = "sleet",
                FullName = "Sleet"
            };

            app.HelpOption(Constants.HelpOption);
            app.VersionOption("--version", AssemblyVersionHelper.GetVersion().ToFullVersionString());

            Configure();

            InitAppCommand.Register(app, log);
            PushAppCommand.Register(app, log);
            DeleteAppCommand.Register(app, log);
            ValidateAppCommand.Register(app, log);
            StatsAppCommand.Register(app, log);
            CreateConfigAppCommand.Register(app, log);
            DestroyAppCommand.Register(app, log);
            DownloadAppCommand.Register(app, log);
            RecreateAppCommand.Register(app, log);
            FeedSettingsAppCommand.Register(app, log);
            RetentionAppCommand.Register(app, log);

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

            var exitCode = 1;

            try
            {
                exitCode = app.Execute(args);
            }
            catch (CommandParsingException ex)
            {
                ex.Command.ShowHelp();
            }
            catch (Exception ex)
            {
                ExceptionUtils.LogException(ex, log);
            }

            return(Task.FromResult(exitCode));
        }
Beispiel #3
0
        private static void Run(CommandLineApplication cmd, ILogger log)
        {
            cmd.Description = "Push a package to 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 forceName = cmd.Option("-f|--force", "Overwrite existing packages.",
                                       CommandOptionType.NoValue);

            var skipExisting    = cmd.Option("--skip-existing", "Skip packages that already exist on the feed.", CommandOptionType.NoValue);
            var propertyOptions = cmd.Option(Constants.PropertyOption, Constants.PropertyDescription, CommandOptionType.MultipleValue);

            var argRoot = cmd.Argument(
                "[root]",
                "Paths to individual packages or directories containing packages.",
                multipleValues: true);

            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 = Util.CreateFileSystemOrThrow(settings, sourceName.Value(), cache);

                    var success = await PushCommand.RunAsync(settings, fileSystem, argRoot.Values.ToList(), forceName.HasValue(), skipExisting.HasValue(), log);

                    return(success ? 0 : 1);
                }
            });
        }
Beispiel #4
0
        private static void Run(CommandLineApplication cmd, ILogger log)
        {
            cmd.Description = "Download packages from a feed to a local folder.";

            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 outputPath   = cmd.Option("-o|--output-path", "Output directory to store downloaded nupkgs.", CommandOptionType.SingleValue);
            var skipExisting = cmd.Option("--skip-existing", "Skip packages that already exist in the output folder.", CommandOptionType.NoValue);
            var noLock       = cmd.Option("--no-lock", "Skip locking the feed and verifying the client version.", CommandOptionType.NoValue);
            var ignoreErrors = cmd.Option("--ignore-errors", "Ignore download errors.", CommandOptionType.NoValue);

            var required = new List <CommandOption>()
            {
                outputPath
            };

            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 = Util.CreateFileSystemOrThrow(settings, sourceName.Value(), cache);

                    // Download packages
                    var success = await DownloadCommand.RunAsync(settings, fileSystem, outputPath.Value(), ignoreErrors.HasValue(), noLock.HasValue(), skipExisting.HasValue(), log);

                    return(success ? 0 : 1);
                }
            });
        }
Beispiel #5
0
        private static void Run(CommandLineApplication cmd, ILogger log)
        {
            cmd.Description = "Recreate a feed. This downloads all packages, deletes the feed, and then creates a new feed from the existing packages. This may be used to fix feed problems or to upgrade between Sleet versions.";

            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);

            cmd.HelpOption(Constants.HelpOption);

            var nupkgPath = cmd.Option("--nupkg-path", "Optional temporary directory to store downloaded nupkgs in. This folder will be cleaned up if the command completes successfully. If the command fails these files will be left as a backup.", CommandOptionType.SingleValue);

            var force           = cmd.Option("-f|--force", "Ignore errors when recreating the feed.", CommandOptionType.NoValue);
            var propertyOptions = cmd.Option(Constants.PropertyOption, Constants.PropertyDescription, CommandOptionType.MultipleValue);

            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 tmpPath = nupkgPath.HasValue() ? nupkgPath.Value() : null;

                    // Run
                    var success = await RecreateCommand.RunAsync(settings, fileSystem, tmpPath, force.HasValue(), log);

                    return(success ? 0 : 1);
                }
            });
        }
Beispiel #6
0
 internal static void SetVerbosity(ILogger log, bool verbose)
 {
     if (log is ConsoleLogger consoleLogger)
     {
         if (CmdUtils.IsDebugModeEnabled())
         {
             consoleLogger.VerbosityLevel = LogLevel.Debug;
         }
         else if (verbose)
         {
             consoleLogger.VerbosityLevel = LogLevel.Verbose;
         }
         else
         {
             consoleLogger.VerbosityLevel   = DefaultLogLevel;
             consoleLogger.CollapseMessages = true;
         }
     }
 }