Files
ocis/settings/pkg/command/root.go
T

68 lines
1.5 KiB
Go
Raw Normal View History

package command
import (
2021-03-03 15:05:21 +01:00
"context"
"os"
2022-01-03 13:53:27 +01:00
"github.com/owncloud/ocis/ocis-pkg/clihelper"
2021-03-09 15:55:45 +01:00
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/settings/pkg/config"
"github.com/owncloud/ocis/settings/pkg/config/parser"
2021-03-11 15:50:01 +01:00
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
2022-01-03 13:53:27 +01:00
// GetCommands provides all commands for this service
func GetCommands(cfg *config.Config) cli.Commands {
return []*cli.Command{
// start this service
Server(cfg),
// interaction with this service
// infos about this service
Health(cfg),
Version(cfg),
}
}
// Execute is the entry point for the ocis-settings command.
2021-03-03 15:05:21 +01:00
func Execute(cfg *config.Config) error {
2022-01-03 13:53:27 +01:00
app := clihelper.DefaultApp(&cli.App{
Name: "ocis-settings",
Usage: "Provide settings and permissions for oCIS",
Before: func(c *cli.Context) error {
return parser.ParseConfig(cfg)
},
2022-01-03 13:53:27 +01:00
Commands: GetCommands(cfg),
})
cli.HelpFlag = &cli.BoolFlag{
Name: "help,h",
Usage: "Show the help",
}
return app.Run(os.Args)
}
2021-03-03 15:05:21 +01:00
// SutureService allows for the settings command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
2021-03-11 15:50:01 +01:00
cfg *config.Config
2021-03-03 15:05:21 +01:00
}
// NewSutureService creates a new settings.SutureService
2021-03-11 15:50:01 +01:00
func NewSutureService(cfg *ociscfg.Config) suture.Service {
cfg.Settings.Commons = cfg.Commons
2021-03-03 15:05:21 +01:00
return SutureService{
2021-03-11 15:50:01 +01:00
cfg: cfg.Settings,
2021-03-03 15:05:21 +01:00
}
}
2021-03-11 15:50:01 +01:00
func (s SutureService) Serve(ctx context.Context) error {
s.cfg.Context = ctx
2021-03-03 15:05:21 +01:00
if err := Execute(s.cfg); err != nil {
2021-03-11 15:50:01 +01:00
return err
2021-03-03 15:05:21 +01:00
}
2021-03-11 15:50:01 +01:00
return nil
2021-03-03 15:05:21 +01:00
}