From e0656daaa01807b3d30f981cf86a7c63c91cbd59 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 3 Jan 2022 13:53:27 +0100 Subject: [PATCH] simplify commands and version handling --- accounts/pkg/command/root.go | 55 ++++++++++++------------ accounts/pkg/command/version.go | 13 ++++-- glauth/pkg/command/root.go | 41 +++++++++--------- glauth/pkg/command/version.go | 18 ++++---- graph-explorer/pkg/command/root.go | 41 +++++++++--------- graph-explorer/pkg/command/version.go | 16 +++---- graph/pkg/command/root.go | 40 +++++++++--------- graph/pkg/command/version.go | 16 +++---- graph/pkg/config/config.go | 1 - idp/pkg/command/root.go | 42 +++++++++---------- idp/pkg/command/version.go | 16 +++---- ocis-pkg/clihelper/app.go | 26 ++++++++++++ ocis/pkg/command/accounts.go | 13 +----- ocis/pkg/command/glauth.go | 5 +-- ocis/pkg/command/graph.go | 10 +---- ocis/pkg/command/graphexplorer.go | 10 +---- ocis/pkg/command/idp.go | 12 +----- ocis/pkg/command/ocs.go | 8 +--- ocis/pkg/command/proxy.go | 8 +--- ocis/pkg/command/root.go | 25 +++-------- ocis/pkg/command/settings.go | 8 +--- ocis/pkg/command/store.go | 21 ++-------- ocis/pkg/command/thumbnails.go | 4 +- ocis/pkg/command/version.go | 5 +++ ocis/pkg/command/web.go | 5 +-- ocis/pkg/command/webdav.go | 8 +--- ocs/pkg/command/root.go | 43 +++++++++---------- ocs/pkg/command/version.go | 16 +++---- proxy/pkg/command/root.go | 42 +++++++++---------- proxy/pkg/command/version.go | 16 +++---- settings/pkg/command/root.go | 43 +++++++++---------- settings/pkg/command/version.go | 16 +++---- storage/pkg/command/root.go | 60 ++++++++++++--------------- store/pkg/command/root.go | 43 +++++++++---------- store/pkg/command/version.go | 16 +++---- thumbnails/pkg/command/root.go | 43 +++++++++---------- thumbnails/pkg/command/version.go | 16 +++---- web/pkg/command/root.go | 42 +++++++++---------- web/pkg/command/version.go | 16 +++---- webdav/pkg/command/root.go | 41 +++++++++--------- webdav/pkg/command/version.go | 16 +++---- 41 files changed, 437 insertions(+), 499 deletions(-) create mode 100644 ocis-pkg/clihelper/app.go diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 05b3e83510..5122954234 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -14,49 +15,45 @@ import ( "github.com/urfave/cli/v2" ) +// 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 + AddAccount(cfg), + UpdateAccount(cfg), + ListAccounts(cfg), + InspectAccount(cfg), + RemoveAccount(cfg), + RebuildIndex(cfg), + + // infos about this service + Health(cfg), + Version(cfg), + } +} + // Execute is the entry point for the ocis-accounts command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-accounts", - Version: version.String, - Usage: "Provide accounts and groups for oCIS", - Compiled: version.Compiled(), - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-accounts", + Usage: "Provide accounts and groups for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - AddAccount(cfg), - UpdateAccount(cfg), - ListAccounts(cfg), - InspectAccount(cfg), - RemoveAccount(cfg), - RebuildIndex(cfg), - - Health(cfg), - PrintVersion(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/accounts/pkg/command/version.go b/accounts/pkg/command/version.go index 7e7fc0f571..6d3ec843f9 100644 --- a/accounts/pkg/command/version.go +++ b/accounts/pkg/command/version.go @@ -5,27 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/accounts/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get accounts services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running accounts service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index f72d940c1b..120791317a 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -6,6 +6,7 @@ import ( "os" "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,41 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// 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-glauth command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-glauth", - Version: version.String, - Usage: "Serve GLAuth API for oCIS", - Compiled: version.Compiled(), - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-glauth", + Usage: "Serve GLAuth API for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/glauth/pkg/command/version.go b/glauth/pkg/command/version.go index b9be475ab4..c3d2e4ffd3 100644 --- a/glauth/pkg/command/version.go +++ b/glauth/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/glauth/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() - services, err := reg.GetService(cfg.Ldaps.Namespace + "." + cfg.Service.Name) + services, err := reg.GetService(cfg.Ldap.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get glauth services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running glauth service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index 6a4ae2bbe9..4e3fecc58b 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -6,6 +6,7 @@ import ( "os" "github.com/owncloud/ocis/graph-explorer/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,38 +14,38 @@ import ( "github.com/urfave/cli/v2" ) +// 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 graph-explorer command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "graph-explorer", - Version: version.String, - Usage: "Serve Graph-Explorer for oCIS", - Compiled: version.Compiled(), - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "graph-explorer", + Usage: "Serve Graph-Explorer for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - }, - } + Commands: GetCommands(cfg), + }) + cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } return app.Run(os.Args) } diff --git a/graph-explorer/pkg/command/version.go b/graph-explorer/pkg/command/version.go index 2fde4e337e..400c0bf104 100644 --- a/graph-explorer/pkg/command/version.go +++ b/graph-explorer/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/graph-explorer/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get graph services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running graph service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 41b7239309..af4f264f17 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/thejerf/suture/v4" @@ -14,38 +15,37 @@ import ( "github.com/urfave/cli/v2" ) +// 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-graph command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-graph", - Version: version.String, - Usage: "Serve Graph API for oCIS", - Compiled: version.Compiled(), - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-graph", + Usage: "Serve Graph API for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } return app.Run(os.Args) } diff --git a/graph/pkg/command/version.go b/graph/pkg/command/version.go index 3eeaff740c..8ced4ad48a 100644 --- a/graph/pkg/command/version.go +++ b/graph/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/graph/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get graph services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running graph service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index f5925b7544..523bcfdb04 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -33,7 +33,6 @@ type Spaces struct { DefaultQuota string `ocisConfig:"default_quota" env:"GRAPH_SPACES_DEFAULT_QUOTA"` } -// TODO: do we really need a ldap backend if CS3 also does LDAP!? type LDAP struct { URI string `ocisConfig:"uri" env:"GRAPH_LDAP_URI"` BindDN string `ocisConfig:"bind_dn" env:"GRAPH_LDAP_BIND_DN"` diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index e346e4b1f2..bcb8e4ea1f 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -6,6 +6,7 @@ import ( "os" "github.com/owncloud/ocis/idp/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,42 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// 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-idp command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-idp", - Version: version.String, - Usage: "Serve IDP API for oCIS", - Compiled: version.Compiled(), - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-idp", + Usage: "Serve IDP API for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - PrintVersion(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/idp/pkg/command/version.go b/idp/pkg/command/version.go index 30a5451394..f9cbcd574e 100644 --- a/idp/pkg/command/version.go +++ b/idp/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/idp/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get idp services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running idp service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/ocis-pkg/clihelper/app.go b/ocis-pkg/clihelper/app.go new file mode 100644 index 0000000000..4ea39ace31 --- /dev/null +++ b/ocis-pkg/clihelper/app.go @@ -0,0 +1,26 @@ +package clihelper + +import ( + "github.com/owncloud/ocis/ocis-pkg/version" + "github.com/urfave/cli/v2" +) + +func DefaultApp(app *cli.App) *cli.App { + // version info + app.Version = version.String + app.Compiled = version.Compiled() + + // author info + app.Authors = []*cli.Author{ + { + Name: "ownCloud GmbH", + Email: "support@owncloud.com", + }, + } + + // disable global version flag + // instead we provide the version command + app.HideVersion = true + + return app +} diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 1c3db45c0d..62efe82eaa 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -13,14 +13,6 @@ func AccountsCommand(cfg *config.Config) *cli.Command { Name: "accounts", Usage: "Start accounts server", Category: "Extensions", - Subcommands: []*cli.Command{ - command.ListAccounts(cfg.Accounts), - command.AddAccount(cfg.Accounts), - command.UpdateAccount(cfg.Accounts), - command.RemoveAccount(cfg.Accounts), - command.InspectAccount(cfg.Accounts), - command.PrintVersion(cfg.Accounts), - }, Before: func(ctx *cli.Context) error { if err := ParseConfig(ctx, cfg); err != nil { return err @@ -32,10 +24,7 @@ func AccountsCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.Accounts) - return handleOriginalAction(c, origCmd) - }, + Subcommands: command.GetCommands(cfg.Accounts), } } diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index c6baacfdeb..1f9da764d0 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -24,10 +24,7 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.GLAuth) - return handleOriginalAction(c, origCmd) - }, + Subcommands: command.GetCommands(cfg.GLAuth), } } diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index ecc94826ca..92e5b532c2 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -19,18 +19,12 @@ func GraphCommand(cfg *config.Config) *cli.Command { } if cfg.Commons != nil { - cfg.Graph.Commons = cfg.Commons + cfg.Accounts.Commons = cfg.Commons } return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.Graph) - return handleOriginalAction(c, origCmd) - }, - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.Graph), - }, + Subcommands: command.GetCommands(cfg.Graph), } } diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index 7833206b91..f02ad25b75 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -19,18 +19,12 @@ func GraphExplorerCommand(cfg *config.Config) *cli.Command { } if cfg.Commons != nil { - cfg.Graph.Commons = cfg.Commons + cfg.GraphExplorer.Commons = cfg.Commons } return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.GraphExplorer) - return handleOriginalAction(c, origCmd) - }, - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.GraphExplorer), - }, + Subcommands: command.GetCommands(cfg.GraphExplorer), } } diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 7b35c15ba8..62d929cbe1 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -13,9 +13,6 @@ func IDPCommand(cfg *config.Config) *cli.Command { Name: "idp", Usage: "Start idp server", Category: "Extensions", - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.IDP), - }, Before: func(ctx *cli.Context) error { if err := ParseConfig(ctx, cfg); err != nil { return err @@ -27,14 +24,7 @@ func IDPCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - idpCommand := command.Server(cfg.IDP) - if err := idpCommand.Before(c); err != nil { - return err - } - - return cli.HandleAction(idpCommand.Action, c) - }, + Subcommands: command.GetCommands(cfg.IDP), } } diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index 243c27696f..dd010e71f3 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -24,13 +24,7 @@ func OCSCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.OCS) - return handleOriginalAction(c, origCmd) - }, - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.OCS), - }, + Subcommands: command.GetCommands(cfg.OCS), } } diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 7458a80d66..2554573a28 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -13,9 +13,6 @@ func ProxyCommand(cfg *config.Config) *cli.Command { Name: "proxy", Usage: "Start proxy server", Category: "Extensions", - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.Proxy), - }, Before: func(ctx *cli.Context) error { if err := ParseConfig(ctx, cfg); err != nil { return err @@ -27,10 +24,7 @@ func ProxyCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.Proxy) - return handleOriginalAction(c, origCmd) - }, + Subcommands: command.GetCommands(cfg.Proxy), } } diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index 51ff2189ba..163adebc80 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -4,10 +4,10 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/shared" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -16,24 +16,16 @@ import ( func Execute() error { cfg := config.DefaultConfig() - app := &cli.App{ - Name: "ocis", - Version: version.String, - Usage: "ownCloud Infinite Scale Stack", - Compiled: version.Compiled(), + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis", + Usage: "ownCloud Infinite Scale Stack", Before: func(c *cli.Context) error { + // TODO: what do do? //cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, - } + }) for _, fn := range register.Commands { app.Commands = append( @@ -47,11 +39,6 @@ func Execute() error { Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 90bdafc304..ae1fec6c60 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -13,9 +13,6 @@ func SettingsCommand(cfg *config.Config) *cli.Command { Name: "settings", Usage: "Start settings server", Category: "Extensions", - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.Settings), - }, Before: func(ctx *cli.Context) error { if err := ParseConfig(ctx, cfg); err != nil { return err @@ -27,10 +24,7 @@ func SettingsCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.Settings) - return handleOriginalAction(c, origCmd) - }, + Subcommands: command.GetCommands(cfg.Settings), } } diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index cec0e2e028..6fda33d5eb 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -9,36 +9,23 @@ import ( // StoreCommand is the entrypoint for the ocs command. func StoreCommand(cfg *config.Config) *cli.Command { - //var globalLog shared.Log return &cli.Command{ Name: "store", Usage: "Start a go-micro store", Category: "Extensions", - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.Store), - }, Before: func(ctx *cli.Context) error { if err := ParseConfig(ctx, cfg); err != nil { return err } - // TODO: what to do - //globalLog = cfg.Log + if cfg.Commons != nil { + cfg.Store.Commons = cfg.Commons + } return nil }, - Action: func(c *cli.Context) error { - // TODO: what to do - // if accounts logging is empty in ocis.yaml - //if (cfg.Store.Log == shared.Log{}) && (globalLog != shared.Log{}) { - // // we can safely inherit the global logging values. - // cfg.Store.Log = globalLog - //} - - origCmd := command.Server(cfg.Store) - return handleOriginalAction(c, origCmd) - }, + Subcommands: command.GetCommands(cfg.Store), } } diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index f671358e77..add5b66845 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -13,9 +13,6 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { Name: "thumbnails", Usage: "Start thumbnails server", Category: "Extensions", - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.Thumbnails), - }, Before: func(ctx *cli.Context) error { if err := ParseConfig(ctx, cfg); err != nil { return err @@ -31,6 +28,7 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { origCmd := command.Server(cfg.Thumbnails) return handleOriginalAction(c, origCmd) }, + Subcommands: command.GetCommands(cfg.Thumbnails), } } diff --git a/ocis/pkg/command/version.go b/ocis/pkg/command/version.go index 21d762b591..f693406832 100644 --- a/ocis/pkg/command/version.go +++ b/ocis/pkg/command/version.go @@ -7,6 +7,7 @@ import ( tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" mreg "go-micro.dev/v4/registry" @@ -19,6 +20,10 @@ func VersionCommand(cfg *config.Config) *cli.Command { Usage: "Lists running services with version", Category: "Runtime", Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() serviceList, err := reg.ListServices() if err != nil { diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index c3f2df2eaf..e1f66f8eef 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -24,10 +24,7 @@ func WebCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.Web) - return handleOriginalAction(c, origCmd) - }, + Subcommands: command.GetCommands(cfg.Web), } } diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index 31cb2c5285..ea7f518225 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -14,9 +14,6 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { Name: "webdav", Usage: "Start webdav server", Category: "Extensions", - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.WebDAV), - }, Before: func(ctx *cli.Context) error { if err := ParseConfig(ctx, cfg); err != nil { return err @@ -28,10 +25,7 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { return nil }, - Action: func(c *cli.Context) error { - origCmd := command.Server(cfg.WebDAV) - return handleOriginalAction(c, origCmd) - }, + Subcommands: command.GetCommands(cfg.WebDAV), } } diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 3f17fb049e..2b143d547a 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,43 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// 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-ocs command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-ocs", - Version: version.String, - Usage: "Serve OCS API for oCIS", - Compiled: version.Compiled(), - - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-ocs", + Usage: "Serve OCS API for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - PrintVersion(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/ocs/pkg/command/version.go b/ocs/pkg/command/version.go index dac137c15c..116c081df6 100644 --- a/ocs/pkg/command/version.go +++ b/ocs/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/ocs/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get ocs services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running ocs service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 02ab99c584..283e85246a 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,42 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// 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-proxy command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-proxy", - Version: version.String, - Usage: "proxy for oCIS", - Compiled: version.Compiled(), - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-proxy", + Usage: "proxy for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - PrintVersion(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/proxy/pkg/command/version.go b/proxy/pkg/command/version.go index bd9cd67179..7545db5d42 100644 --- a/proxy/pkg/command/version.go +++ b/proxy/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/proxy/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get proxy services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running proxy service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index 9ee08aef21..03340bb1af 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,43 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// 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. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-settings", - Version: version.String, - Usage: "Provide settings and permissions for oCIS", - Compiled: version.Compiled(), - - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-settings", + Usage: "Provide settings and permissions for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - PrintVersion(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/settings/pkg/command/version.go b/settings/pkg/command/version.go index 55091cf81a..15c3901363 100644 --- a/settings/pkg/command/version.go +++ b/settings/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/settings/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get settings services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running settings service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/storage/pkg/command/root.go b/storage/pkg/command/root.go index 18400c6b75..477ec1df1a 100644 --- a/storage/pkg/command/root.go +++ b/storage/pkg/command/root.go @@ -3,58 +3,50 @@ package command import ( "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" "github.com/owncloud/ocis/ocis-pkg/log" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/storage/pkg/config" "github.com/urfave/cli/v2" ) +// GetCommands provides all commands for this service +func GetCommands(cfg *config.Config) cli.Commands { + return []*cli.Command{ + Frontend(cfg), + Gateway(cfg), + Users(cfg), + Groups(cfg), + AppProvider(cfg), + AuthBasic(cfg), + AuthBearer(cfg), + AuthMachine(cfg), + Sharing(cfg), + StorageHome(cfg), + StorageUsers(cfg), + StoragePublicLink(cfg), + StorageMetadata(cfg), + Health(cfg), + } +} + // Execute is the entry point for the storage command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "storage", - Version: version.String, - Usage: "Storage service for oCIS", - Compiled: version.Compiled(), + app := clihelper.DefaultApp(&cli.App{ + Name: "storage", + Usage: "Storage service for oCIS", - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage") }, - Commands: []*cli.Command{ - Frontend(cfg), - Gateway(cfg), - Users(cfg), - Groups(cfg), - AppProvider(cfg), - AuthBasic(cfg), - AuthBearer(cfg), - AuthMachine(cfg), - Sharing(cfg), - StorageHome(cfg), - StorageUsers(cfg), - StoragePublicLink(cfg), - StorageMetadata(cfg), - Health(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index ca3d05bb2b..c32c0c45f3 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,43 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// 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-store command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-store", - Version: version.String, - Usage: "Service to store values for ocis extensions", - Compiled: version.Compiled(), - - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-store", + Usage: "Service to store values for ocis extensions", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - PrintVersion(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/store/pkg/command/version.go b/store/pkg/command/version.go index 588e45b646..91554c791a 100644 --- a/store/pkg/command/version.go +++ b/store/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/store/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get store services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running store service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index fbaaeba51d..ad18155e75 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,43 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// 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-thumbnails command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "ocis-thumbnails", - Version: version.String, - Usage: "Example usage", - Compiled: version.Compiled(), - - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "ocis-thumbnails", + Usage: "Example usage", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - PrintVersion(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/thumbnails/pkg/command/version.go b/thumbnails/pkg/command/version.go index d3dfb24591..45030313a3 100644 --- a/thumbnails/pkg/command/version.go +++ b/thumbnails/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/thumbnails/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get thumbnails services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running thumbnails service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index b56960a86a..38c8ea330d 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,46 +14,45 @@ import ( "github.com/urfave/cli/v2" ) +// 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 web command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "web", - Version: version.String, - Usage: "Serve ownCloud Web for oCIS", - Compiled: version.Compiled(), - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, + app := clihelper.DefaultApp(&cli.App{ + Name: "web", + Usage: "Serve ownCloud Web for oCIS", Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } // ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { + // TODO: remove cli.Context _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { return err diff --git a/web/pkg/command/version.go b/web/pkg/command/version.go index 94a87b4966..7b76bdcfe9 100644 --- a/web/pkg/command/version.go +++ b/web/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/web/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get web services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running web service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil } diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index e39d64cd0d..2846715b32 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/owncloud/ocis/ocis-pkg/clihelper" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/ocis-pkg/version" @@ -13,41 +14,39 @@ import ( "github.com/urfave/cli/v2" ) +// 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-webdav command. func Execute(cfg *config.Config) error { - app := &cli.App{ - Name: "webdav", - Version: version.String, - Usage: "Serve WebDAV API for oCIS", - Compiled: version.Compiled(), + app := clihelper.DefaultApp(&cli.App{ + Name: "webdav", + Usage: "Serve WebDAV API for oCIS", - Authors: []*cli.Author{ - { - Name: "ownCloud GmbH", - Email: "support@owncloud.com", - }, - }, Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ - Server(cfg), - Health(cfg), - }, - } + Commands: GetCommands(cfg), + }) cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ - Name: "version,v", - Usage: "Print the version", - } - return app.Run(os.Args) } diff --git a/webdav/pkg/command/version.go b/webdav/pkg/command/version.go index a0ab763f59..f6649a41a7 100644 --- a/webdav/pkg/command/version.go +++ b/webdav/pkg/command/version.go @@ -5,30 +5,32 @@ import ( "os" "github.com/owncloud/ocis/ocis-pkg/registry" + "github.com/owncloud/ocis/ocis-pkg/version" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/webdav/pkg/config" "github.com/urfave/cli/v2" ) -// PrintVersion prints the service versions of all running instances. -func PrintVersion(cfg *config.Config) *cli.Command { +// Version prints the service versions of all running instances. +func Version(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, Action: func(c *cli.Context) error { + fmt.Println("Version: " + version.String) + fmt.Printf("Compiled: %s\n", version.Compiled()) + fmt.Println("") + reg := registry.GetRegistry() services, err := reg.GetService(cfg.HTTP.Namespace + "." + cfg.Service.Name) if err != nil { - fmt.Println(fmt.Errorf("could not get webdav services from the registry: %v", err)) + fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) return err } if len(services) == 0 { - fmt.Println("No running webdav service found.") + fmt.Println("No running " + cfg.Service.Name + " service found.") return nil }