Skip to content

Commit

Permalink
Add indicator what's included in "run all" to list commands (#664)
Browse files Browse the repository at this point in the history
Simple `*` at the end of the command means what's included in `run
--all` when running `runme list` or `runme beta list`.
  • Loading branch information
sourishkrout authored Sep 16, 2024
1 parent 77ace52 commit 2f6f670
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 41 deletions.
16 changes: 14 additions & 2 deletions internal/cmd/beta/list_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package beta
import (
"bytes"
"encoding/json"
"fmt"
"strings"

"github.com/cli/go-gh/v2/pkg/jsonpretty"
Expand Down Expand Up @@ -107,15 +108,26 @@ func renderTasksAsTableForCmd(cmd *cobra.Command, tasks []project.Task) error {
named = "No"
}

table.AddField(task.CodeBlock.Name())
name := task.CodeBlock.Name()
if !task.CodeBlock.ExcludeFromRunAll() {
name = name + "*"
}
table.AddField(name)
table.AddField(project.GetRelativePath(getCwd(), task.DocumentPath))
table.AddField(renderLineFromLines(task.CodeBlock.Lines()))
table.AddField(task.CodeBlock.Intro())
table.AddField(named)
table.EndRow()
}

return errors.WithStack(table.Render())
err = errors.WithStack(table.Render())

if !term.IsTTY() {
return err
}

_, _ = fmt.Fprintf(term.ErrOut(), "\n*) Included when running all via \"run --all\"\n")
return err
}

// TODO(adamb): output should be well-defined. It's questionable whether
Expand Down
18 changes: 16 additions & 2 deletions internal/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"bytes"
"encoding/json"
"fmt"
"strings"

"github.com/cli/cli/v2/pkg/iostreams"
Expand All @@ -21,6 +22,7 @@ type row struct {
FirstCommand string `json:"first_command"`
Description string `json:"description"`
Named bool `json:"named"`
RunAll bool `json:"run_all"`
}

func listCmd() *cobra.Command {
Expand Down Expand Up @@ -64,11 +66,19 @@ func listCmd() *cobra.Command {
FirstCommand: shell.TryGetNonCommentLine(lines),
Description: block.Intro(),
Named: !block.IsUnnamed(),
RunAll: !block.ExcludeFromRunAll(),
}
rows = append(rows, r)
}
if !formatJSON {
return displayTable(io, rows)
err := displayTable(io, rows)

if !io.IsStderrTTY() {
return err
}

_, _ = fmt.Fprintf(io.ErrOut, "\n*) Included when running all via \"run --all\"\n")
return err
}

return displayJSON(io, rows)
Expand Down Expand Up @@ -97,7 +107,11 @@ func displayTable(io *iostreams.IOStreams, rows []row) error {
if !row.Named {
named = "No"
}
table.AddField(row.Name)
name := row.Name
if row.RunAll {
name += "*"
}
table.AddField(name)
table.AddField(row.File)
table.AddField(row.FirstCommand)
table.AddField(row.Description)
Expand Down
4 changes: 2 additions & 2 deletions testdata/beta/find_repo_upward.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ echo root-ignored

-- result-ls.txt --
NAME FILE FIRST COMMAND DESCRIPTION NAMED
nested-hello README.md echo nested-hello Yes
root-hello ../README.md echo root-hello Yes
nested-hello* README.md echo nested-hello Yes
root-hello* ../README.md echo root-hello Yes
-- result-print.txt --
# ../README.md:root-hello
echo root-hello
Expand Down
19 changes: 19 additions & 0 deletions testdata/beta/include_indicator.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# prints an asterisk next to included tasks
exec runme beta list
cmp stdout result-list.txt
! stderr .

-- INCLUDED.md --
```sh {"name": "included"}
echo included
```

-- EXCLUDED.md --
```sh {"name": "excluded", "excludeFromRunAll": true}
echo excluded
```

-- result-list.txt --
NAME FILE FIRST COMMAND DESCRIPTION NAMED
excluded EXCLUDED.md echo excluded Yes
included* INCLUDED.md echo included Yes
2 changes: 1 addition & 1 deletion testdata/beta/project_dir_nested.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ echo nested-hello

-- result-ls.txt --
NAME FILE FIRST COMMAND DESCRIPTION NAMED
nested-hello nested/README.md echo nested-hello Yes
nested-hello* nested/README.md echo nested-hello Yes
-- result-print.txt --
# nested/README.md:nested-hello
echo nested-hello
19 changes: 19 additions & 0 deletions testdata/flags/include_indicator.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# prints an asterisk next to included tasks
exec runme list
cmp stdout result-list.txt
! stderr .

-- INCLUDED.md --
```sh {"name": "included"}
echo included
```

-- EXCLUDED.md --
```sh {"name": "excluded", "excludeFromRunAll": true}
echo excluded
```

-- result-list.txt --
NAME FILE FIRST COMMAND DESCRIPTION NAMED
excluded EXCLUDED.md echo excluded Yes
included* INCLUDED.md echo included Yes
10 changes: 5 additions & 5 deletions testdata/flags/project.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ say_hi()
```
-- gitupwards.txt --
NAME FILE FIRST COMMAND DESCRIPTION NAMED
echo file.md echo "Hello, runme!" Yes
hello-js ../root.md console.log("Hello, runme, from javascript!") It can even run scripting languages. Yes
hello-js-cat ../root.md console.log("Hello, runme, from javascript!") And it can even run a cell with a custom interpreter. Yes
hello-python ../root.md def say_hi(): Yes
echo* file.md echo "Hello, runme!" Yes
hello-js* ../root.md console.log("Hello, runme, from javascript!") It can even run scripting languages. Yes
hello-js-cat* ../root.md console.log("Hello, runme, from javascript!") And it can even run a cell with a custom interpreter. Yes
hello-python* ../root.md def say_hi(): Yes
-- projectset.txt --
NAME FILE FIRST COMMAND DESCRIPTION NAMED
echo nested/file.md echo "Hello, runme!" Yes
echo* nested/file.md echo "Hello, runme!" Yes
12 changes: 6 additions & 6 deletions testdata/flags/relative.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ runme:

It can even run scripting languages:

```js {"name":"hello-js"}
```js {"name":"hello-js","excludeFromRunAll":"true"}
console.log("Hello, runme, from javascript!")
```

Expand Down Expand Up @@ -76,9 +76,9 @@ say_hi()
```
-- very/deeply/relative.txt --
NAME FILE FIRST COMMAND DESCRIPTION NAMED
count sub.md echo "1" It can contain multiple lines too. Yes
again ../another.md echo "Hello, runme! Again!" Yes
echo nested/file.md echo "Hello, runme!" Yes
count* sub.md echo "1" It can contain multiple lines too. Yes
again* ../another.md echo "Hello, runme! Again!" Yes
echo* nested/file.md echo "Hello, runme!" Yes
hello-js ../../root.md console.log("Hello, runme, from javascript!") It can even run scripting languages. Yes
hello-js-cat ../../root.md console.log("Hello, runme, from javascript!") And it can even run a cell with a custom interpreter. Yes
hello-python ../../root.md def say_hi(): Yes
hello-js-cat* ../../root.md console.log("Hello, runme, from javascript!") And it can even run a cell with a custom interpreter. Yes
hello-python* ../../root.md def say_hi(): Yes
4 changes: 2 additions & 2 deletions testdata/permissions/basic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ $ echo "Hello, runme 2!"

-- output.txt --
NAME FILE FIRST COMMAND DESCRIPTION NAMED
command1 README.md echo "Hello, runme 1!" Yes
command2 README.md echo "Hello, runme 2!" Yes
command1* README.md echo "Hello, runme 1!" Yes
command2* README.md echo "Hello, runme 2!" Yes
41 changes: 41 additions & 0 deletions testdata/prompts/basic.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
env SHELL=/bin/bash
exec runme run --all --category=foo --filename=PROMPTS.md
cmp stdout foo-bar-list.txt
! stderr .

-- PROMPTS.md --

```sh {"id":"01HQQZ50CYM981N6X20VMRJYXV","promptEnv":""}
echo "<empty>"
```

```sh {"id":"01HQQZ60MHZEDTXWG70PMXZNHH","promptEnv":"auto"}
echo "auto"
```

```sh {"id":"01HQQZ6WBD82EQ39ZR7N49XV7B","promptEnv":"yes"}
echo "yes"
```

```sh {"id":"01HQQZ7AYPP87D1MB6D06G9BTX","promptEnv":"no"}
echo "no"
```

-- foo-bar-list.txt --
► Running task set-env...
► ✓ Task set-env exited with code 0
► Running task print-foo...
foo!
► ✓ Task print-foo exited with code 0
► Running task print-bar...
bar!
► ✓ Task print-bar exited with code 0
-- bar-list.txt --
bar!
-- buzz-bar-list.txt --
► Running task print-bar...
bar!
► ✓ Task print-bar exited with code 0
► Running task print-buzz...
buzz!
► ✓ Task print-buzz exited with code 0
47 changes: 26 additions & 21 deletions testdata/script/basic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ echo Inferred

With `{"name":"hello"}` you can annotate it and give it a nice name:

```sh {"name":"echo"}
```sh {"name":"echo","excludeFromRunAll":"true"}
$ echo "Hello, runme!"
```

Expand Down Expand Up @@ -187,59 +187,64 @@ $ echo "Runs as shell script"
-- golden-list.txt --
NAME FILE FIRST COMMAND DESCRIPTION NAMED
echo README.md echo "Hello, runme!" With {"name":"hello"} you can annotate it and give it a nice name. Yes
hello-js README.md console.log("Hello, runme, from javascript!") It can even run scripting languages. Yes
hello-cat README.md Hello runme And it can even run a cell with a custom interpreter. Yes
hello-python README.md def say_hi(): Yes
run-shellscript shellscript.md echo "Runs as shell script" This is a basic snippet with shell command. Yes
hello-js* README.md console.log("Hello, runme, from javascript!") It can even run scripting languages. Yes
hello-cat* README.md Hello runme And it can even run a cell with a custom interpreter. Yes
hello-python* README.md def say_hi(): Yes
run-shellscript* shellscript.md echo "Runs as shell script" This is a basic snippet with shell command. Yes
-- golden-list-allow-unnamed.txt --
NAME FILE FIRST COMMAND DESCRIPTION NAMED
echo-hello README.md echo "Hello, runme!" This is a basic snippet with shell command. No
echo-hello-2 README.md echo "Hello, runme!" You can omit the language, and runme will assume you are in shell. No
echo-inferred README.md echo Inferred Names will automatically be inferred from a script's contents. No
echo-hello* README.md echo "Hello, runme!" This is a basic snippet with shell command. No
echo-hello-2* README.md echo "Hello, runme!" You can omit the language, and runme will assume you are in shell. No
echo-inferred* README.md echo Inferred Names will automatically be inferred from a script's contents. No
echo README.md echo "Hello, runme!" With {"name":"hello"} you can annotate it and give it a nice name. Yes
echo-1 README.md echo "1" It can contain multiple lines too. No
echo-hello-3 README.md echo "Hello, runme! Again!" Also, the dollar sign is not needed. No
hello-js README.md console.log("Hello, runme, from javascript!") It can even run scripting languages. Yes
hello-cat README.md Hello runme And it can even run a cell with a custom interpreter. Yes
tempdir README.md temp_dir=$(mktemp -d -t "runme-XXXXXXX") It works with cd, pushd, and similar because all lines are executed as a single script. No
package-main README.md package main It can also execute a snippet of Go code. No
hello-python README.md def say_hi(): Yes
run-shellscript shellscript.md echo "Runs as shell script" This is a basic snippet with shell command. Yes
echo-1* README.md echo "1" It can contain multiple lines too. No
echo-hello-3* README.md echo "Hello, runme! Again!" Also, the dollar sign is not needed. No
hello-js* README.md console.log("Hello, runme, from javascript!") It can even run scripting languages. Yes
hello-cat* README.md Hello runme And it can even run a cell with a custom interpreter. Yes
tempdir* README.md temp_dir=$(mktemp -d -t "runme-XXXXXXX") It works with cd, pushd, and similar because all lines are executed as a single script. No
package-main* README.md package main It can also execute a snippet of Go code. No
hello-python* README.md def say_hi(): Yes
run-shellscript* shellscript.md echo "Runs as shell script" This is a basic snippet with shell command. Yes
-- golden-list-json.txt --
[
{
"name": "echo",
"file": "README.md",
"first_command": "echo \"Hello, runme!\"",
"description": "With {\"name\":\"hello\"} you can annotate it and give it a nice name.",
"named": true
"named": true,
"run_all": false
},
{
"name": "hello-js",
"file": "README.md",
"first_command": "console.log(\"Hello, runme, from javascript!\")",
"description": "It can even run scripting languages.",
"named": true
"named": true,
"run_all": true
},
{
"name": "hello-cat",
"file": "README.md",
"first_command": "Hello runme",
"description": "And it can even run a cell with a custom interpreter.",
"named": true
"named": true,
"run_all": true
},
{
"name": "hello-python",
"file": "README.md",
"first_command": "def say_hi():",
"description": "",
"named": true
"named": true,
"run_all": true
},
{
"name": "run-shellscript",
"file": "shellscript.md",
"first_command": "echo \"Runs as shell script\"",
"description": "This is a basic snippet with shell command.",
"named": true
"named": true,
"run_all": true
}
]

0 comments on commit 2f6f670

Please sign in to comment.