public async Task <int> ExecuteAsync(CancellationToken cancellationToken)
        {
            if (this.ShowHelp || !this.Subcommand.HasValue)
            {
                DisplayHelp();
                return(1);
            }

            var success      = false;
            var cacheManager = new ExtensionCacheManager();

            switch (this.Subcommand)
            {
            case CacheSubcommand.Add:
                success = await this.AddExtensions(cacheManager, cancellationToken);

                break;

            case CacheSubcommand.Remove:
                success = await this.RemoveExtensions(cacheManager, cancellationToken);

                break;

            case CacheSubcommand.List:
                success = await this.ListExtensions(cacheManager, cancellationToken);

                break;
            }

            return(success ? 0 : 2);
        }
        private static ExtensionCacheManager CreateExtensionCacheManager(IWixToolsetCoreServiceProvider coreProvider, Dictionary <Type, object> singletons)
        {
            var extensionCacheManager = new ExtensionCacheManager();

            singletons.Add(typeof(ExtensionCacheManager), extensionCacheManager);

            return(extensionCacheManager);
        }
        private async Task <bool> RemoveExtensions(ExtensionCacheManager cacheManager, CancellationToken cancellationToken)
        {
            var success = false;

            foreach (var extensionRef in this.ExtensionReferences)
            {
                var removed = await cacheManager.RemoveAsync(this.Global, extensionRef, cancellationToken);

                success |= removed;
            }

            return(success);
        }
        private async Task <bool> ListExtensions(ExtensionCacheManager cacheManager, CancellationToken cancellationToken)
        {
            var found        = false;
            var extensionRef = this.ExtensionReferences.FirstOrDefault();

            var extensions = await cacheManager.ListAsync(this.Global, extensionRef, cancellationToken);

            foreach (var extension in extensions)
            {
                this.Messaging.Write($"{extension.Id} {extension.Version}{(extension.Damaged ? " (damaged)" : String.Empty)}");
                found = true;
            }

            return(found);
        }