Skip to content

Commit 7c9b559

Browse files
committed
many fixes
1 parent cb105a4 commit 7c9b559

26 files changed

+440
-98
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@ install-linux-amd64: ## Install mdtk to /usr/local/bin/
2020
install-linux-arm64: ## Install mdtk to /usr/local/bin/
2121
cp ./sources/mdtk_bin/linux_arm64/mdtk /usr/local/bin/mdtk
2222

23+
size:
24+
@cd ./sources/mdtk_bin/linux_amd64 && ls -lh
25+
2326
help: ## Display this help screen.
2427
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk -F ':.*?## ' '{printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

README.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,27 @@ Download the appropriate binary for your environment and move it to $PATH direct
2828
- {$} is a special variable for --script option, replaced by positional parameter $1...$9.
2929

3030
### * options
31-
--file, -f [+value] Specify a task file.
31+
--file, -f [+value] Select a task file.
3232
--nest, -n [+value] Set the nest maximum times of embedded comment (embed/task).
3333
Default is 20.
3434
--quiet, -q Task output is not sent to standard output.
35-
--make-cache, -c Make taskdata cache.
35+
--all-task, -a Can select private groups at the command.
36+
Or show all tasks that include private groups at task help.
3637
--script, -s Display run-script.
3738
(= shebang + 'set -euo pipefail' + expanded-script)
38-
If --debug option is not present, do not run.
39+
If --debug option is not set, do not run.
3940
--debug, -d Display expanded-script and run.
40-
If --script option is present, display run-script.
41+
If --script option is set, display run-script.
42+
--make-cache, -c Make taskdata cache.
43+
--lib, -l [+value] Select a library file.
44+
This is a special version of --file option.
45+
No need to add an extension '.mdtklib'.
46+
--make-library [+value] Make taskdata library.
47+
Value is library name.
4148
--version, -v Show version.
4249
--help, -h Show command help.
4350
--manual, -m Show mdtk manual.
44-
--task-help-all, -a Show all tasks that include private groups at task help.
51+
--write-configbase Write config base file to current directory.
4552

4653

4754

@@ -99,8 +106,8 @@ It cannot be used in normal task run.
99106
Some comments written as '#xxxx> comment' have a special behavior.
100107

101108
~~~
102-
#embed> <group>:<task> : The specified task is directly embedded.
103-
#task> <group>:<task> -- args : The specified task is embedded as a subshell.
109+
#embed> <group>:<task> : The selected task is directly embedded.
110+
#task> <group>:<task> -- args : The selected task is embedded as a subshell.
104111
#task> @ <group>:<task> -- args : The config once flag is temporarily reset.
105112
The rest is the same as without @.
106113
#config> once : When called multiple times, it is called only the first time.
@@ -109,16 +116,16 @@ Some comments written as '#xxxx> comment' have a special behavior.
109116

110117

111118
### * Filename
112-
mdtk uses Taskfile.md in the current directory unless you specify a file path with --file/-f flag.
119+
mdtk uses Taskfile.md in the current directory unless you select a file path with --file/-f flag.
113120
Instead of Taskfile.md, you can use *.taskrun.md.
114121
In this case, however, only one *.taskrun.md file should be placed in the same directory.
115122

116123
Search Order: --file path -> Taskfile.md -> *.taskrun.md
117124

118125

119126
### * Sub Taskfile
120-
You can load sub taskfile in the following code block.
121-
There must be no duplicate group/task combinations throughout all loaded files.
127+
You can read sub taskfile in the following code block.
128+
There must be no duplicate group/task combinations throughout all read files.
122129

123130
~~~markdown
124131
```taskfile
@@ -130,10 +137,22 @@ There must be no duplicate group/task combinations throughout all loaded files.
130137

131138

132139
### * Task Cache
133-
You can make a taskdata cache by specifying --make-cache option.
140+
You can make a taskdata cache by setting --make-cache option.
134141
The cache 'may' speed up task reading.
135142
If the cache already exists, it will be read automatically with no option.
136-
However, note that if taskfiles have some updates at this time, the cache will be remake,
137-
which is slower than if there was no cache.
143+
However, note that if taskfiles have some updates at this time, the cache will be remade
144+
and run-speed is slower than it without cache.
138145
Good to use for taskfiles that are being updated less frequently.
139146
To disable the cache, simply delete the relevant cache.
147+
148+
You can also make a taskdata library. It is similar to cache and use --make-library option.
149+
Differences of the library and the cache are as follows.
150+
- The library is not read automatically and not remade automataically.
151+
- Select library file directly using --file/-f or --lib/-l option.
152+
- Therefore, can use it alone. Not need to hold '.md' taskfiles at the same place.
153+
- Embedded comments of all public tasks will be expanded.
154+
- All private tasks will be removed.
155+
- All file-path data of tasks will be removed.
156+
157+
In 'taskfile' code block, you cannot read the cache/library.
158+
Please use mdtk command in task when you use them at outside.

memo/TODO.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
- v0.1.0以降
55
- [x] version表示オプション追加 (--version, -v)
66
- version情報は外部ファイルに`VERSION=xx.yy.zz`の形で記載してgo:embedで読み込む
7-
- [ ] group名の衝突を回避する手段を実装する
8-
- taskfile読み込み時にaliasを付けられると言い?
9-
- そもそもmdtk in mdtkで読み込めば別データ扱いで管理できるのでいらないかもしれない
107
- [x] scriptを全部読み込んでバイナリで保持しておく.cache機能
118
- [x] command helpとmarkdown helpを外部ファイルに出してgo:embedで読み込むように変更
129
- [x] helpのPAGER表示 (今のところ長くなっているmarkdown helpのみ)
@@ -17,12 +14,26 @@
1714
- [x] scriptの書き出し用にdebugとは別に生成されたスクリプトを標準出力に出すだけのオプションを用意する
1815
- 実行はされない
1916
- [x] 変数に`{$}`を入れると位置パラメータ(positional parameter) `$1 ~ $9`が順番に入るようにする
20-
- [ ] pager表示を調整する
21-
- pager表示しなくてもいいようにする
22-
- PAGER環境変数がなければ何もしないようにするべき?
23-
- 起動行数指定もいるため、コンフィグファイルで変えられるようにするべき
2417
- [x] 指定グループのタスクヘルプだけ見れるようにする
2518
- [x] shorthandオプションをまとめて書けるように変更
2619
- `-abc`
2720
- [x] stdoutに出力しないquietモードを用意する
28-
21+
- v0.3.0以降
22+
- [ ] group名の衝突を回避する手段を実装する
23+
- taskfile読み込み時にaliasを付けられると言い?
24+
- そもそもmdtk in mdtkで読み込めば別データ扱いで管理できるのでいらないかもしれない
25+
- [x] pager表示を調整する
26+
- pager表示しなくてもいいようにする
27+
- PAGER環境変数がなければ何もしないようにするべき?
28+
- 起動行数指定もいるため、コンフィグファイルで変えられるようにするべき
29+
- [ ] change color
30+
- config?
31+
- [x] configファイルの読み込み、デフォルトコンフィグの書き出し
32+
- [x] mdtklibファイルの読み込みと書き出し機能
33+
- cacheと同じように構造体で保持するが、publicタスクを全て展開し、privateタスクは消去する
34+
- cacheとは異なり.mdtklibファイルを`--file`オプションで直接指定する。読み込めなければ失敗する
35+
- mdtk in mdtkで使用することを想定
36+
- FilePathデータは削除されている
37+
- cacheと異なり自動更新はされない
38+
- 読み込み時のコストを考えるとコンパクトなmdtklibを複数作成した方がいい
39+
- [x] コマンドオプションの調整

sources/mdtk/cache/cache.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package cache
2+
3+
import (
4+
"os"
5+
"mdtk/path"
6+
"mdtk/taskset"
7+
)
8+
9+
func toCacheName(filename path.Path) string {
10+
return string(filename) + ".cache"
11+
}
12+
13+
func ExistCacheFile(filename path.Path) bool {
14+
_, err := os.Stat(toCacheName(filename))
15+
return err == nil
16+
}
17+
18+
func IsLatestCache(tds taskset.TaskDataSet, filename path.Path) bool {
19+
status, err := os.Stat(toCacheName(filename))
20+
if err != nil {
21+
return false
22+
}
23+
24+
for k, _ := range tds.FilePath {
25+
substatus, err := os.Stat(string(k))
26+
if err != nil || status.ModTime().Before(substatus.ModTime()) {
27+
return false
28+
}
29+
}
30+
31+
return true
32+
}
33+
34+
func WriteCache(tds taskset.TaskDataSet, filename path.Path) error {
35+
return writeBase(tds, toCacheName(filename))
36+
}
37+
38+
func ReadCache(filename path.Path) (taskset.TaskDataSet, error) {
39+
return readBase(toCacheName(filename))
40+
}

sources/mdtk/cache/mdtklib.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package cache
2+
3+
import (
4+
"mdtk/grtask"
5+
"mdtk/taskset"
6+
"mdtk/args"
7+
"mdtk/path"
8+
"path/filepath"
9+
)
10+
11+
func expandPublicGroupTask(tds taskset.TaskDataSet, nestsize int) taskset.TaskDataSet {
12+
13+
for i, data := range tds.Data {
14+
if data.Group.IsPrivate() {
15+
continue
16+
}
17+
code := tds.GetTaskStart(grtask.Create(data.Group, data.Task), args.Args{}, nestsize)
18+
tds.Data[i].Code = code
19+
}
20+
21+
return tds
22+
}
23+
24+
func removePrivateGroupTask(tds taskset.TaskDataSet) taskset.TaskDataSet {
25+
d := []taskset.TaskData{}
26+
for _, data := range tds.Data {
27+
if !data.Group.IsPrivate() {
28+
d = append(d, data)
29+
}
30+
}
31+
tds.Data = d
32+
return tds
33+
}
34+
35+
func cleanFilePath(tds taskset.TaskDataSet, s string) taskset.TaskDataSet {
36+
tds.FilePath = map[path.Path]bool{path.Path(s): true}
37+
for i, _ := range tds.Data {
38+
tds.Data[i].FilePath = path.Path(s)
39+
}
40+
return tds
41+
}
42+
43+
44+
func WriteLib(tds taskset.TaskDataSet, dir path.Path, output_namebase string, nestsize int) error {
45+
tdsb := expandPublicGroupTask(tds, nestsize)
46+
tdsb = removePrivateGroupTask(tdsb)
47+
tdsb = cleanFilePath(tdsb, output_namebase)
48+
return writeBase(tdsb, filepath.Join(string(dir), output_namebase + ".mdtklib"))
49+
}
50+
51+
func ReadLib(filename path.Path) (taskset.TaskDataSet, error) {
52+
return readBase(string(filename))
53+
}

sources/mdtk/cache/readwrite.go

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,11 @@ package cache
33
import (
44
"os"
55
"encoding/gob"
6-
"mdtk/path"
76
"mdtk/taskset"
87
)
98

10-
func toCacheName(filename path.Path) string {
11-
return string(filename) + ".cache"
12-
}
13-
14-
func ExistCacheFile(filename path.Path) bool {
15-
_, err := os.Stat(toCacheName(filename))
16-
return err == nil
17-
}
18-
19-
func IsLatestCache(tds taskset.TaskDataSet, filename path.Path) bool {
20-
status, err := os.Stat(toCacheName(filename))
21-
if err != nil {
22-
return false
23-
}
24-
25-
for k, _ := range tds.FilePath {
26-
substatus, err := os.Stat(string(k))
27-
if err != nil || status.ModTime().Before(substatus.ModTime()) {
28-
return false
29-
}
30-
}
31-
32-
return true
33-
}
34-
35-
func WriteCache(tds taskset.TaskDataSet, filename path.Path) error {
36-
file, err := os.Create(toCacheName(filename))
9+
func writeBase(tds taskset.TaskDataSet, filename string) error {
10+
file, err := os.Create(filename)
3711
defer file.Close()
3812
if err != nil {
3913
return err
@@ -43,8 +17,8 @@ func WriteCache(tds taskset.TaskDataSet, filename path.Path) error {
4317
return nil
4418
}
4519

46-
func ReadCache(filename path.Path) (taskset.TaskDataSet, error) {
47-
file, err := os.Open(toCacheName(filename))
20+
func readBase(filename string) (taskset.TaskDataSet, error) {
21+
file, err := os.Open(filename)
4822
defer file.Close()
4923
if err != nil {
5024
return taskset.TaskDataSet{}, err
@@ -59,3 +33,5 @@ func ReadCache(filename path.Path) (taskset.TaskDataSet, error) {
5933
return tds, nil
6034
}
6135

36+
37+

sources/mdtk/code/code_embed_codes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (code Code) ApplyEmbedCodes(tf TaskDataSetInterface, nestsize int) (Code, e
2121
if err != nil {
2222
return "", err
2323
}
24-
// subcode = subcode.RemoveEmbedArgsComment()
24+
subcode = subcode.RemoveEmbedArgsComment()
2525
res = strings.Replace(res, embed[0], string(subcode), 1)
2626
}
2727

sources/mdtk/code/code_embed_tasks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (code Code) ApplySubTasks(tf TaskDataSetInterface, nestsize int) (Code, err
5555
if err2 != nil {
5656
return "", err2
5757
}
58-
// subcode = subcode.RemoveEmbedArgsComment()
58+
subcode = subcode.RemoveEmbedArgsComment()
5959
rsubcode := indent + strings.Replace(string(subcode), "\n", "\n" + indent, -1)
6060
execsubcode := "\n# subtask: " + string(grtaskname) + "\n(\n" + rsubcode + "\n) # end: " + string(grtaskname) + "\n"
6161
res = strings.Replace(res, task[0], execsubcode, 1)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pager=less -R
2+
pager_min_limit=30

0 commit comments

Comments
 (0)