From ffe3a8afeb4d20918a8c74f9d7ceeb2c1699a2d7 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Fri, 31 Jul 2026 01:15:39 +0000 Subject: [PATCH] pipeline: clarify selected workflow cancellation --- internal/cli/pipeline_cancel.go | 27 ++++++++++++++++++--------- internal/cli/pipeline_cancel_test.go | 11 +++++++++++ 2 file(s) changed, 29 insertion(s)(+), 9 deletion(s)(-) diff --git a/internal/cli/pipeline_cancel.go b/internal/cli/pipeline_cancel.go --- a/internal/cli/pipeline_cancel.go +++ b/internal/cli/pipeline_cancel.go @@ -2,6 +2,7 @@ import ( "fmt" + "io" "strings" "github.com/alyraffauf/tg/internal/app" @@ -30,19 +31,27 @@ return err } return output(cmd, result, func(result *app.PipelineCancelResult) { - if !result.CancellationRequested { - fmt.Fprintf(cmd.OutOrStdout(), "Pipeline %s has no pending or running workflows.\n", result.Pipeline) - return - } - if len(workflows) == 0 { - fmt.Fprintf(cmd.OutOrStdout(), "Cancellation requested for pipeline %s.\n", result.Pipeline) - return - } - fmt.Fprintf(cmd.OutOrStdout(), "Cancellation requested for workflows %s in pipeline %s.\n", strings.Join(result.Workflows, ", "), result.Pipeline) + renderPipelineCancellation(cmd.OutOrStdout(), result, len(workflows) > 0) }) }, } command.Flags().StringVarP(&repository, "repo", "R", "", "Target repository as handle/repo") command.Flags().StringSliceVarP(&workflows, "workflow", "w", nil, "Workflow name to cancel (repeatable)") return command +} + +func renderPipelineCancellation(writer io.Writer, result *app.PipelineCancelResult, selectedWorkflows bool) { + if !result.CancellationRequested { + if selectedWorkflows { + fmt.Fprintln(writer, "None of the selected workflows are pending or running.") + return + } + fmt.Fprintf(writer, "Pipeline %s has no pending or running workflows.\n", result.Pipeline) + return + } + if !selectedWorkflows { + fmt.Fprintf(writer, "Cancellation requested for pipeline %s.\n", result.Pipeline) + return + } + fmt.Fprintf(writer, "Cancellation requested for workflows %s in pipeline %s.\n", strings.Join(result.Workflows, ", "), result.Pipeline) } diff --git a/internal/cli/pipeline_cancel_test.go b/internal/cli/pipeline_cancel_test.go --- a/internal/cli/pipeline_cancel_test.go +++ b/internal/cli/pipeline_cancel_test.go @@ -1,6 +1,7 @@ package cli import ( + "bytes" "testing" "github.com/alyraffauf/tg/internal/app" @@ -15,5 +16,15 @@ if command.Flags().Lookup(name) == nil { t.Errorf("pipeline cancel has no --%s flag", name) } + } +} + +func TestRenderPipelineCancellationForUncancellableSelection(t *testing.T) { + var output bytes.Buffer + renderPipelineCancellation(&output, &app.PipelineCancelResult{Pipeline: "pipeline-123"}, true) + + const want = "None of the selected workflows are pending or running.\n" + if output.String() != want { + t.Fatalf("renderPipelineCancellation() = %q, want %q", output.String(), want) } } -- tangled.sh