Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions cmd/xc/deprecation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@ import (
)

func warnInteractive(tasks models.Tasks) {
var logger = log.New(os.Stderr, "warning: xc: ", 0)
var interactiveTasks []string
for _, task := range tasks {
if task.Interactive {
interactiveTasks = append(interactiveTasks, task.Name)
}
}
if len(interactiveTasks) > 0 {
logger := log.New(os.Stderr, "warning: xc: ", 0)
if len(interactiveTasks) == 1 {
logger.Printf(`Task "%s" is set to Interactive,
which is a deprecated attribute that has no effect.
You can safely remove the attribute.
(see https://github.com/joerdav/xc/issues/127)`, task.Name)
(see https://github.com/joerdav/xc/issues/127)`, interactiveTasks[0])
} else {
logger.Printf(`Tasks %v are set to Interactive,
which is a deprecated attribute that has no effect.
You can safely remove the attribute.
(see https://github.com/joerdav/xc/issues/127)`, interactiveTasks)
}
}
}
49 changes: 49 additions & 0 deletions cmd/xc/deprecation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,52 @@ func TestInteractiveWarning(t *testing.T) {
t.Fatal("warning explanation does not contain repo link")
}
}

func TestInteractiveWarningMultiple(t *testing.T) {
tasks := models.Tasks{
{
Name: "task1",
Script: "echo task1",
Interactive: true,
},
{
Name: "task2",
Script: "echo task2",
},
{
Name: "task3",
Script: "echo task3",
Interactive: true,
},
}
orig := os.Stderr
r, w, _ := os.Pipe()
defer w.Close()
defer r.Close()
os.Stderr = w
defer func() {
os.Stderr = orig
}()
warnInteractive(tasks)
w.Close()
os.Stderr = orig
res, _ := io.ReadAll(r)
result := string(res)

// Should contain both task names in a single warning
if !strings.Contains(result, "task1") {
t.Fatal("warning does not contain task1")
}
if !strings.Contains(result, "task3") {
t.Fatal("warning does not contain task3")
}
if !strings.Contains(result, "Interactive") {
t.Fatal("warning does not contain 'Interactive'")
}

// Should only have one warning message (count occurrences of "warning:")
warningCount := strings.Count(result, "warning: xc:")
if warningCount != 1 {
t.Fatalf("expected 1 warning message, got %d", warningCount)
}
}