Skip to content

Commit 8f61df0

Browse files
committed
improve module unregister
1 parent f9cd878 commit 8f61df0

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

cmds/module/main.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,26 @@ func main() {
7474
}
7575

7676
func unregister(container *dic.Container, util *color.Color, module string) {
77-
workDir, _ := os.Getwd()
78-
word := container.GetCoreUtilWord()
7977
config := container.GetCoreConfigParser()
78+
word := container.GetCoreUtilWord()
8079
pluralizer := container.GetCoreUtilPluralizer()
81-
moduleName := word.Camelcase(module)
80+
moduleName := word.Camelcase(pluralizer.Singular(module))
81+
list := config.Parse()
82+
83+
exist := false
84+
for _, v := range list {
85+
if v == fmt.Sprintf("module:%s", word.Underscore(module)) {
86+
exist = true
87+
break
88+
}
89+
}
90+
91+
if !exist {
92+
util.Println("Module tidak terdaftar")
93+
return
94+
}
95+
96+
workDir, _ := os.Getwd()
8297

8398
yaml := fmt.Sprintf("%s/modules.yaml", workDir)
8499
file, _ := ioutil.ReadFile(yaml)
@@ -92,7 +107,6 @@ func unregister(container *dic.Container, util *color.Color, module string) {
92107
modules = modRegex.ReplaceAllString(modules, "")
93108
ioutil.WriteFile(yaml, []byte(modules), 0644)
94109

95-
list := config.Parse()
96110
if len(list) == 0 {
97111
regex := regexp.MustCompile(fmt.Sprintf("(?m)[\r\n]+^.*%s.*$", "github.com/crowdeco/skeleton/dics/modules"))
98112
codeblock = regex.ReplaceAllString(codeblock, fmt.Sprintf("\n %s", generators.MODULE_IMPORT))

docs/basic_usage.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
- Jalankan aplikasi `go run cmds/app/main.go`
1010

1111
- Modulmu dapat diakses via `http://localhost:<APP_PORT>/api/[API_VERSION]/<modul-plural>` `modul-plural` adalah bentuk plural dari nama modul yang kamu masukkan, kamu juga dapat melihatnya pada file `protos/<modul>.proto`, bila bingung, bisa melihat contoh pada [skeleton-todo](https://github.com/crowdeco/skeleton-todo/blob/main/protos/todo.proto#L34)
12+
13+
- Untuk menghapus module, kamu dapat jalankan perintah `go run cmds/module/main.go unregister <modul>`

0 commit comments

Comments
 (0)