protected override async Task Initialize(Spectre.Console.ProgressContext ctx) { await runInitStep(ctx, "Checking Docker connection", () => DockerConnectionHelper.CheckConnection()); var imagesToPull = new List <string>(); await runInitStep(ctx, "Checking Docker images", async() => { if (!await ImagePuller.CheckImageExists(ImageName)) { imagesToPull.Add(ImageName); } if (!string.IsNullOrEmpty(ServiceContainerImage) && !await ImagePuller.CheckImageExists(ServiceContainerImage)) { imagesToPull.Add(ServiceContainerImage); } }); foreach (var imageName in imagesToPull) { await runInitStep(ctx, $"Pulling {imageName}", () => ImagePuller.Pull(imageName)); } }
private async Task runInitStep(Spectre.Console.ProgressContext ctx, string name, Func <Task> action) { var progressPrepare = ctx.AddTask(name); try { await action(); } catch (Exception ex) { throw new CliFx.Exceptions.CommandException(ex.Message); } progressPrepare.MaxValue = progressPrepare.Value = 1; }