fix flag parsing

This commit is contained in:
A.Unger
2021-03-04 14:33:16 +01:00
parent 96521d23a9
commit e8b1665f63
12 changed files with 78 additions and 66 deletions
+31 -5
View File
@@ -1,21 +1,19 @@
package command
import (
"context"
"os"
"strings"
"github.com/micro/cli/v2"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/web/pkg/config"
"github.com/owncloud/ocis/web/pkg/flagset"
"github.com/owncloud/ocis/web/pkg/version"
"github.com/spf13/viper"
)
// Execute is the entry point for the web command.
func Execute() error {
cfg := config.New()
func Execute(cfg *config.Config) error {
app := &cli.App{
Name: "web",
Version: version.String,
@@ -29,7 +27,7 @@ func Execute() error {
},
},
Flags: flagset.RootWithConfig(cfg),
//Flags: flagset.RootWithConfig(cfg),
Commands: []*cli.Command{
Server(cfg),
@@ -102,3 +100,31 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error {
return nil
}
// SutureService allows for the web command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
ctx context.Context
cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service.
cfg *config.Config
}
// NewSutureService creates a new web.SutureService
func NewSutureService(ctx context.Context, cfg *config.Config) SutureService {
sctx, cancel := context.WithCancel(ctx)
cfg.Context = sctx // propagate the context down to the go-micro services.
return SutureService{
ctx: sctx,
cancel: cancel,
cfg: cfg,
}
}
func (s SutureService) Serve() {
if err := Execute(s.cfg); err != nil {
return
}
}
func (s SutureService) Stop() {
s.cancel()
}
+1 -2
View File
@@ -30,7 +30,7 @@ func Server(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "server",
Usage: "Start integrated server",
Flags: flagset.ServerWithConfig(cfg),
Flags: append(flagset.ServerWithConfig(cfg), flagset.RootWithConfig(cfg)...),
Before: func(c *cli.Context) error {
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/")
@@ -166,7 +166,6 @@ func Server(cfg *config.Config) *cli.Command {
http.Namespace(cfg.HTTP.Namespace),
http.Config(cfg),
http.Metrics(metrics),
http.Flags(flagset.RootWithConfig(config.New())),
)
if err != nil {
+4
View File
@@ -1,5 +1,7 @@
package config
import "context"
// Log defines the available logging configuration.
type Log struct {
Level string
@@ -93,6 +95,8 @@ type Config struct {
Asset Asset
OIDC OIDC
Web Web
Context context.Context
}
// New initializes a new configuration with or without defaults.
+3 -6
View File
@@ -10,23 +10,20 @@ func RootWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "log-level",
Value: "info",
Usage: "Set logging level",
EnvVars: []string{"WEB_LOG_LEVEL"},
EnvVars: []string{"WEB_LOG_LEVEL", "OCIS_LOG_LEVEL"},
Destination: &cfg.Log.Level,
},
&cli.BoolFlag{
Name: "log-pretty",
Value: true,
Usage: "Enable pretty logging",
EnvVars: []string{"WEB_LOG_PRETTY"},
EnvVars: []string{"WEB_LOG_PRETTY", "OCIS_LOG_PRETTY"},
Destination: &cfg.Log.Pretty,
},
&cli.BoolFlag{
Name: "log-color",
Value: true,
Usage: "Enable colored logging",
EnvVars: []string{"WEB_LOG_COLOR"},
EnvVars: []string{"WEB_LOG_COLOR", "OCIS_LOG_COLOR"},
Destination: &cfg.Log.Color,
},
}