Skip to content

Commit 3d9e0ff

Browse files
committed
✨ feat: add cmd/gmoji and add some new const and repo methods
1 parent 37294cd commit 3d9e0ff

5 files changed

Lines changed: 56 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Allow custom build configuration
1818
- Allow custom build filtering , styles, etc
1919
- can be used directly in GitHub Actions
20+
- Support git-emoji code search and replace render
2021

2122
> **[中文说明](README.zh-CN.md)**
2223

README.zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- 允许自定义生成配置
2020
- 允许自定义生成过滤、样式等
2121
- 可以直接在 GitHub Actions 中使用
22+
- 支持 `git-emoji` code 搜索和替换渲染
2223

2324
> **[EN-README](README.md)**
2425

cmd/gmoji/main.go

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package main
22

33
import (
4+
"fmt"
5+
6+
"github.com/gookit/gitw/gmoji"
47
"github.com/gookit/goutil/cflag"
8+
"github.com/gookit/goutil/cliutil"
59
"github.com/gookit/goutil/errorx"
610
)
711

@@ -10,17 +14,50 @@ var cmd = cflag.New(func(c *cflag.CFlags) {
1014
c.Desc = "quick show or render git emoji code"
1115
})
1216

13-
var opts = struct {
17+
var geOpts = struct {
18+
list bool
19+
lang string
1420
render string
15-
search string
21+
search cflag.String
1622
}{}
1723

24+
// quick run:
25+
//
26+
// go run ./cmd/gmoji
27+
// go run ./cmd/gmoji -h
28+
//
29+
// install to GOPATH/bin:
30+
//
31+
// go install ./cmd/gmoji
1832
func main() {
19-
cmd.StringVar(&opts.render, "render", "", "want rendered text;;r")
20-
cmd.StringVar(&opts.search, "search", "", "want rendered text;;s")
33+
cmd.Var(&geOpts.search, "search", "search emoji by keywords,multi by comma;;s")
34+
cmd.StringVar(&geOpts.render, "render", "", "want rendered text;;r")
35+
cmd.StringVar(&geOpts.lang, "lang", gmoji.LangEN, "select language for emojis;;L")
36+
cmd.BoolVar(&geOpts.list, "list", false, "list all git emojis;;ls,l")
37+
2138
cmd.Func = execute
39+
cmd.QuickRun()
2240
}
2341

2442
func execute(c *cflag.CFlags) error {
25-
return errorx.Raw("TODO")
43+
em, err := gmoji.Emojis(geOpts.lang)
44+
if err != nil {
45+
return err
46+
}
47+
48+
if geOpts.list {
49+
cliutil.Warnf("All git emojis(total: %d):\n", em.Len())
50+
fmt.Println(em.String())
51+
return nil
52+
}
53+
54+
if geOpts.search != "" {
55+
sub := em.Search(geOpts.search.Strings(), 10)
56+
57+
cliutil.Warnf("Matched emojis(total: %d):\n", sub.Len())
58+
fmt.Println(sub.String())
59+
return nil
60+
}
61+
62+
return errorx.Raw("TODO render ...")
2663
}

gitw.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const (
2727
GitHubHost = "github.com"
2828
// GitHubURL string
2929
GitHubURL = "https://github.com"
30+
// GitHubGit string
31+
GitHubGit = "git@github.com"
3032
)
3133

3234
// git host type

repo.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,16 @@ func (r *Repo) RemoteNames() []string {
481481
return r.loadRemoteInfos().remoteNames
482482
}
483483

484+
// RemoteLines get like: {origin: url, other: url}
485+
func (r *Repo) RemoteLines() map[string]string {
486+
remotes := make(map[string]string)
487+
for name, infos := range r.remoteInfosMp {
488+
remotes[name] = infos.FetchInfo().URL
489+
}
490+
491+
return remotes
492+
}
493+
484494
// UpstreamPath get current upstream remote and branch.
485495
// Returns like: origin/main
486496
//

0 commit comments

Comments
 (0)