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.
2628var 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
3133UniRTM delegates tasks to professional tools (go-task, make, just)
3234if their configuration files are detected, or falls back to executing
3335tasks defined in unirtm.toml.
3436
37+ If no task is provided, it lists all available tasks.
38+
3539Examples:
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.
7077func 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