mirror of
https://shylinux.com/x/icebergs
synced 2025-04-25 09:08:06 +08:00
add some
This commit is contained in:
parent
77f10bbe69
commit
8d3dbc1dea
@ -29,7 +29,7 @@ func init() {
|
||||
}
|
||||
})
|
||||
m.Options(CMD_ENV, env, CMD_INPUT, os.Stdin, CMD_OUTPUT, os.Stdout, CMD_ERRPUT, os.Stderr)
|
||||
kit.If(kit.Env(CTX_LOG), func(p string) { m.Optionv(CMD_ERRPUT, p) })
|
||||
kit.If(kit.Select("/dev/null", kit.Env(CTX_LOG)), func(p string) { m.Optionv(CMD_ERRPUT, p) })
|
||||
m.Cmd(FOREVER, STOP)
|
||||
if bin := kit.Select(os.Args[0], ice.BIN_ICE_BIN, nfs.Exists(m, ice.BIN_ICE_BIN)); len(arg) > 0 && arg[0] == ice.SPACE {
|
||||
m.Cmdy(FOREVER, bin, ice.SPACE, START, ice.DEV, ice.OPS, arg[1:])
|
||||
|
@ -33,6 +33,9 @@ func _config_only(v ice.Any, arg ...string) bool {
|
||||
return false
|
||||
}
|
||||
func _config_save(m *ice.Message, name string, arg ...string) {
|
||||
if !ice.HasVar() {
|
||||
return
|
||||
}
|
||||
data, msg := ice.Map{}, m.Spawn(m.Source())
|
||||
for _, k := range arg {
|
||||
if v := mdb.Confv(msg, k); _config_only(v, mdb.META) && _config_only(kit.Value(v, mdb.META),
|
||||
@ -58,6 +61,9 @@ func _config_save(m *ice.Message, name string, arg ...string) {
|
||||
}
|
||||
}
|
||||
func _config_load(m *ice.Message, name string, arg ...string) {
|
||||
if !ice.HasVar() {
|
||||
return
|
||||
}
|
||||
if f, e := miss.OpenFile(path.Join(ice.VAR_CONF, name)); e == nil {
|
||||
defer f.Close()
|
||||
data, msg := ice.Map{}, m.Spawn(m.Source())
|
||||
|
@ -19,10 +19,12 @@ func (f *Frame) Begin(m *ice.Message, arg ...string) {
|
||||
f.s = make(chan os.Signal, 10)
|
||||
}
|
||||
func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
if f, p, e := logs.CreateFile(ice.VAR_LOG_ICE_PID); e == nil {
|
||||
m.Logs("save", "file", p, PID, os.Getpid())
|
||||
fmt.Fprint(f, os.Getpid())
|
||||
f.Close()
|
||||
if ice.HasVar() {
|
||||
if f, p, e := logs.CreateFile(ice.VAR_LOG_ICE_PID); e == nil {
|
||||
m.Logs("save", "file", p, PID, os.Getpid())
|
||||
fmt.Fprint(f, os.Getpid())
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
t := time.NewTicker(kit.Duration(mdb.Conf(m, TIMER, kit.Keym(TICK))))
|
||||
for {
|
||||
|
@ -28,6 +28,9 @@ func (f *Frame) Begin(m *ice.Message, arg ...string) {
|
||||
}
|
||||
}
|
||||
func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
if !ice.HasVar() {
|
||||
return
|
||||
}
|
||||
mdb.Confm(m, FILE, nil, func(k string, v ice.Map) {
|
||||
if mdb.Conf(m, k, kit.Keym(mdb.DISABLE)) == ice.TRUE {
|
||||
return
|
||||
|
@ -101,6 +101,9 @@ func _hash_prunes(m *ice.Message, prefix, chain string, arg ...string) {
|
||||
})
|
||||
}
|
||||
func _hash_export(m *ice.Message, prefix, chain, file string) {
|
||||
if !ice.HasUsr() {
|
||||
return
|
||||
}
|
||||
defer Lock(m, prefix)()
|
||||
if len(Confm(m, prefix, kit.Keys(chain, HASH))) == 0 {
|
||||
return
|
||||
@ -116,6 +119,9 @@ func _hash_export(m *ice.Message, prefix, chain, file string) {
|
||||
}
|
||||
}
|
||||
func _hash_import(m *ice.Message, prefix, chain, file string) {
|
||||
if !ice.HasUsr() {
|
||||
return
|
||||
}
|
||||
defer Lock(m, prefix)()
|
||||
f, e := miss.OpenFile(kit.Keys(file, JSON))
|
||||
if e != nil && !ice.Info.Important {
|
||||
|
@ -59,6 +59,9 @@ func _zone_select(m *ice.Message, prefix, chain, zone string, id string) {
|
||||
})
|
||||
}
|
||||
func _zone_export(m *ice.Message, prefix, chain, file string) {
|
||||
if !ice.HasUsr() {
|
||||
return
|
||||
}
|
||||
defer Lock(m, prefix)()
|
||||
if len(Confm(m, prefix, kit.Keys(chain, HASH))) == 0 {
|
||||
return
|
||||
@ -91,6 +94,9 @@ func _zone_export(m *ice.Message, prefix, chain, file string) {
|
||||
m.Logs(EXPORT, KEY, path.Join(prefix, chain), FILE, p, COUNT, count)
|
||||
}
|
||||
func _zone_import(m *ice.Message, prefix, chain, file string) {
|
||||
if !ice.HasUsr() {
|
||||
return
|
||||
}
|
||||
defer Lock(m, prefix)()
|
||||
f, e := miss.OpenFile(kit.Keys(file, CSV))
|
||||
if e != nil && !ice.Info.Important {
|
||||
|
@ -144,6 +144,9 @@ const (
|
||||
VAR = "var/"
|
||||
USR = "usr/"
|
||||
|
||||
SCAN = "scan"
|
||||
GOWORK = "gowork"
|
||||
|
||||
ETC_LOCAL_SH = "etc/local.sh"
|
||||
ETC_CERT_KEY = "etc/cert/cert.key"
|
||||
ETC_CERT_PEM = "etc/cert/cert.pem"
|
||||
|
@ -105,7 +105,7 @@ func (f *Frame) parse(m *ice.Message, h, line string) string {
|
||||
return ""
|
||||
}
|
||||
func (f *Frame) scan(m *ice.Message, h, line string) *Frame {
|
||||
// kit.If(f.source == STDIO, func() { m.Option(ice.LOG_DISABLE, ice.TRUE) })
|
||||
kit.If(f.source == STDIO, func() { m.Option(ice.LOG_DISABLE, ice.TRUE) })
|
||||
f.ps1 = kit.Simple(mdb.Confv(m, PROMPT, kit.Keym(PS1)))
|
||||
f.ps2 = kit.Simple(mdb.Confv(m, PROMPT, kit.Keym(PS2)))
|
||||
ps, bio := f.ps1, bufio.NewScanner(f.stdin)
|
||||
|
@ -471,15 +471,12 @@ func init() {
|
||||
VERSION: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy("web.code.version")
|
||||
}},
|
||||
"gowork": {Name: "gowork name", Help: "工作区", Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.GOWORK: {Name: "gowork name", Help: "工作区", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(cli.SYSTEM, cli.GO, "work", "init")
|
||||
m.Cmd(cli.SYSTEM, cli.GO, "work", "use", ".")
|
||||
m.Cmd(cli.SYSTEM, cli.GO, "work", "use", nfs.USR_RELEASE)
|
||||
m.Cmd(cli.SYSTEM, cli.GO, "work", "use", nfs.USR_ICEBERGS)
|
||||
m.Cmd(cli.SYSTEM, cli.GO, "work", "use", nfs.USR_TOOLKITS)
|
||||
kit.For([]string{".", nfs.USR_RELEASE, nfs.USR_ICEBERGS, nfs.USR_TOOLKITS}, func(p string) { m.Cmd(cli.SYSTEM, cli.GO, "work", "use", p) })
|
||||
DreamEach(m, m.Option(mdb.NAME), "", func(name string) { m.Cmd(cli.SYSTEM, cli.GO, "work", "use", path.Join(ice.USR_LOCAL_WORK, name)) })
|
||||
}},
|
||||
"scan": {Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.SCAN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
list := m.CmdMap(CODE_GIT_REPOS, nfs.REPOS)
|
||||
GoToastTable(m.Cmd(nfs.DIR, nfs.USR_LOCAL_WORK, mdb.NAME), mdb.NAME, func(value ice.Maps) {
|
||||
if repos, ok := list[value[mdb.NAME]]; ok {
|
||||
|
@ -35,7 +35,9 @@ func _serve_start(m *ice.Message) {
|
||||
m.Cmd(SPIDE, ice.OPS, _serve_address(m)+"/exit", ice.Maps{CLIENT_TIMEOUT: cli.TIME_30ms, ice.LOG_DISABLE: ice.TRUE})
|
||||
}).Sleep(cli.TIME_1s)
|
||||
m.Spawn(ice.Maps{TOKEN: ""}).Start("", m.OptionSimple(tcp.HOST, tcp.PORT)...)
|
||||
m.Cmd(nfs.SAVE, ice.VAR_LOG_ICE_PORT, m.Option(tcp.PORT))
|
||||
if ice.HasVar() {
|
||||
m.Cmd(nfs.SAVE, ice.VAR_LOG_ICE_PORT, m.Option(tcp.PORT))
|
||||
}
|
||||
if m.Cmd(tcp.HOST).Length() == 0 {
|
||||
return
|
||||
}
|
||||
|
3
conf.go
3
conf.go
@ -341,8 +341,9 @@ const ( // Err
|
||||
ErrNotValid = "not valid: "
|
||||
ErrNotStart = "not start: "
|
||||
|
||||
ErrNotFoundSpace = "not found space: "
|
||||
ErrNotFoundIndex = "not found index: "
|
||||
ErrNotFoundSpide = "not found spide: "
|
||||
ErrNotFoundSpace = "not found space: "
|
||||
ErrAlreadyExists = "already exists: "
|
||||
ErrNotImplement = "not implement: "
|
||||
ErrTooDeepCount = "too deep count: "
|
||||
|
10
data.go
10
data.go
@ -52,6 +52,9 @@ func (m *Message) Conf(arg ...Any) string { return kit.Format(m.Confv(arg...)) }
|
||||
var _important = task.Lock{}
|
||||
|
||||
func SaveImportant(m *Message, arg ...string) {
|
||||
if !HasVar() {
|
||||
return
|
||||
}
|
||||
if Info.Important != true || len(arg) == 0 {
|
||||
return
|
||||
}
|
||||
@ -60,12 +63,13 @@ func SaveImportant(m *Message, arg ...string) {
|
||||
m.Cmd("nfs.push", VAR_DATA_IMPORTANT, kit.Join(arg, SP), NL)
|
||||
}
|
||||
func loadImportant(m *Message) {
|
||||
if !HasVar() {
|
||||
return
|
||||
}
|
||||
if f, e := os.Open(VAR_DATA_IMPORTANT); e == nil {
|
||||
defer f.Close()
|
||||
kit.For(f, func(s string) { kit.If(s != "" && !strings.HasPrefix(s, "# "), func() { m.Cmd(kit.Split(s)) }) })
|
||||
}
|
||||
if _, e := os.Stat(VAR); e == nil {
|
||||
Info.Important = true
|
||||
}
|
||||
Info.Important = HasVar()
|
||||
}
|
||||
func removeImportant(m *Message) { os.Remove(VAR_DATA_IMPORTANT) }
|
||||
|
29
init.go
29
init.go
@ -26,7 +26,7 @@ func (s *Frame) Begin(m *Message, arg ...string) {
|
||||
func (s *Frame) Start(m *Message, arg ...string) {
|
||||
m.Cmd(INIT, arg)
|
||||
kit.For([]string{LOG, GDB, SSH}, func(k string) { m.Sleep30ms().Start(k) })
|
||||
Info.Important = true
|
||||
Info.Important = HasVar()
|
||||
m.Sleep30ms().Cmd(arg)
|
||||
}
|
||||
func (s *Frame) Close(m *Message, arg ...string) {
|
||||
@ -73,7 +73,9 @@ var Index = &Context{Name: ICE, Help: "冰山模块", Commands: Commands{
|
||||
m.GoSleep300ms(func() {
|
||||
m.root.Option(EXIT, kit.Select("0", arg, 0))
|
||||
m.Cmd(SOURCE, ETC_EXIT_SHY)
|
||||
m.Cmd(EXPORT, EXPORT)
|
||||
if HasUsr() {
|
||||
m.Cmd(EXPORT, EXPORT)
|
||||
}
|
||||
m.Cmd(CTX_EXIT)
|
||||
removeImportant(m)
|
||||
})
|
||||
@ -110,15 +112,36 @@ func Run(arg ...string) string {
|
||||
kit.If(Pulse._cmd == nil, func() { Pulse._cmd = &Command{RawHand: logs.FileLines(3)} })
|
||||
switch Index.Merge(Index).Begin(Pulse, arg...); kit.Select("", arg, 0) {
|
||||
case SERVE, SPACE:
|
||||
_forever = true
|
||||
logs.Disable(false)
|
||||
Pulse.Go(func() { Index.Start(Pulse, arg...) })
|
||||
conf.Wait()
|
||||
os.Exit(kit.Int(Pulse.Option(EXIT)))
|
||||
default:
|
||||
Pulse.Cmdy(INIT).Cmdy(arg)
|
||||
kit.If(Pulse.IsErrNotFound(), func() { Pulse.SetAppend().SetResult().Cmdy(SYSTEM, arg) })
|
||||
kit.If(strings.TrimSpace(Pulse.Result()) == "" && Pulse.Length() > 0, func() { Pulse.TableEcho() })
|
||||
kit.If(Pulse.Result() != "" && !strings.HasSuffix(Pulse.Result(), NL), func() { Pulse.Echo(NL) })
|
||||
}
|
||||
return Pulse.Result()
|
||||
}
|
||||
|
||||
var _forever bool
|
||||
|
||||
func HasVar() bool {
|
||||
if !_forever {
|
||||
return false
|
||||
}
|
||||
if _, e := os.Stat(VAR); e == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
func HasUsr() bool {
|
||||
if !_forever {
|
||||
return false
|
||||
}
|
||||
if _, e := os.Stat(USR); e == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
28
logs.go
28
logs.go
@ -133,31 +133,37 @@ func (m *Message) Warn(err Any, arg ...Any) bool {
|
||||
return true
|
||||
}
|
||||
func (m *Message) WarnNotLogin(err Any, arg ...Any) bool {
|
||||
return m.Warn(err, ErrNotLogin, kit.Simple(arg...), logs.FileLineMeta(2))
|
||||
return m.warnInfo(err, ErrNotLogin, arg...)
|
||||
}
|
||||
func (m *Message) WarnNotRight(err Any, arg ...Any) bool {
|
||||
return m.Warn(err, ErrNotRight, kit.Simple(arg...), logs.FileLineMeta(2))
|
||||
return m.warnInfo(err, ErrNotRight, arg...)
|
||||
}
|
||||
func (m *Message) WarnNotAllow(err Any, arg ...Any) bool {
|
||||
return m.Warn(err, ErrNotAllow, kit.Simple(arg...), logs.FileLineMeta(2))
|
||||
return m.warnInfo(err, ErrNotAllow, arg...)
|
||||
}
|
||||
func (m *Message) WarnNotFound(err Any, arg ...Any) bool {
|
||||
return m.Warn(err, ErrNotFound, kit.Simple(arg...), logs.FileLineMeta(2))
|
||||
}
|
||||
func (m *Message) WarnNotFoundSpace(err Any, arg ...Any) bool {
|
||||
return m.Warn(err, ErrNotFoundSpace, kit.Simple(arg...), logs.FileLineMeta(2))
|
||||
return m.warnInfo(err, ErrNotFound, arg...)
|
||||
}
|
||||
func (m *Message) WarnNotFoundIndex(err Any, arg ...Any) bool {
|
||||
return m.Warn(err, ErrNotFoundIndex, kit.Simple(arg...), logs.FileLineMeta(2))
|
||||
return m.warnInfo(err, ErrNotFoundIndex, arg...)
|
||||
}
|
||||
func (m *Message) WarnNotFoundSpide(err Any, arg ...Any) bool {
|
||||
return m.warnInfo(err, ErrNotFoundSpide, arg...)
|
||||
}
|
||||
func (m *Message) WarnNotFoundSpace(err Any, arg ...Any) bool {
|
||||
return m.warnInfo(err, ErrNotFoundSpace, arg...)
|
||||
}
|
||||
func (m *Message) WarnNotValid(err Any, arg ...Any) bool {
|
||||
return m.Warn(err, ErrNotValid, kit.Simple(arg...), logs.FileLineMeta(2))
|
||||
return m.warnInfo(err, ErrNotValid, arg...)
|
||||
}
|
||||
func (m *Message) WarnNotValidTime(time Any, arg ...Any) bool {
|
||||
return m.Warn(kit.Format(time) < m.Time(), ErrNotValid, kit.Simple(arg...), time, m.Time(), logs.FileLineMeta(2))
|
||||
return m.warnInfo(kit.Format(time) < m.Time(), ErrNotValid, append(arg, time, m.Time())...)
|
||||
}
|
||||
func (m *Message) WarnAlreadyExists(err Any, arg ...Any) bool {
|
||||
return m.Warn(err, ErrAlreadyExists, kit.Simple(arg...), logs.FileLineMeta(2))
|
||||
return m.warnInfo(err, ErrAlreadyExists, arg...)
|
||||
}
|
||||
func (m *Message) warnInfo(err Any, info string, arg ...Any) bool {
|
||||
return m.Warn(err, info, kit.Simple(arg...), logs.Meta{logs.FILELINE, kit.FileLine(-1, 3)})
|
||||
}
|
||||
func (m *Message) ErrorNotImplement(arg ...Any) *Message {
|
||||
m.Error(true, append(kit.List(ErrNotImplement), append(arg, logs.FileLineMeta(2)))...)
|
||||
|
@ -432,7 +432,7 @@ func init() {
|
||||
mdb.Config(m, INSTEADOF, strings.TrimPrefix(strings.TrimSuffix(value[mdb.NAME], _INSTEADOF), "url."))
|
||||
}
|
||||
})
|
||||
m.Cmd(web.DREAM, "scan")
|
||||
m.Go(func() { m.Cmd(web.DREAM, nfs.SCAN) })
|
||||
}},
|
||||
INIT: {Name: "init remote*", Help: "初始化", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionDefault(nfs.PATH, kit.Path(""))
|
||||
|
Loading…
x
Reference in New Issue
Block a user