Skip to content

Commit af260e4

Browse files
committed
feat(cli): allow 'unirtm run' to list tasks when invoked without arguments
- Updated 'run' command to accept 0 minimum arguments. - If no arguments are provided, it now enumerates and beautifully prints all tasks available in the current context via the routing engine. - This aligns the functionality directly with 'mise run'/'mise tasks', providing a quick overview of available targets before execution.
1 parent 3196eb1 commit af260e4

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

cmd/25.run.go

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"fmt"
99
"os"
1010

11+
"github.com/pterm/pterm"
12+
"golang.org/x/term"
1113
"github.com/snowdreamtech/unirtm/internal/cli/output"
1214
"github.com/snowdreamtech/unirtm/internal/config"
1315
"github.com/snowdreamtech/unirtm/internal/pkg/env"
@@ -24,22 +26,27 @@ func init() {
2426

2527
// runCmd represents the run command which executes a task via the routing engine.
2628
var runCmd = &cobra.Command{
27-
Use: "run <task> [args...]",
29+
Use: "run [task] [args...]",
2830
Short: "Run a task using the multi-modal routing engine",
2931
Long: `Run a task using the multi-modal routing engine.
3032
3133
UniRTM delegates tasks to professional tools (go-task, make, just)
3234
if their configuration files are detected, or falls back to executing
3335
tasks defined in unirtm.toml.
3436
37+
If no task is provided, it lists all available tasks.
38+
3539
Examples:
40+
# List all available tasks
41+
unirtm run
42+
3643
# Run a build task
3744
unirtm run build
3845
3946
# Run a task with arguments
4047
unirtm run test -- -v`,
4148
Aliases: []string{"r"},
42-
Args: cobra.MinimumNArgs(1),
49+
Args: cobra.MinimumNArgs(0),
4350
DisableFlagParsing: false,
4451
RunE: runTaskCommand,
4552
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
@@ -68,13 +75,6 @@ Examples:
6875

6976
// runTaskCommand executes the task routing.
7077
func runTaskCommand(cmd *cobra.Command, args []string) error {
71-
taskName := args[0]
72-
taskArgs := args[1:]
73-
74-
// Separate args if there's a "--" separator, but cobra handles arguments
75-
// after -- properly into args depending on config, but if they put it we might need to parse.
76-
// Actually args[1:] is fine.
77-
7878
ctx := context.Background()
7979

8080
// Load configuration
@@ -126,6 +126,31 @@ func runTaskCommand(cmd *cobra.Command, args []string) error {
126126
return fmt.Errorf("failed to get current directory: %w", err)
127127
}
128128

129+
if len(args) == 0 {
130+
tasks := engine.ListTasks(cwd)
131+
if len(tasks) == 0 {
132+
pterm.Info.Println("No tasks available in current context.")
133+
return nil
134+
}
135+
136+
isTerminal := term.IsTerminal(int(os.Stdout.Fd()))
137+
if isTerminal {
138+
pterm.DefaultSection.Println("Available Tasks")
139+
} else {
140+
fmt.Println("Available Tasks:")
141+
}
142+
143+
var taskItems []pterm.BulletListItem
144+
for _, t := range tasks {
145+
taskItems = append(taskItems, pterm.BulletListItem{Level: 0, Text: pterm.FgCyan.Sprint(t)})
146+
}
147+
pterm.DefaultBulletList.WithItems(taskItems).Render()
148+
return nil
149+
}
150+
151+
taskName := args[0]
152+
taskArgs := args[1:]
153+
129154
// Prepare environment injects
130155
shimsDir := env.GetShimsDir()
131156
envInjects := []string{

0 commit comments

Comments
 (0)