diff --git a/base/cli/system.go b/base/cli/system.go index 01782898..2e50f8f4 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -67,26 +67,6 @@ func _system_out(m *ice.Message, out string) io.Writer { } return nil } -func _system_find(m *ice.Message, bin string, dir ...string) string { - if strings.Contains(bin, ice.DF) { - return bin - } - if strings.HasPrefix(bin, ice.PS) { - return bin - } - if strings.HasPrefix(bin, nfs.PWD) { - return bin - } - if len(dir) == 0 { - dir = append(dir, strings.Split(kit.Env(PATH), ice.DF)...) - } - for _, p := range dir { - if nfs.ExistsFile(m, path.Join(p, bin)) { - return kit.Path(p, bin) - } - } - return "" -} func _system_exec(m *ice.Message, cmd *exec.Cmd) { if r, ok := m.Optionv(CMD_INPUT).(io.Reader); ok { cmd.Stdin = r // 输入流 @@ -115,6 +95,26 @@ func _system_exec(m *ice.Message, cmd *exec.Cmd) { } m.Push(mdb.TIME, m.Time()).Push(CODE, int(cmd.ProcessState.ExitCode())) } +func _system_find(m Message, bin string, dir ...string) string { + if strings.Contains(bin, ice.DF) { + return bin + } + if strings.HasPrefix(bin, ice.PS) { + return bin + } + if strings.HasPrefix(bin, nfs.PWD) { + return bin + } + if len(dir) == 0 { + dir = append(dir, strings.Split(kit.Env(PATH), ice.DF)...) + } + for _, p := range dir { + if nfs.ExistsFile(m, path.Join(p, bin)) { + return kit.Path(p, bin) + } + } + return "" +} const ( CMD_DIR = "cmd_dir" @@ -156,10 +156,15 @@ func init() { }) } -func IsSuccess(m *ice.Message) bool { +type Message interface { + Append(key string, arg ...ice.Any) string + Optionv(key string, arg ...ice.Any) ice.Any +} + +func IsSuccess(m Message) bool { return m.Append(CODE) == "0" || m.Append(CODE) == "" } -func SystemFind(m *ice.Message, bin string, dir ...string) string { +func SystemFind(m Message, bin string, dir ...string) string { if text := kit.ReadFile(ice.ETC_PATH); len(text) > 0 { dir = append(dir, strings.Split(text, ice.NL)...) } diff --git a/base/nfs/pack.go b/base/nfs/pack.go index 1cd7a7f4..c65cea46 100644 --- a/base/nfs/pack.go +++ b/base/nfs/pack.go @@ -71,7 +71,7 @@ var DiskFile = file.NewDiskFile() func init() { file.Init(OptionFiles(ice.Pulse, DiskFile, PackFile)) } -func OptionFiles(m *ice.Message, f ...file.File) file.File { +func OptionFiles(m Message, f ...file.File) file.File { if len(f) > 1 { m.Optionv(ice.MSG_FILES, file.NewMultiFile(f...)) } else if len(f) > 0 { @@ -79,10 +79,10 @@ func OptionFiles(m *ice.Message, f ...file.File) file.File { } return m.Optionv(ice.MSG_FILES).(file.File) } -func StatFile(m *ice.Message, p string) (os.FileInfo, error) { +func StatFile(m Message, p string) (os.FileInfo, error) { return OptionFiles(m).StatFile(p) } -func OpenFile(m *ice.Message, p string) (io.ReadCloser, error) { +func OpenFile(m Message, p string) (io.ReadCloser, error) { return OptionFiles(m).OpenFile(p) } func CreateFile(m *ice.Message, p string) (io.WriteCloser, string, error) { @@ -127,7 +127,11 @@ func Link(m *ice.Message, oldname string, newname string) error { return OptionFiles(m).Link(oldname, newname) } -func ExistsFile(m *ice.Message, p string) bool { +type Message interface { + Optionv(key string, arg ...ice.Any) ice.Any +} + +func ExistsFile(m Message, p string) bool { if _, e := OptionFiles(m).StatFile(p); e == nil { return true } diff --git a/core/code/inner.go b/core/code/inner.go index 0676ae6e..5976e38a 100644 --- a/core/code/inner.go +++ b/core/code/inner.go @@ -173,6 +173,9 @@ func init() { _inner_make(m, m.Cmd(cli.SYSTEM, cli.MAKE, arg)) }}, FAVOR: {Name: "favor", Help: "收藏"}, + "man": {Name: "man", Help: "手册", Hand: func(m *ice.Message, arg ...string) { + m.Result(kit.Split(arg[0])) + }}, }, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) { if arg[0] = strings.Split(arg[0], ice.FS)[0]; !strings.HasSuffix(arg[0], ice.PS) { arg[1] = kit.Slice(strings.Split(arg[0], ice.PS), -1)[0] diff --git a/core/wiki/chart.go b/core/wiki/chart.go index 03ae98dc..a6709054 100644 --- a/core/wiki/chart.go +++ b/core/wiki/chart.go @@ -151,7 +151,7 @@ func _chart_show(m *ice.Message, kind, text string, arg ...string) { m.Option(HEIGHT, chart.GetHeight()) // 渲染引擎 - _wiki_template(m, CHART, "", text) + _wiki_template(m, CHART, "", text, arg...) defer m.Echo("") chart.Draw(m, 0, 0) m.RenderResult() @@ -191,7 +191,7 @@ func init() { }, Configs: ice.Configs{ CHART: {Name: CHART, Help: "图表", Value: kit.Data( nfs.TEMPLATE, ``, )}, diff --git a/option.go b/option.go index 66ff4bfc..3786ab36 100644 --- a/option.go +++ b/option.go @@ -127,6 +127,10 @@ func (m *Message) ProcessDisplay(arg ...Any) { m.Option(MSG_DISPLAY, arg...) } +func (m *Message) ProcessStory(arg ...Any) { + m.Option(MSG_PROCESS, "_story") + m.Option(PROCESS_ARG, arg...) +} func (m *Message) ProcessField(arg ...Any) { m.Process(PROCESS_FIELD) m.Option(FIELD_PREFIX, arg...)