/
help_ext_cmd.go
72 lines (56 loc) · 1.54 KB
/
help_ext_cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package command
import (
"fmt"
"github.com/bitwormhole/starter-cli/cli"
"github.com/bitwormhole/starter/application"
"github.com/bitwormhole/starter/markup"
)
// HelpAboutCommand 。。。
type HelpAboutCommand struct {
markup.Component `class:"cli-handler"`
Context application.Context `inject:"context"`
}
func (inst *HelpAboutCommand) _Impl() cli.Handler {
return inst
}
func (inst *HelpAboutCommand) Init(service cli.Service) error {
service.RegisterHandler(HelpAbout, inst)
service.RegisterHandler(HelpContent, inst)
service.RegisterHandler(HelpVersion, inst)
return nil
}
func (inst *HelpAboutCommand) Handle(ctx *cli.TaskContext) error {
cmd := ctx.CurrentTask.CommandName
switch cmd {
case HelpAbout:
inst.doHelpAbout(ctx)
break
case HelpContent:
inst.doHelpContent(ctx)
break
case HelpVersion:
inst.doHelpVersion(ctx)
break
default:
inst.doHelpAbout(ctx)
break
}
return nil
}
func (inst *HelpAboutCommand) doHelpAbout(ctx *cli.TaskContext) error {
return nil
}
func (inst *HelpAboutCommand) doHelpContent(ctx *cli.TaskContext) error {
return nil
}
func (inst *HelpAboutCommand) doHelpVersion(ctx *cli.TaskContext) error {
const prefix = "module.main."
props := inst.Context.GetProperties()
console := ctx.Console
title := props.GetProperty("application.title", "-")
name := props.GetProperty(prefix+"name", "-")
ver := props.GetProperty(prefix+"version", "-")
rev := props.GetProperty(prefix+"revision", "-")
console.WriteString(fmt.Sprintln(title, " (", name, "@", ver, ", r", rev, ")"))
return nil
}