Skip to content

Commit cb105a4

Browse files
committed
many fixes
1 parent ffdd4df commit cb105a4

File tree

20 files changed

+375
-111
lines changed

20 files changed

+375
-111
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,27 @@ Download the appropriate binary for your environment and move it to $PATH direct
2121
- Can write without group. In this case, all groups will be searched.
2222
- Special group-task names are as follows.
2323
- '_' group : Searchs only empty-name group.
24-
- 'help' : Show task help.
24+
- 'help' task : Show task help. If write group, show only written group's tasks.
2525
- empty : If 'default' task is defined, run it. Otherwise, run 'help'.
2626
- args -> arg_name=arg_value
2727
- Write after 2 hyphens.
28+
- {$} is a special variable for --script option, replaced by positional parameter $1...$9.
2829

2930
### * options
3031
--file, -f [+value] Specify a task file.
3132
--nest, -n [+value] Set the nest maximum times of embedded comment (embed/task).
3233
Default is 20.
34+
--quiet, -q Task output is not sent to standard output.
3335
--make-cache, -c Make taskdata cache.
34-
--debug Show run-script.
36+
--script, -s Display run-script.
37+
(= shebang + 'set -euo pipefail' + expanded-script)
38+
If --debug option is not present, do not run.
39+
--debug, -d Display expanded-script and run.
40+
If --script option is present, display run-script.
3541
--version, -v Show version.
3642
--help, -h Show command help.
3743
--manual, -m Show mdtk manual.
38-
--task-help-all Show all tasks that include private groups at task help.
44+
--task-help-all, -a Show all tasks that include private groups at task help.
3945

4046

4147

@@ -85,6 +91,9 @@ In the command, as follows, write the variables and its values after '--'.
8591
mdtk does not check for the existence of variables during script generation.
8692
It leaves this to the SHELL environment at runtime.
8793

94+
{$} is a special variable for --script option, replaced by positional parameter $1...$9.
95+
It cannot be used in normal task run.
96+
8897

8998
### * Embedded Comments
9099
Some comments written as '#xxxx> comment' have a special behavior.

memo/TODO.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,16 @@
1313
- [x] PAGER表示の拡張
1414
- cmd helpとtask helpも
1515
- 改行数をカウントして、長くなったらPAGER表示に自動的に切り替わるようにする
16-
16+
- v0.2.0以降
17+
- [x] scriptの書き出し用にdebugとは別に生成されたスクリプトを標準出力に出すだけのオプションを用意する
18+
- 実行はされない
19+
- [x] 変数に`{$}`を入れると位置パラメータ(positional parameter) `$1 ~ $9`が順番に入るようにする
20+
- [ ] pager表示を調整する
21+
- pager表示しなくてもいいようにする
22+
- PAGER環境変数がなければ何もしないようにするべき?
23+
- 起動行数指定もいるため、コンフィグファイルで変えられるようにするべき
24+
- [x] 指定グループのタスクヘルプだけ見れるようにする
25+
- [x] shorthandオプションをまとめて書けるように変更
26+
- `-abc`
27+
- [x] stdoutに出力しないquietモードを用意する
28+

sources/Taskfile.md.cache

0 Bytes
Binary file not shown.

sources/mdtk/code/code_embed_args.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package code
22

33
import (
4+
"fmt"
45
"strings"
6+
"strconv"
57
"mdtk/args"
68
)
79

@@ -20,12 +22,23 @@ func (code Code) ApplyArgs(args args.Args, enclose_with_quotes bool) (Code, erro
2022
q = "'"
2123
}
2224

25+
count := 1
26+
2327
for _, arg := range args {
2428
name, value, err := arg.GetData()
2529
if err != nil {
2630
return "", err
2731
}
28-
argstr += name + "=" + escapeQuoteAndEnclose(value, q) + "; "
32+
if enclose_with_quotes && value == "{$}" {
33+
if count > 9 {
34+
return "", fmt.Errorf("you set too many special variable {$} ( > 9).")
35+
}
36+
argstr += name + "=$" + strconv.Itoa(count) + "; "
37+
count++
38+
} else {
39+
argstr += name + "=" + escapeQuoteAndEnclose(value, q) + "; "
40+
}
41+
2942
}
3043

3144
return Code(argstr + "\n" + string(code)), nil

sources/mdtk/exec/exec.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,29 @@ func getShell() string {
2626
return sh
2727
}
2828

29+
func GetShHead() string {
30+
return "set -euo pipefail"
31+
}
32+
2933
func ToExecCode(code string, eos string) string {
30-
shhead := "set -euo pipefail\n"
31-
return "cat - << '" + eos + "' | " + shname + "\n" + shhead + code + "\n" + eos
34+
return "cat - << '" + eos + "' | " + shname + "\n" + GetShHead() + "\n" + code + "\n" + eos
3235
}
3336

34-
func Run(code string) {
37+
func Run(code string, quiet_mode bool) {
3538
execcode := ToExecCode(code, "EOS")
3639
// fmt.Println(execcode)
3740

3841
out, err := exec.Command(Shname(), "-c", execcode).CombinedOutput()
39-
if err != nil {
42+
if quiet_mode {
43+
out = nil
44+
}
45+
if err != nil {
4046
PrintExecError(out)
4147
os.Exit(1)
4248
}
4349

4450
// 実行したコマンドの結果を出力
45-
fmt.Printf("%s", string(out))
51+
fmt.Print(string(out))
4652
}
4753

4854
func PrintExecError(out []byte) {

sources/mdtk/help/cmd_help.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ mdtk is a markdown task-runner using codeblock.
1010
Can write without group.
1111
In this case, all groups will be searched.
1212
Special group-task names are as follows.
13-
- '_' group : Searchs only empty-name group.
14-
- 'help' : Show task help.
15-
- empty : If 'default' task is defined, run it.
16-
Otherwise, run 'help'.
13+
- '_' group : Searchs only empty-name group.
14+
- 'help' task : Show task help.
15+
If write group, show only written group's tasks.
16+
- empty : If 'default' task is defined, run it.
17+
Otherwise, run 'help'.
1718
args -> arg_name=arg_value
1819
Write after 2 hyphens.
20+
{$} is a special variable for --script option,
21+
replaced by positional parameter $1...$9.

sources/mdtk/help/command_help.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
//go:embed cmd_help.txt
1010
var cmdhelp string
1111

12-
func ShowCommandHelp(f parse.Flag, descline int) {
12+
func ShowCommandHelp(f parse.Flag, descline uint, pager_min_row uint) {
1313
s := fmt.Sprintln(cmdhelp)
1414

1515
s += fmt.Sprintln(" options")
1616
s += fmt.Sprintf("%s\n", f.GetHelpStr(4, descline))
1717

18-
PagerOutput(s, 40)
18+
PagerOutput(s, pager_min_row)
1919
}
2020

2121

sources/mdtk/help/help.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import (
99
)
1010

1111
func ShouldShowHelp(gtname grtask.GroupTask, tds taskset.TaskDataSet) bool {
12-
return string(gtname) == "help" || (string(gtname) == "default" && doNotExistExplicitDefaultTask(tds))
12+
_, t, _ := gtname.Split()
13+
return string(t) == "help" || (string(gtname) == "default" && doNotExistExplicitDefaultTask(tds))
1314
}
1415

15-
func ShowHelp(filename path.Path, tds taskset.TaskDataSet, show_private bool) {
16+
func ShowHelp(filename path.Path, gtname grtask.GroupTask, tds taskset.TaskDataSet, show_private bool, pager_min_row uint) {
17+
g, _, _ := gtname.Split()
18+
1619
tds = getEmbedArgsTexts(tds)
1720
tds = getTaskNameMaxLength(tds)
1821

@@ -54,6 +57,10 @@ func ShowHelp(filename path.Path, tds taskset.TaskDataSet, show_private bool) {
5457
s := fmt.Sprintf(bgray + "[%s help]" + clear + "\n", filename)
5558

5659
for _, k := range group_arr {
60+
if g != "" && string(g) != k {
61+
continue
62+
}
63+
5764
if k == "_" {
5865
for _, t := range group_map["_"] {
5966
if counts[k + ":" + string(t.Task)] > 1 {
@@ -93,5 +100,5 @@ func ShowHelp(filename path.Path, tds taskset.TaskDataSet, show_private bool) {
93100
}
94101
}
95102

96-
PagerOutput(s, 40)
103+
PagerOutput(s, pager_min_row)
97104
}

sources/mdtk/help/mdtk_manual.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
//go:embed mdtk_manual.txt
88
var mdtkman string
99

10-
func ShowManual() {
10+
func ShowManual(pager_min_row uint) {
1111
// fmt.Println(mdhelp)
12-
PagerOutput(mdtkman, 40)
12+
PagerOutput(mdtkman, pager_min_row)
1313
}

sources/mdtk/help/mdtk_manual.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ In the command, as follows, write the variables and its values after '--'.
3232
mdtk does not check for the existence of variables during script generation.
3333
It leaves this to the SHELL environment at runtime.
3434

35+
{$} is a special variable for --script option, replaced by positional parameter $1...$9.
36+
It cannot be used in normal task run.
37+
3538

3639
* Embedded Comments
3740
Some comments written as '#xxxx> comment' have a special behavior.

0 commit comments

Comments
 (0)