Skip to content
Permalink
Browse files

add customer commandline support

Signed-off-by: Toby Yan <me@tobyan.com>
  • Loading branch information...
toby1991 committed May 14, 2019
1 parent adafcea commit c936dc81e0556bcdd9e08cf86990a89fa662d60b
Showing with 75 additions and 41 deletions.
  1. +2 −2 README.md
  2. +30 −2 app/console/commands/hello.go
  3. +5 −0 app/console/commands/kernel.go
  4. +37 −36 artisan.go
  5. +1 −1 go.mod
@@ -38,10 +38,10 @@ Totoval is an API web framework that helps Golang engineers build a performance-
- [x] Language Package
- [x] Cache: Memory
- [ ] Cache: Redis
- [x] Queue, Worker
- [x] Queue, Worker `nsq`
- [x] Event, Listener
- [ ] File Storage
- [ ] Custom Artisan Command Line
- [x] Custom Artisan Command Line
- [ ] Task Scheduling
- [ ] User Authorization
- [ ] Database Seeder
@@ -1,7 +1,35 @@
package commands

import "fmt"
import (
"fmt"

func main() {
"github.com/urfave/cli"

"github.com/totoval/framework/cmd"
)

func init() {
cmd.Add(&HelloWorld{})
}

type HelloWorld struct {
}

func (hw *HelloWorld) Command() string {
return "say:hello-world"
}

func (hw *HelloWorld) Aliases() []string {
return []string{
"c",
}
}

func (hw *HelloWorld) Description() string {
return "Say Hello"
}

func (hw *HelloWorld) Handler(c *cli.Context) error {
fmt.Println("Hello World")
return nil
}
@@ -0,0 +1,5 @@
package commands

func Initialize() {

}
@@ -1,67 +1,68 @@
package main

import (
"log"
"os"

"github.com/urfave/cli"

"github.com/totoval/framework/cache"
"github.com/totoval/framework/cmd"
"github.com/totoval/framework/cmd/groups"
"github.com/totoval/framework/cmd/migration"
"github.com/totoval/framework/database"
"github.com/totoval/framework/helpers/m"
"github.com/urfave/cli"
"log"
"os"
"github.com/totoval/framework/queue"
"totoval/app/console/commands"

"totoval/app/events"
"totoval/app/jobs"
"totoval/app/listeners"
"totoval/config"
"totoval/database/migrations"
"totoval/resources/lang"
)

func init() {
config.Initialize()
cache.Initialize()
database.Initialize()
m.Initialize()
lang.Initialize() // an translation must contains resources/lang/xx.json file (then a resources/lang/validation_translator/xx.go)
queue.Initialize()
jobs.Initialize()
events.Initialize()
listeners.Initialize()

migration.Initialize()
commands.Initialize()
}

func main() {
app := cli.NewApp()
app.Name = "artisan"
app.Usage = "Let's work like an artisan"
app.Version = "0.4.6"

chLog := make(chan interface{})

// command group
migrateCommand := &groups.MigrateCommand{MigratorInitializer: migrations.Initialize, ChLog: chLog}

//app.Flags = []cli.Flag {
// cli.StringFlag{
// Name: "lang",
// Value: "english",
// Usage: "language for the greeting",
// Destination: &language,
// },
//}
app.Commands = cmd.List()

app.Action = func(c *cli.Context) error {
return nil
}
cmd.Println(cmd.CODE_INFO, "COMMANDS:")
for _, cate := range app.Categories() {
categoryName := cate.Name
if categoryName == "" {
categoryName = "kernel"
}
cmd.Println(cmd.CODE_WARNING, " "+categoryName+":")

app.Commands = []cli.Command{
migrateCommand.MigrationInit(),
migrateCommand.Migrate(),
migrateCommand.MigrateRollBack(),
for _, cmds := range cate.Commands {
cmd.Println(cmd.CODE_SUCCESS, " "+cmds.Name+" "+cmd.Sprintf(cmd.CODE_WARNING, "%s", cmds.Usage))
}
}
return nil
}

err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}

receiveLog(chLog)
}

func receiveLog(chLog chan interface{}) {
for _log := range chLog {
if _log == nil {
os.Exit(0)
}
if __log, ok := _log.(cmd.TermLog); ok {
__log.Print()
}
}
}
2 go.mod
@@ -9,7 +9,7 @@ require (
github.com/go-playground/universal-translator v0.16.0
github.com/golang/protobuf v1.3.1
github.com/jinzhu/gorm v1.9.2
github.com/totoval/framework v0.4.6-hotfix-3
github.com/totoval/framework v0.5.0
github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43 // indirect
github.com/urfave/cli v1.20.0
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd // indirect

0 comments on commit c936dc8

Please sign in to comment.
You can’t perform that action at this time.