simplify commands and version handling

This commit is contained in:
Willy Kloucek
2022-01-03 13:53:27 +01:00
committed by Jörn Friedrich Dreyer
parent 5b70d46213
commit 23e7a8ffab
42 changed files with 873 additions and 499 deletions
+1 -12
View File
@@ -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),
}
}
+1 -4
View File
@@ -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),
}
}
+2 -8
View File
@@ -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),
}
}
+2 -8
View File
@@ -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),
}
}
+1 -11
View File
@@ -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),
}
}
+1 -7
View File
@@ -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),
}
}
+1 -7
View File
@@ -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),
}
}
+6 -19
View File
@@ -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)
}
+1 -7
View File
@@ -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),
}
}
+4 -17
View File
@@ -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),
}
}
+1 -3
View File
@@ -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),
}
}
+5
View File
@@ -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 {
+1 -4
View File
@@ -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),
}
}
+1 -7
View File
@@ -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),
}
}