Beispiel #1
0
        private static void Run(CommandLineApplication cmd, ILogger log)
        {
            cmd.Description = "Delete a package or packages from a feed.";

            var optionConfigFile = cmd.Option("-c|--config", "sleet.json file to read sources and settings from.",
                                              CommandOptionType.SingleValue);

            var sourceName = cmd.Option("-s|--source", "Source name from sleet.json.",
                                        CommandOptionType.SingleValue);

            var packageId = cmd.Option("-i|--id", "Package id.",
                                       CommandOptionType.SingleValue);

            var version = cmd.Option("-v|--version", "Package version. If this is not specified all versions will be deleted.",
                                     CommandOptionType.SingleValue);

            var reason = cmd.Option("-r|--reason", "Reason for deleting the package.", CommandOptionType.SingleValue);

            var force = cmd.Option("-f|--force", "Ignore missing packages.", CommandOptionType.NoValue);

            cmd.HelpOption("-?|-h|--help");

            var required = new List <CommandOption>()
            {
                sourceName,
                packageId
            };

            cmd.OnExecute(async() =>
            {
                cmd.ShowRootCommandFullNameAndVersion();

                // Validate parameters
                foreach (var requiredOption in required)
                {
                    if (!requiredOption.HasValue())
                    {
                        throw new ArgumentException($"Missing required parameter --{requiredOption.LongName}.");
                    }
                }

                var settings = LocalSettings.Load(optionConfigFile.Value());

                using (var cache = new LocalCache())
                {
                    var fileSystem = FileSystemFactory.CreateFileSystem(settings, cache, sourceName.Value());

                    if (fileSystem == null)
                    {
                        throw new InvalidOperationException("Unable to find source. Verify that the --source parameter is correct and that sleet.json contains the named source.");
                    }

                    return(await RunCore(settings, fileSystem, packageId.Value(), version.Value(), reason.Value(), force.HasValue(), log));
                }
            });
        }
Beispiel #2
0
        private static void Run(CommandLineApplication cmd, ILogger log)
        {
            cmd.Description = "Validate a feed.";

            var optionConfigFile = cmd.Option("-c|--config", "sleet.json file to read sources and settings from.",
                                              CommandOptionType.SingleValue);

            var sourceName = cmd.Option("-s|--source", "Source name from sleet.json.",
                                        CommandOptionType.SingleValue);

            cmd.HelpOption("-?|-h|--help");

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

            cmd.OnExecute(async() =>
            {
                try
                {
                    cmd.ShowRootCommandFullNameAndVersion();

                    // Validate parameters
                    foreach (var requiredOption in required)
                    {
                        if (!requiredOption.HasValue())
                        {
                            throw new ArgumentException($"Missing required parameter --{requiredOption.LongName}.");
                        }
                    }

                    var settings = LocalSettings.Load(optionConfigFile.Value());

                    using (var cache = new LocalCache())
                    {
                        var fileSystem = FileSystemFactory.CreateFileSystem(settings, cache, sourceName.Value());

                        if (fileSystem == null)
                        {
                            throw new InvalidOperationException("Unable to find source. Verify that the --source parameter is correct and that sleet.json contains the named source.");
                        }

                        return(await RunCore(settings, fileSystem, log));
                    }
                }
                catch (Exception ex)
                {
                    log.LogError(ex.Message);
                    log.LogDebug(ex.ToString());
                }

                return(1);
            });
        }
Beispiel #3
0
        internal static async Task <ISleetFileSystem> CreateFileSystemOrThrow(LocalSettings settings, string sourceName, LocalCache cache)
        {
            var sourceNamePassed = !string.IsNullOrEmpty(sourceName);

            // Default to the only possible feed if one was not provided.
            if (string.IsNullOrEmpty(sourceName))
            {
                var names = GetSourceNames(settings.Json);

                if (names.Count == 1)
                {
                    sourceName = names[0];
                }
            }

            // Initialize the network/proxy settings before creating the filesystem
            InitNetwork(settings);

            // Create
            var fileSystem = await FileSystemFactory.CreateFileSystemAsync(settings, cache, sourceName);

            if (fileSystem == null)
            {
                var message = "Unable to find source. Verify that the --source parameter is correct and that sleet.json contains the named source.";

                if (!sourceNamePassed)
                {
                    var names = GetSourceNames(settings.Json);

                    if (names.Count < 1)
                    {
                        message = "The local settings file is missing or does not contain any sources. Use 'CreateConfig' to add a source.";
                    }
                    else
                    {
                        message = "The local settings file contains multiple sources. Use --source to specify the feed to use.";
                    }
                }

                throw new InvalidOperationException(message);
            }

            return(fileSystem);
        }