Skip to content

Commit 288f1a5

Browse files
committed
add: mdtkconfig nest_max_depth, bugfix: stdin does not work
1 parent bea0f78 commit 288f1a5

File tree

15 files changed

+78
-25
lines changed

15 files changed

+78
-25
lines changed

Taskfile.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,22 @@ git tag
3232
git push origin $t
3333
~~~
3434

35+
~~~bash task:git:rm-git-tag -- remove git tag & push to GitHub
36+
#args> t:tag
37+
git tag --delete $t
38+
git push origin :$t
39+
~~~
40+
3541
## Compress to .tar.gz and Decompress
3642

3743
~~~bash task:tar.gz:compress -- Compress binary files
3844
cd sources
3945
source ./mdtk/version.txt
40-
tar -zcvf ../mdtk_bin_v${VERSION}.tar.gz ./mdtk_bin
46+
tar -zcvf ../mdtk_bin_v${VERSION}_amd64.tar.gz ./mdtk_bin/linux_amd64
47+
tar -zcvf ../mdtk_bin_v${VERSION}_arm64.tar.gz ./mdtk_bin/linux_arm64
4148
~~~
4249
~~~bash task:tar.gz:decompress -- Decompress binary files
43-
echo 'run command: tar -zxvf ./mdtk_bin_VERSION.tar.gz'
50+
echo 'run command: tar -zxvf ./mdtk_bin_VERSION_ARCH.tar.gz'
4451
~~~
4552

4653
## Install Guide

memo/TODO.md renamed to memo_ja/TODO.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,18 @@
6464
- v0.5.1以降
6565
- [x] execの出力がストリーム出力に対応していなかったので修正
6666
- 全部終わってから書き出していた
67-
67+
- v0.5.2以降
68+
- [ ] 属性(`attribute`)をつけれるようにする
69+
- `~~~sh task::t -- description`
70+
- `description = [attribute] xxxxxxx`
71+
- descriptionの一部として扱う
72+
- descriptionの最初に記述する
73+
- 当然無くてもいい
74+
- タスクヘルプの解析時に属性があるかを解析する
75+
- `hidden`属性をつけていたら公開タスクでもタスクヘルプで見えないようにする
76+
- group名を非公開に変えてしまうと他のタスクからアクセスできなくなる可能性があるため
77+
- ただの非公開扱いなので`-a`をつけたら見える
78+
- [x] mdtkconfigにnestsizeを指定する項目を増やす
79+
- [x] tar.gzの作成をamd64とarm64で別にする
80+
- [x] 標準入力を受け付けなかったバグを修正
81+
- v0.5.3以降
File renamed without changes.

sources/.mdtkconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# shell to be used
2-
shell: bash
2+
shell: /bin/bash
33
script_head_set: set -euo pipefail
44

55
# List of languages that can be written at beginning of fenced code block
66
acceptable_langs: sh shell bash zsh
77

8+
nest_max_depth: 30
9+
810
# Settings of pager
911
pager: less -R
1012
pager_min_limit: 30

sources/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ install: ## mdtk install (test)
1212
cd mdtk && CGO_ENABLED=0 go install -ldflags '-s -w' -trimpath mdtk.go
1313
test:
1414
@cd mdtk && go test ./...
15+
1516

1617

1718
cross-compile: ## cross compile

sources/Taskfile.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ embed: 1
66

77
## Base Test
88

9-
```bash task::hello_world
9+
```bash task::hello_world -- aaa
1010
#desc> hello world
1111
#desc> test sample
1212
THIS=mdtk
1313
echo "Hello $THIS World!"
14+
read num
15+
echo $num
16+
echo ion
1417
```
1518

1619
```bash task::test -- mdtk first test 日本語のテキストサンプルです

sources/mdtk/config/default_config.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ script_head_set: set -euo pipefail
55
# List of languages that can be written at beginning of fenced code block
66
acceptable_langs: sh shell bash zsh
77

8+
# Maximum depth at which tasks can be deployed with embedded comment
9+
nest_max_depth: 20
10+
811
# Settings of pager
912
pager: less -R
1013
pager_min_limit: 30

sources/mdtk/config/readwrite.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type cfg struct {
2121
Shell string
2222
ScriptHeadSet string
2323
LangAlias []string
24+
NestMaxDepth uint
2425
Pager []string
2526
PagerMinLimit uint
2627
}
@@ -86,6 +87,12 @@ func setConfig(data []string) error {
8687
} else {
8788
Config.LangAlias = s
8889
}
90+
case "nest_max_depth":
91+
if vv, err := strconv.ParseUint(strings.TrimSpace(v), 10, 64); err != nil {
92+
return err
93+
} else {
94+
Config.NestMaxDepth = uint(vv)
95+
}
8996
case "pager":
9097
if s, err := parse.LexArgString(v); err != nil {
9198
return err

sources/mdtk/exec/exec.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,19 @@ func GetShHead() string {
1515
return config.Config.ScriptHeadSet
1616
}
1717

18-
func ToExecCode(code string, eos string) string {
19-
return "cat - << '" + eos + "' | " + GetShell() + "\n" + GetShHead() + "\n" + code + "\n" + eos
20-
}
21-
2218
func Run(code string, quiet_mode bool) {
23-
execcode := ToExecCode(code, "EOS")
24-
// fmt.Println(execcode)
19+
cmd := exec.Command(GetShell(), "-c", GetShHead() + "\n" + code)
2520

26-
cmd := exec.Command(GetShell(), "-c", execcode)
2721
if !quiet_mode {
2822
cmd.Stdout = os.Stdout
2923
}
24+
cmd.Stdin = os.Stdin
3025
cmd.Stderr = os.Stderr
3126

32-
err := cmd.Run()
33-
34-
if err != nil {
27+
if err := cmd.Run(); err != nil {
3528
errtext := "mdtk: Command exec error."
3629
fmt.Println(errtext, "Error command was run in", os.Args)
3730
os.Exit(1)
3831
}
39-
40-
// 実行したコマンドの結果を出力
41-
// fmt.Print(string(out))
4232
}
4333

sources/mdtk/mdtk.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ import (
1414
"mdtk/cache"
1515
"mdtk/config"
1616
"os"
17+
"strconv"
1718
_ "embed"
1819
)
1920

2021
func GetFlag () parse.Flag {
22+
nestsizestr := strconv.FormatUint(uint64(config.Config.NestMaxDepth), 10)
23+
2124
flags := parse.Flag{}
2225
flags.Set("--file", []string{"-f"}).SetHasValue("").SetDescription("Select a task file.")
23-
flags.Set("--nest", []string{"-n"}).SetHasValue("20").SetDescription("Set the nest maximum times of embedded comment (embed/task).\nDefault is 20.")
26+
flags.Set("--nest", []string{"-n"}).SetHasValue(nestsizestr).SetDescription("Set the nest maximum depth of embedded comment (embed/task).\nDefault is " + nestsizestr + ".")
2427
flags.Set("--quiet", []string{"-q"}).SetDescription("Task output is not sent to standard output.")
2528
flags.Set("--all-task", []string{"-a"}).SetDescription("Can select private groups at the command.\nOr show all tasks that include private groups at task help.")
2629
flags.Set("--script", []string{"-s"}).SetDescription("Display run-script.\n(= shebang + '" + exec.GetShHead() + "' + expanded-script)\nIf --debug option is not set, do not run.")
@@ -55,9 +58,20 @@ func main() {
5558
task_args := args.ToArgs(task_args_strarr...)
5659

5760
if fd := flags.GetData("--file"); fd.Exist {
58-
config.ReadConfig(string(path.Path(fd.Value).Dir()))
61+
if err := config.ReadConfig(string(path.Path(fd.Value).Dir())); err != nil {
62+
fmt.Print(err)
63+
os.Exit(1)
64+
}
5965
} else {
60-
config.ReadConfig("")
66+
if err := config.ReadConfig(""); err != nil {
67+
fmt.Print(err)
68+
os.Exit(1)
69+
}
70+
}
71+
72+
nestsize := config.Config.NestMaxDepth
73+
if fd := flags.GetData("--nest"); fd.Exist {
74+
nestsize = uint(fd.ValueUint())
6175
}
6276

6377
// show command/md help
@@ -88,7 +102,7 @@ func main() {
88102

89103
// make lib
90104
if fd := flags.GetData("--make-library"); fd.Exist {
91-
cache.WriteLib(tds, filename.Dir(), fd.Value, int(flags.GetData("--nest").ValueUint()))
105+
cache.WriteLib(tds, filename.Dir(), fd.Value, int(nestsize))
92106
return
93107
}
94108

@@ -110,7 +124,7 @@ func main() {
110124
os.Exit(1)
111125
}
112126

113-
code := tds.GetTaskStart(gtname, task_args, int(flags.GetData("--nest").ValueUint()))
127+
code := tds.GetTaskStart(gtname, task_args, int(nestsize))
114128

115129
if checkOptionsAndWriteScriptToStdout(code, flags) {
116130
return

0 commit comments

Comments
 (0)