2020-01-22 17:49:46 +01:00
|
|
|
package command
|
|
|
|
|
|
|
|
|
|
import (
|
2021-03-15 15:17:29 +00:00
|
|
|
"context"
|
2020-01-22 17:49:46 +01:00
|
|
|
"os"
|
|
|
|
|
|
2021-02-04 12:23:11 +01:00
|
|
|
"github.com/owncloud/ocis/graph-explorer/pkg/config"
|
2022-01-03 15:21:56 +01:00
|
|
|
"github.com/owncloud/ocis/graph-explorer/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
|
|
|
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
|
|
|
|
"github.com/thejerf/suture/v4"
|
2021-09-14 16:05:03 +02:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-01-22 17:49:46 +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),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 12:24:11 +01:00
|
|
|
// Execute is the entry point for the graph-explorer 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: "graph-explorer",
|
|
|
|
|
Usage: "Serve Graph-Explorer for oCIS",
|
2020-01-22 17:49:46 +01:00
|
|
|
Before: func(c *cli.Context) error {
|
2022-01-03 15:21:56 +01:00
|
|
|
return parser.ParseConfig(cfg)
|
2020-01-22 17:49:46 +01:00
|
|
|
},
|
2022-01-03 13:53:27 +01:00
|
|
|
Commands: GetCommands(cfg),
|
|
|
|
|
})
|
|
|
|
|
|
2020-01-22 17:49:46 +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-explorer command to be embedded and supervised by a suture supervisor tree.
|
|
|
|
|
type SutureService struct {
|
|
|
|
|
cfg *config.Config
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewSutureService creates a new graph-explorer.SutureService
|
|
|
|
|
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
2021-12-17 10:44:57 +01:00
|
|
|
//cfg.GraphExplorer.Log = cfg.Log
|
2021-03-15 15:17:29 +00:00
|
|
|
return SutureService{
|
|
|
|
|
cfg: cfg.GraphExplorer,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s SutureService) Serve(ctx context.Context) error {
|
|
|
|
|
s.cfg.Context = ctx
|
|
|
|
|
if err := Execute(s.cfg); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|