-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split command line interfaces and http server
- Loading branch information
Showing
7 changed files
with
50 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package register | ||
|
||
import ( | ||
"github.com/RobyFerro/go-web-framework" | ||
"github.com/RobyFerro/go-web/app/http/middleware" | ||
) | ||
|
||
// BaseEntities returns a struct that contains Go-Web base entities | ||
func BaseEntities() foundation.BaseEntities { | ||
return foundation.BaseEntities{ | ||
Commands: Commands, | ||
Controllers: Controllers, | ||
Services: Services, | ||
SingletonServices: SingletonServices, | ||
CommandServices: CommandServices, | ||
Models: Models, | ||
Middlewares: middleware.Middleware{}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package register | ||
|
||
import ( | ||
"github.com/RobyFerro/go-web-framework/register" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/RobyFerro/go-web-framework/cli" | ||
"github.com/RobyFerro/go-web/app" | ||
"github.com/RobyFerro/go-web/service" | ||
"github.com/common-nighthawk/go-figure" | ||
"log" | ||
"github.com/RobyFerro/go-web-framework" | ||
"github.com/RobyFerro/go-web/register" | ||
"os" | ||
) | ||
|
||
func main() { | ||
myFigure := figure.NewFigure("GWF-Alfred", "", true) | ||
myFigure.Print() | ||
|
||
fmt.Println("\nGo-Web - Alfred CLI tool - Author: [email protected]") | ||
|
||
args := os.Args[1:] | ||
|
||
if len(args) == 0 { | ||
log.Fatal("Missing arguments, type -h/--help to show available commands") | ||
} | ||
|
||
switch args[0] { | ||
case "--help", "-h": | ||
help() | ||
case "--make-controller", "-mC": | ||
if len(args) != 2 { | ||
log.Fatal("Missing controller name") | ||
} | ||
cmd := cli.ControllerCreate{Args: args[1]} | ||
cmd.Run() | ||
case "--make-command", "-mCMD": | ||
if len(args) != 2 { | ||
log.Fatal("Missing command name") | ||
} | ||
|
||
cmd := cli.CmdCreate{Args: args[1]} | ||
cmd.Run() | ||
case "--make-model", "-mM": | ||
if len(args) != 2 { | ||
log.Fatal("Missing model name") | ||
} | ||
cmd := cli.ModelCreate{Args: args[1]} | ||
cmd.Run() | ||
case "--make-migration", "-mDBM": | ||
if len(args) != 2 { | ||
log.Fatal("Missing migration name") | ||
} | ||
cmd := cli.MigrationCreate{Args: args[1]} | ||
cmd.Run() | ||
case "--make-job", "-mJ": | ||
if len(args) != 2 { | ||
log.Fatal("Missing migration name") | ||
} | ||
cmd := cli.JobCreate{Args: args[1]} | ||
cmd.Run() | ||
case "--migrate-up", "-mU": | ||
conf, err := app.Configuration() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
db := service.ConnectDB(conf) | ||
cmd := cli.MigrationUp{} | ||
cmd.Run(db) | ||
case "--migrate-rollback", "-mR": | ||
if len(args) != 2 { | ||
log.Fatal("Missing rollback step") | ||
} | ||
|
||
conf, err := app.Configuration() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
db := service.ConnectDB(conf) | ||
cmd := cli.MigrateRollback{ | ||
Args: args[1], | ||
} | ||
cmd.Run(db) | ||
case "--make-middleware", "-mMW": | ||
if len(args) != 2 { | ||
log.Fatal("Missing middleware name") | ||
} | ||
cmd := cli.MiddlewareCreate{Args: args[1]} | ||
cmd.Run() | ||
case "--generate-key", "-gK": | ||
cmd := cli.GenerateKey{} | ||
cmd.Run() | ||
} | ||
} | ||
|
||
func help() { | ||
fmt.Println("Usage: alfred [command] [options]") | ||
|
||
fmt.Println("\nBASIC COMMANDS:") | ||
fmt.Println(" --help -h: Shows help menu") | ||
|
||
fmt.Println("\nPROJECT COMMANDS - RUNS THIS COMMANDS ONLY IN PROJECT ROOT!") | ||
fmt.Println(" --make-controller, -mC <controller_name>: Creates new Go-Web controller") | ||
fmt.Println(" --make-command, -mCMD <command_name>: Creates new Go-Web command") | ||
fmt.Println(" --make-model, -mM <model_name>: Creates new Go-Web model") | ||
fmt.Println(" --make-migration , -mDBM <migration_name>: Creates new Go-Web SQL migration") | ||
fmt.Println(" --make-middleware , -mMW <middleware_name>: Creates new middleware") | ||
fmt.Println(" --make-job, -mJ <job_name>: Creates new async job") | ||
fmt.Println(" --migrate-up, -mU: Executes migrations") | ||
fmt.Println(" --migrate-rollback, -mR <steps>: Executes migrations rollback") | ||
fmt.Println(" --generate-key, -gK: Generate new application key") | ||
entities := register.BaseEntities() | ||
foundation.StartCommand(os.Args[1:], entities) | ||
} |