3
0
corteza/app/cli.go
2020-11-28 14:29:33 +01:00

68 lines
1.4 KiB
Go

package app
import (
"context"
"github.com/cortezaproject/corteza-server/pkg/cli"
"github.com/cortezaproject/corteza-server/pkg/rbac"
"github.com/cortezaproject/corteza-server/store"
systemCommands "github.com/cortezaproject/corteza-server/system/commands"
)
// CLI function initializes basic Corteza subsystems
// and sets-up the command line interface
func (app *CortezaApp) InitCLI() {
ctx := cli.Context()
app.Command = cli.RootCommand(nil)
serveCmd := cli.ServeCommand(func() (err error) {
if err = app.Activate(ctx); err != nil {
return
}
return app.Serve(ctx)
})
upgradeCmd := cli.UpgradeCommand(func() (err error) {
if err = app.InitStore(ctx); err != nil {
return
}
return
})
provisionCmd := cli.ProvisionCommand(func() (err error) {
if err = app.Provision(ctx); err != nil {
return
}
// Provisioning doesn't automatically reload rbac rules, so this is required
rbac.Global().Reload(ctx)
return
})
storeInit := func(ctx context.Context) (store.Storer, error) {
err := app.InitStore(ctx)
return app.Store, err
}
app.Command.AddCommand(
systemCommands.Users(app),
systemCommands.Roles(app),
systemCommands.Auth(app),
systemCommands.RBAC(app),
systemCommands.Sink(app),
systemCommands.Import(storeInit),
serveCmd,
upgradeCmd,
provisionCmd,
cli.VersionCommand(),
)
}
func (app *CortezaApp) Execute() error {
return app.Command.Execute()
}