CLI refactoring
This commit is contained in:
@@ -84,7 +84,6 @@ func main() {
|
||||
if err := messaging.Init(ctx); err != nil {
|
||||
log.Fatalf("Error initializing messaging: %+v", err)
|
||||
}
|
||||
|
||||
// Checks subscription, will os.Exit(1) if there is an error
|
||||
// Disabled for now, system service is the only one that validates subscription
|
||||
// ctx = subscription.Monitor(ctx)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
system "github.com/crusttech/crust/system"
|
||||
"github.com/crusttech/crust/system/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -16,9 +17,10 @@ func main() {
|
||||
log.SetOutput(os.Stdout)
|
||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||
|
||||
ctx := context.AsContext(sigctx.New())
|
||||
|
||||
flags("system", system.Flags, auth.Flags)
|
||||
|
||||
system.Init(context.AsContext(sigctx.New()))
|
||||
|
||||
setupCobra()
|
||||
system.Init(ctx)
|
||||
cli.Init(ctx)
|
||||
}
|
||||
|
||||
@@ -1,17 +1,27 @@
|
||||
package main
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
systemCli "github.com/crusttech/crust/system/cli"
|
||||
"github.com/crusttech/crust/internal/settings"
|
||||
"github.com/crusttech/crust/system/internal/repository"
|
||||
)
|
||||
|
||||
func setupCobra() {
|
||||
func Init(ctx context.Context) {
|
||||
// Main command.
|
||||
rootCmd := &cobra.Command{Use: "system-cli"}
|
||||
|
||||
settingsService := settings.NewService(settings.NewRepository(repository.DB(ctx), "sys_settings"))
|
||||
|
||||
Settings(rootCmd, settingsService)
|
||||
|
||||
ExternalAuth(ctx, rootCmd, settingsService)
|
||||
|
||||
// @todo move cmd setup lines below to similar structure as Settings()
|
||||
|
||||
// User management commands.
|
||||
var cmdUsers = &cobra.Command{
|
||||
Use: "users",
|
||||
@@ -24,7 +34,7 @@ func setupCobra() {
|
||||
Use: "list",
|
||||
Short: "List users",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
systemCli.UsersList()
|
||||
UsersList()
|
||||
},
|
||||
}
|
||||
cmdUsers.AddCommand(cmdUsersList)
|
||||
@@ -35,7 +45,7 @@ func setupCobra() {
|
||||
Short: "Assign role to user",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
systemCli.RoleAssignUser(args[1], args[0])
|
||||
RoleAssignUser(args[1], args[0])
|
||||
},
|
||||
}
|
||||
cmdUsers.AddCommand(cmdUserAssignRole)
|
||||
@@ -52,7 +62,7 @@ func setupCobra() {
|
||||
Use: "reset",
|
||||
Short: "Reset roles",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
systemCli.RolesReset()
|
||||
RolesReset()
|
||||
},
|
||||
}
|
||||
cmdRole.AddCommand(cmdRolesReset)
|
||||
@@ -63,7 +73,7 @@ func setupCobra() {
|
||||
Short: "Add user to role",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
systemCli.RoleAssignUser(args[0], args[1])
|
||||
RoleAssignUser(args[0], args[1])
|
||||
},
|
||||
}
|
||||
cmdRole.AddCommand(cmdRoleAddUser)
|
||||
Reference in New Issue
Block a user