From 2471de39f39f7b01861c24ced557c2c23755ab77 Mon Sep 17 00:00:00 2001 From: Ilja Neumann Date: Wed, 22 Apr 2020 15:48:09 +0200 Subject: [PATCH] Extract server flags to flagset pkg --- pkg/command/server.go | 44 ++----------------------------------- pkg/flagset/flagset.go | 50 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 42 deletions(-) create mode 100644 pkg/flagset/flagset.go diff --git a/pkg/command/server.go b/pkg/command/server.go index b96f9a3959..67471b248a 100644 --- a/pkg/command/server.go +++ b/pkg/command/server.go @@ -3,6 +3,7 @@ package command import ( "context" "fmt" + "github.com/owncloud/ocis-accounts/pkg/flagset" "syscall" "github.com/micro/cli/v2" @@ -22,48 +23,7 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start ocis accounts service", Description: "an accounts backend manager (driver) needs to be specified. By default the service uses the filesystem as storage", - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "manager", - DefaultText: "filesystem", - Usage: "accounts backend manager", - Value: "filesystem", - EnvVars: []string{"ACCOUNTS_MANAGER"}, - Destination: &cfg.Manager, - }, - &cli.StringFlag{ - Name: "mount-path", - Usage: "mounting point (necessary when manager=filesystem)", - EnvVars: []string{"ACCOUNTS_MOUNT_PATH"}, - Destination: &cfg.MountPath, - }, - &cli.StringFlag{ - Name: "name", - Value: "accounts", - DefaultText: "accounts", - Usage: "service name", - EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, - }, - &cli.StringFlag{ - Name: "namespace", - Aliases: []string{"ns"}, - Value: "com.owncloud", - DefaultText: "com.owncloud", - Usage: "namespace", - EnvVars: []string{"ACCOUNTS_NAMESPACE"}, - Destination: &cfg.Server.Namespace, - }, - &cli.StringFlag{ - Name: "address", - Aliases: []string{"addr"}, - Value: "localhost:9180", - DefaultText: "localhost:9180", - Usage: "service endpoint", - EnvVars: []string{"ACCOUNTS_ADDRESS"}, - Destination: &cfg.Server.Address, - }, - }, + Flags: flagset.ServerWithConfig(cfg), Before: func(c *cli.Context) error { logger = oclog.NewLogger(oclog.Name(cfg.Server.Name)) return ParseConfig(c, cfg) diff --git a/pkg/flagset/flagset.go b/pkg/flagset/flagset.go new file mode 100644 index 0000000000..bbf5012e41 --- /dev/null +++ b/pkg/flagset/flagset.go @@ -0,0 +1,50 @@ +package flagset + +import "github.com/micro/cli/v2" +import "github.com/owncloud/ocis-accounts/pkg/config" + +// ServerWithConfig applies cfg to the root flagset +func ServerWithConfig(cfg *config.Config) []cli.Flag { + return []cli.Flag{ + &cli.StringFlag{ + Name: "manager", + DefaultText: "filesystem", + Usage: "accounts backend manager", + Value: "filesystem", + EnvVars: []string{"ACCOUNTS_MANAGER"}, + Destination: &cfg.Manager, + }, + &cli.StringFlag{ + Name: "mount-path", + Usage: "mounting point (necessary when manager=filesystem)", + EnvVars: []string{"ACCOUNTS_MOUNT_PATH"}, + Destination: &cfg.MountPath, + }, + &cli.StringFlag{ + Name: "name", + Value: "accounts", + DefaultText: "accounts", + Usage: "service name", + EnvVars: []string{"ACCOUNTS_NAME"}, + Destination: &cfg.Server.Name, + }, + &cli.StringFlag{ + Name: "namespace", + Aliases: []string{"ns"}, + Value: "com.owncloud", + DefaultText: "com.owncloud", + Usage: "namespace", + EnvVars: []string{"ACCOUNTS_NAMESPACE"}, + Destination: &cfg.Server.Namespace, + }, + &cli.StringFlag{ + Name: "address", + Aliases: []string{"addr"}, + Value: "localhost:9180", + DefaultText: "localhost:9180", + Usage: "service endpoint", + EnvVars: []string{"ACCOUNTS_ADDRESS"}, + Destination: &cfg.Server.Address, + }, + } +}