forked from x/icebergs
opt some
This commit is contained in:
parent
8d30b1c0bb
commit
c2d4cea08a
@ -26,7 +26,7 @@ func _daemon_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
}
|
||||
h := mdb.HashCreate(m.Spawn(), STATUS, START,
|
||||
ice.CMD, kit.Join(cmd.Args, lex.SP), DIR, cmd.Dir, ENV, kit.Select("", cmd.Env),
|
||||
m.OptionSimple(CMD_INPUT, CMD_OUTPUT, CMD_ERRPUT, mdb.CACHE_CLEAR_ON_EXIT),
|
||||
m.OptionSimple(CMD_INPUT, CMD_OUTPUT, CMD_ERRPUT, mdb.CACHE_CLEAR_ONEXIT),
|
||||
)
|
||||
if e := cmd.Start(); m.Warn(e, ice.ErrNotStart, cmd.Args) {
|
||||
mdb.HashModify(m, h, STATUS, ERROR, ERROR, e)
|
||||
@ -100,7 +100,7 @@ const DAEMON = "daemon"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
DAEMON: {Name: "daemon hash auto", Help: "守护进程", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { mdb.HashPrunesValue(m, mdb.CACHE_CLEAR_ON_EXIT, ice.TRUE) }},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { mdb.HashPrunesValue(m, mdb.CACHE_CLEAR_ONEXIT, ice.TRUE) }},
|
||||
START: {Name: "start cmd* dir env", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Options(CMD_DIR, m.Option(DIR), CMD_ENV, kit.Split(m.Option(ENV), " ="))
|
||||
_daemon_exec(m, _system_cmd(m, kit.Split(m.Option(ice.CMD))...))
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
func _tail_create(m *ice.Message, arg ...string) {
|
||||
h := mdb.HashCreate(m, arg)
|
||||
kit.For(kit.Split(m.Option(nfs.FILE)), func(file string) {
|
||||
m.Options(cli.CMD_OUTPUT, nfs.Pipe(m, func(text string) { mdb.ZoneInsert(m, h, nfs.FILE, file, nfs.SIZE, len(text), mdb.TEXT, text) }), mdb.CACHE_CLEAR_ON_EXIT, ice.TRUE)
|
||||
m.Options(cli.CMD_OUTPUT, nfs.Pipe(m, func(text string) { mdb.ZoneInsert(m, h, nfs.FILE, file, nfs.SIZE, len(text), mdb.TEXT, text) }), mdb.CACHE_CLEAR_ONEXIT, ice.TRUE)
|
||||
m.Cmd(cli.DAEMON, TAIL, "-n", "0", "-f", file)
|
||||
})
|
||||
}
|
||||
|
@ -117,6 +117,8 @@ const (
|
||||
MONTH = "720h"
|
||||
DAYS = "72h"
|
||||
HOUR = "1h"
|
||||
|
||||
CACHE_CLEAR_ONEXIT = "cache.clear.onexit"
|
||||
)
|
||||
const (
|
||||
HASH_FIELD = "time,hash,type,name,text"
|
||||
|
@ -94,8 +94,6 @@ const (
|
||||
|
||||
SOURCE = "_source"
|
||||
TARGET = "_target"
|
||||
|
||||
CACHE_CLEAR_ON_EXIT = "cache.clear.on.exit"
|
||||
)
|
||||
const (
|
||||
INPUTS = "inputs"
|
||||
|
@ -48,7 +48,7 @@ func init() {
|
||||
m.Push(PATH, path.Join(p, s.Name())+kit.Select("", PS, s.IsDir()))
|
||||
m.Push(SIZE, kit.FmtSize(s.Size()))
|
||||
})
|
||||
m.Sort(PATH).PushAction(mdb.REMOVE).StatusTimeCount()
|
||||
m.PushAction(mdb.REMOVE).StatusTimeCount()
|
||||
}
|
||||
}},
|
||||
})
|
||||
@ -86,7 +86,9 @@ func ReadDir(m optionMessage, p string) ([]os.FileInfo, error) {
|
||||
list, e := OptionFiles(m).ReadDir(p)
|
||||
for i := 0; i < len(list)-1; i++ {
|
||||
for j := i + 1; j < len(list); j++ {
|
||||
if !list[i].IsDir() && list[j].IsDir() || list[i].Name() > list[j].Name() {
|
||||
if list[i].IsDir() && !list[j].IsDir() {
|
||||
continue
|
||||
} else if !list[i].IsDir() && list[j].IsDir() || list[i].Name() > list[j].Name() {
|
||||
list[i], list[j] = list[j], list[i]
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func _dream_show(m *ice.Message, name string) {
|
||||
m.Options(cli.CMD_DIR, kit.Path(p), cli.CMD_ENV, kit.Simple(
|
||||
cli.CTX_OPS, Domain(tcp.LOCALHOST, m.Cmdv(SERVE, tcp.PORT)), cli.CTX_LOG, ice.VAR_LOG_BOOT_LOG, cli.CTX_PID, ice.VAR_LOG_ICE_PID,
|
||||
cli.PATH, cli.BinPath(p, ""), cli.USER, ice.Info.Username, kit.EnvSimple(cli.HOME, cli.TERM, cli.SHELL), mdb.Configv(m, cli.ENV),
|
||||
), cli.CMD_OUTPUT, path.Join(p, ice.VAR_LOG_BOOT_LOG))
|
||||
), cli.CMD_OUTPUT, path.Join(p, ice.VAR_LOG_BOOT_LOG), mdb.CACHE_CLEAR_ONEXIT, ice.TRUE)
|
||||
defer m.Options(cli.CMD_DIR, "", cli.CMD_ENV, "", cli.CMD_OUTPUT, "")
|
||||
gdb.Event(m, DREAM_CREATE, m.OptionSimple(mdb.NAME, mdb.TYPE))
|
||||
kit.If(m.Option(nfs.TEMPLATE), func() { _dream_template(m, p) })
|
||||
|
@ -160,8 +160,7 @@ func _repos_status(m *ice.Message, p string, repos *git.Repository) error {
|
||||
for k, v := range status {
|
||||
if kit.IsIn(k, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO, ice.ETC_LOCAL_SHY) {
|
||||
continue
|
||||
}
|
||||
if kit.IsIn(kit.Ext(k), "swp", "swo") || kit.IsIn(kit.Split(k, nfs.PS)[0], ice.BIN, ice.VAR, ice.USR) {
|
||||
} else if kit.IsIn(kit.Ext(k), "swp", "swo") || kit.IsIn(kit.Split(k, nfs.PS)[0], ice.BIN, ice.VAR, ice.USR) {
|
||||
continue
|
||||
}
|
||||
if m.Push(REPOS, p).Push(STATUS, string(v.Worktree)+string(v.Staging)).Push(nfs.FILE, k); m.Option(ice.MSG_MODE) == mdb.ZONE {
|
||||
@ -172,7 +171,7 @@ func _repos_status(m *ice.Message, p string, repos *git.Repository) error {
|
||||
case git.Untracked:
|
||||
m.PushButton(ADD, nfs.TRASH)
|
||||
case git.Modified:
|
||||
m.PushButton(ADD)
|
||||
m.PushButton(COMMIT)
|
||||
default:
|
||||
m.PushButton(COMMIT)
|
||||
}
|
||||
@ -207,9 +206,9 @@ func _repos_total(m *ice.Message, p string, repos *git.Repository, stats map[str
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func _repos_vimer(m *ice.Message, _repos_path func(m *ice.Message, p string, arg ...string) string, arg ...string) {
|
||||
func _repos_inner(m *ice.Message, _repos_path func(m *ice.Message, p string, arg ...string) string, arg ...string) {
|
||||
if len(arg) == 0 || arg[0] != ice.RUN {
|
||||
arg = []string{path.Join(arg[:3]...), kit.Select("README.md", arg, 3)}
|
||||
arg = []string{path.Join(arg[:3]...) + nfs.PS, kit.Select("README.md", arg, 3)}
|
||||
} else if kit.Select("", arg, 1) != ctx.ACTION {
|
||||
if ls := kit.Split(path.Join(m.Option(nfs.DIR_ROOT), arg[1]), nfs.PS); len(ls) < 2 || ls[2] == INDEX {
|
||||
if repos := _repos_open(m, ls[0]); len(arg) < 3 {
|
||||
@ -249,13 +248,14 @@ func _repos_vimer(m *ice.Message, _repos_path func(m *ice.Message, p string, arg
|
||||
} else if len(arg) < 3 {
|
||||
if iter, err := commit.Files(); !m.Warn(err) {
|
||||
iter.ForEach(func(file *object.File) error {
|
||||
m.Push(nfs.PATH, file.Name)
|
||||
// m.Push(nfs.PATH, file.Name)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
if stats, err := commit.Stats(); err == nil {
|
||||
for _, stat := range stats {
|
||||
m.Echo(stat.Name)
|
||||
m.Push(nfs.PATH, stat.Name)
|
||||
// m.Echo(stat.Name)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -282,11 +282,19 @@ func _repos_vimer(m *ice.Message, _repos_path func(m *ice.Message, p string, arg
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.DisplayLocal(m, "code/vimer.js", "style", "output")
|
||||
ctx.DisplayLocal(m, "code/inner.js", "style", "output")
|
||||
return
|
||||
}
|
||||
ctx.ProcessField(m, "", arg, arg...)
|
||||
}
|
||||
func _repos_credentials(m *ice.Message) map[string]*url.URL {
|
||||
list := map[string]*url.URL{}
|
||||
m.Cmd(nfs.CAT, kit.HomePath(".git-credentials"), func(line string) {
|
||||
u := kit.ParseURL(line)
|
||||
list[u.Host] = u
|
||||
})
|
||||
return list
|
||||
}
|
||||
|
||||
const (
|
||||
INIT = "init"
|
||||
@ -363,11 +371,7 @@ func init() {
|
||||
})
|
||||
}},
|
||||
PUSH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
list := map[string]*url.URL{}
|
||||
m.Cmd(nfs.CAT, kit.HomePath(".git-credentials"), func(line string) {
|
||||
u := kit.ParseURL(line)
|
||||
list[u.Host] = u
|
||||
})
|
||||
list := _repos_credentials(m)
|
||||
_repos_each(m, "", func(repos *git.Repository, value ice.Maps) error {
|
||||
if value[ORIGIN] == "" {
|
||||
return nil
|
||||
@ -407,8 +411,8 @@ func init() {
|
||||
if cfg, err := config.LoadConfig(config.GlobalScope); err == nil {
|
||||
if cfg.Author.Email == "" || cfg.Author.Name == "" {
|
||||
opt.Author = &object.Signature{
|
||||
Name: m.Option(ice.MSG_USERNAME),
|
||||
Email: m.Option(ice.MSG_USERNAME) + "@163.com",
|
||||
Email: kit.Select(m.Option(ice.MSG_USERNAME)+"@163.com", mdb.Config(m, aaa.EMAIL)),
|
||||
Name: kit.Select(m.Option(ice.MSG_USERNAME), mdb.Config(m, aaa.USERNAME)),
|
||||
When: time.Now(),
|
||||
}
|
||||
}
|
||||
@ -421,7 +425,7 @@ func init() {
|
||||
if repos := kit.Select(m.Option(REPOS), arg, 0); repos != "" {
|
||||
_repos_status(m, repos, _repos_open(m, repos))
|
||||
} else {
|
||||
last, remote := "", ""
|
||||
last, remote, password, list := "", "", "", _repos_credentials(m)
|
||||
_repos_each(m, "", func(repos *git.Repository, value ice.Maps) error {
|
||||
if refer, err := repos.Head(); err == nil {
|
||||
if commit, err := repos.CommitObject(refer.Hash()); err == nil {
|
||||
@ -429,12 +433,15 @@ func init() {
|
||||
kit.If(_last > last, func() { last = _last })
|
||||
}
|
||||
}
|
||||
if _remote, err := repos.Remote(ORIGIN); err == nil {
|
||||
if _remote, err := repos.Remote(ORIGIN); err == nil && (remote == "" || remote == path.Base(kit.Path(""))) {
|
||||
remote = kit.Select(remote, kit.Select("", _remote.Config().URLs, 0))
|
||||
}
|
||||
return _repos_status(m, value[REPOS], repos)
|
||||
})
|
||||
m.Sort("repos,status,file").Status(mdb.TIME, last, REMOTE, remote, kit.MDB_COUNT, kit.Split(m.FormatSize())[0], kit.MDB_COST, m.FormatCost())
|
||||
if u, ok := list[kit.ParseURL(remote).Host]; ok {
|
||||
password, _ = u.User.Password()
|
||||
}
|
||||
m.Sort("repos,status,file").Status(mdb.TIME, last, kit.Select(aaa.TECH, aaa.VOID, password == ""), m.Option(aaa.EMAIL), REMOTE, remote, kit.MDB_COUNT, kit.Split(m.FormatSize())[0], kit.MDB_COST, m.FormatCost())
|
||||
}
|
||||
}},
|
||||
TOTAL: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -478,7 +485,7 @@ func init() {
|
||||
m.Cmd("", CLONE, ORIGIN, p, nfs.PATH, m.Option(cli.CMD_DIR), ice.Maps{cli.CMD_DIR: ""})
|
||||
})
|
||||
}},
|
||||
code.VIMER: {Hand: func(m *ice.Message, arg ...string) { _repos_vimer(m, _repos_path, arg...) }},
|
||||
code.INNER: {Hand: func(m *ice.Message, arg ...string) { _repos_inner(m, _repos_path, arg...) }},
|
||||
}, mdb.HashAction(mdb.SHORT, REPOS, mdb.FIELD, "time,repos,branch,commit,origin"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
mdb.HashSelect(m, arg...).Sort(REPOS).Action(CLONE, PULL, PUSH, STATUS)
|
||||
@ -496,7 +503,7 @@ func init() {
|
||||
_repos_stats(m, repos, arg[2])
|
||||
}
|
||||
} else {
|
||||
m.Cmdy("", code.VIMER, arg)
|
||||
m.Cmdy("", code.INNER, arg)
|
||||
}
|
||||
}},
|
||||
})
|
||||
|
@ -103,7 +103,7 @@ func init() {
|
||||
web.RenderHeader(m.W, "WWW-Authenticate", `Basic realm="git server"`)
|
||||
return
|
||||
} else if !nfs.Exists(m, repos) {
|
||||
_repos_init(m, repos)
|
||||
m.Cmd(Prefix(SERVICE), mdb.CREATE, mdb.NAME, path.Base(repos))
|
||||
}
|
||||
case UPLOAD_PACK:
|
||||
if m.Warn(!nfs.Exists(m, repos), ice.ErrNotFound, arg[0]) {
|
||||
@ -139,7 +139,7 @@ func init() {
|
||||
}
|
||||
}},
|
||||
TOKEN: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(TOKEN, cli.MAKE) }},
|
||||
code.VIMER: {Hand: func(m *ice.Message, arg ...string) { _repos_vimer(m, _service_path, arg...) }},
|
||||
code.INNER: {Hand: func(m *ice.Message, arg ...string) { _repos_inner(m, _service_path, arg...) }},
|
||||
}, mdb.HashAction(mdb.SHORT, REPOS, mdb.FIELD, "time,repos,branch,commit"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
mdb.HashSelect(m, arg...).Sort(REPOS).Action(mdb.CREATE, TOKEN)
|
||||
@ -156,7 +156,7 @@ func init() {
|
||||
_repos_stats(m, repos, arg[1])
|
||||
}
|
||||
} else {
|
||||
m.Cmdy("", code.VIMER, arg)
|
||||
m.Cmdy("", code.INNER, arg)
|
||||
}
|
||||
}},
|
||||
})
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"shylinux.com/x/go-git/v5/config"
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
@ -129,8 +130,8 @@ func init() {
|
||||
}
|
||||
}},
|
||||
CONFIGS: {Name: "configs email username", Help: "配置", Hand: func(m *ice.Message, arg ...string) {
|
||||
_configs_set(m, USER_NAME, m.Option(aaa.USERNAME))
|
||||
_configs_set(m, USER_EMAIL, m.Option(aaa.EMAIL))
|
||||
mdb.Config(m, aaa.USERNAME, m.Option(aaa.USERNAME))
|
||||
mdb.Config(m, aaa.EMAIL, m.Option(aaa.EMAIL))
|
||||
}},
|
||||
INSTEADOF: {Name: "insteadof from* to", Help: "代理", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(CONFIGS, func(value ice.Maps) {
|
||||
@ -166,19 +167,13 @@ func init() {
|
||||
}, gdb.EventAction(web.DREAM_TABLES), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == ctx.ACTION {
|
||||
m.Cmdy(REPOS, arg)
|
||||
} else if config, err := config.LoadConfig(config.GlobalScope); err == nil && config.User.Email == "" && mdb.Config(m, aaa.EMAIL) == "" {
|
||||
m.Action(CONFIGS).Echo("please config email and name. ").EchoButton(CONFIGS)
|
||||
} else if len(arg) == 0 {
|
||||
m.Cmdy(REPOS, STATUS).Action(PULL, PUSH, "oauth", "insteadof")
|
||||
return
|
||||
files, adds, dels, last := _status_list(m)
|
||||
m.StatusTimeCount("files", files, "adds", adds, "dels", dels, "last", last, nfs.ORIGIN, _git_remote(m))
|
||||
m.Action(PULL, PUSH, "insteadof", "oauth").Sort("repos,type,file")
|
||||
m.Option(aaa.EMAIL, kit.Select(mdb.Config(m, aaa.EMAIL), config.User.Email))
|
||||
m.Cmdy(REPOS, STATUS).Action(PULL, PUSH, "oauth", CONFIGS)
|
||||
} else {
|
||||
m.Cmdy(REPOS, arg[0], MASTER, INDEX, m.Cmdv(REPOS, arg[0], MASTER, INDEX, nfs.FILE))
|
||||
return
|
||||
_repos_cmd(m, arg[0], DIFF)
|
||||
files, adds, dels := _status_stat(m, 0, 0, 0)
|
||||
m.StatusTime("files", files, "adds", adds, "dels", dels)
|
||||
m.Action(COMMIT, STASH)
|
||||
}
|
||||
}},
|
||||
})
|
||||
|
@ -74,7 +74,7 @@ func init() {
|
||||
}
|
||||
total := false
|
||||
kit.If(len(arg) > 0 && arg[0] == mdb.TOTAL, func() { total, arg = true, arg[1:] })
|
||||
args := []string{"log", "--shortstat", "--pretty=commit: %ad %n%s", "--date=iso", "--reverse"}
|
||||
args := []string{"log", "--shortstat", "--pretty=commit: %H %ad %n%s", "--date=iso", "--reverse"}
|
||||
if len(arg) > 0 {
|
||||
arg[0] += kit.Select("", " 00:00:00", strings.Contains(arg[0], "-") && !strings.Contains(arg[0], nfs.DF))
|
||||
args = append(args, kit.Select("-n", "--since", strings.Contains(arg[0], "-")))
|
||||
@ -84,6 +84,7 @@ func init() {
|
||||
}
|
||||
from, days, commit, adds, dels := "", 0, 0, 0, 0
|
||||
kit.SplitKV(lex.NL, "commit:", _git_cmds(m, args...), func(text string, ls []string) {
|
||||
m.Debug("what %v", ls)
|
||||
add, del := "0", "0"
|
||||
for _, v := range kit.Split(strings.TrimSpace(kit.Select("", ls, -1)), mdb.FS) {
|
||||
switch {
|
||||
@ -93,18 +94,18 @@ func init() {
|
||||
del = kit.Split(v)[0]
|
||||
}
|
||||
}
|
||||
hs := strings.Split(ls[0], lex.SP)
|
||||
if total {
|
||||
if commit++; from == "" {
|
||||
hs := strings.Split(ls[0], lex.SP)
|
||||
if t, e := time.Parse("2006-01-02", hs[0]); e == nil {
|
||||
from, days = hs[0], int(time.Now().Sub(t).Hours())/24
|
||||
if t, e := time.Parse("2006-01-02", hs[1]); e == nil {
|
||||
from, days = hs[1], int(time.Now().Sub(t).Hours())/24
|
||||
}
|
||||
}
|
||||
adds += kit.Int(add)
|
||||
dels += kit.Int(del)
|
||||
return
|
||||
}
|
||||
m.Push(FROM, ls[0]).Push(ADDS, add).Push(DELS, del).Push(REST, kit.Int(add)-kit.Int(del)).Push(COMMIT, ls[1])
|
||||
m.Push(FROM, hs[1]).Push(ADDS, add).Push(DELS, del).Push(REST, kit.Int(add)-kit.Int(del)).Push(COMMIT, ls[1]).Push(mdb.HASH, hs[0])
|
||||
})
|
||||
if total {
|
||||
m.Push(TAGS, _git_cmds(m, "describe", "--tags"))
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/core/code"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -11,9 +13,16 @@ const TREND = "trend"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TREND: {Name: "trend repos@key begin_time@date auto", Help: "趋势图", Actions: ice.Actions{
|
||||
TREND: {Name: "trend repos@key begin_time@date auto", Help: "趋势图", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(REPOS, ice.OptionFields("repos,time")) }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.DETAIL: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy("", code.INNER, m.Option(REPOS), MASTER, m.Option(mdb.HASH), m.Cmdv(REPOS, m.Option(REPOS), MASTER, m.Option(mdb.HASH), nfs.FILE))
|
||||
}},
|
||||
code.INNER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(REPOS, code.INNER, arg)
|
||||
ctx.DisplayLocal(m, "code/inner.js", "style", "float")
|
||||
}},
|
||||
}, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy(REPOS)
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user