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

68 lines
1.5 KiB
Go
Raw Normal View History

2019-12-04 17:15:11 +01:00
package command
import (
2021-03-15 15:17:29 +00:00
"context"
2019-12-04 17:15:11 +01:00
"os"
"github.com/owncloud/ocis/graph/pkg/config/parser"
2022-01-03 13:53:27 +01:00
"github.com/owncloud/ocis/ocis-pkg/clihelper"
2021-03-15 15:17:29 +00:00
"github.com/thejerf/suture/v4"
2021-02-04 11:46:32 +01:00
"github.com/owncloud/ocis/graph/pkg/config"
2021-03-15 15:17:29 +00:00
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/urfave/cli/v2"
2019-12-04 17:15:11 +01:00
)
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),
}
}
2019-12-04 17:15:11 +01:00
// Execute is the entry point for the ocis-graph command.
2021-03-15 15:17:29 +00:00
func Execute(cfg *config.Config) error {
2022-01-03 13:53:27 +01:00
app := clihelper.DefaultApp(&cli.App{
Name: "ocis-graph",
Usage: "Serve Graph API for oCIS",
2019-12-04 17:15:11 +01:00
Before: func(c *cli.Context) error {
return parser.ParseConfig(cfg)
2019-12-04 17:15:11 +01:00
},
2022-01-03 13:53:27 +01:00
Commands: GetCommands(cfg),
})
2019-12-04 17:15:11 +01:00
cli.HelpFlag = &cli.BoolFlag{
Name: "help,h",
Usage: "Show the help",
}
return app.Run(os.Args)
}
2021-03-15 15:17:29 +00:00
// SutureService allows for the graph command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config
}
// NewSutureService creates a new graph.SutureService
func NewSutureService(cfg *ociscfg.Config) suture.Service {
cfg.Graph.Commons = cfg.Commons
2021-03-15 15:17:29 +00:00
return SutureService{
cfg: cfg.Graph,
}
}
func (s SutureService) Serve(ctx context.Context) error {
s.cfg.Context = ctx
if err := Execute(s.cfg); err != nil {
return err
}
return nil
}