mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-08 04:20:59 -05:00
migrate groups from urfave/cli to spf13/cobra
Signed-off-by: Christian Richter <c.richter@opencloud.eu>
This commit is contained in:
committed by
Florian Schade
parent
8d6f7a8942
commit
07956c97f8
@@ -8,19 +8,19 @@ import (
|
|||||||
"github.com/opencloud-eu/opencloud/services/groups/pkg/config"
|
"github.com/opencloud-eu/opencloud/services/groups/pkg/config"
|
||||||
"github.com/opencloud-eu/opencloud/services/groups/pkg/config/parser"
|
"github.com/opencloud-eu/opencloud/services/groups/pkg/config/parser"
|
||||||
"github.com/opencloud-eu/opencloud/services/groups/pkg/logging"
|
"github.com/opencloud-eu/opencloud/services/groups/pkg/logging"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Health is the entrypoint for the health command.
|
// Health is the entrypoint for the health command.
|
||||||
func Health(cfg *config.Config) *cli.Command {
|
func Health(cfg *config.Config) *cobra.Command {
|
||||||
return &cli.Command{
|
return &cobra.Command{
|
||||||
Name: "health",
|
Use: "health",
|
||||||
Usage: "check health status",
|
Short: "check health status",
|
||||||
Category: "info",
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
Before: func(c *cli.Context) error {
|
|
||||||
return configlog.ReturnError(parser.ParseConfig(cfg))
|
return configlog.ReturnError(parser.ParseConfig(cfg))
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||||
|
|
||||||
resp, err := http.Get(
|
resp, err := http.Get(
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ import (
|
|||||||
|
|
||||||
"github.com/opencloud-eu/opencloud/pkg/clihelper"
|
"github.com/opencloud-eu/opencloud/pkg/clihelper"
|
||||||
"github.com/opencloud-eu/opencloud/services/groups/pkg/config"
|
"github.com/opencloud-eu/opencloud/services/groups/pkg/config"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetCommands provides all commands for this service
|
// GetCommands provides all commands for this service
|
||||||
func GetCommands(cfg *config.Config) cli.Commands {
|
func GetCommands(cfg *config.Config) []*cobra.Command {
|
||||||
return []*cli.Command{
|
return []*cobra.Command{
|
||||||
// start this service
|
// start this service
|
||||||
Server(cfg),
|
Server(cfg),
|
||||||
|
|
||||||
@@ -24,11 +25,12 @@ func GetCommands(cfg *config.Config) cli.Commands {
|
|||||||
|
|
||||||
// Execute is the entry point for the opencloud group command.
|
// Execute is the entry point for the opencloud group command.
|
||||||
func Execute(cfg *config.Config) error {
|
func Execute(cfg *config.Config) error {
|
||||||
app := clihelper.DefaultApp(&cli.App{
|
app := clihelper.DefaultAppCobra(&cobra.Command{
|
||||||
Name: "group",
|
Use: "group",
|
||||||
Usage: "Provide groups for OpenCloud",
|
Short: "Provide groups for OpenCloud",
|
||||||
Commands: GetCommands(cfg),
|
|
||||||
})
|
})
|
||||||
|
app.AddCommand(GetCommands(cfg)...)
|
||||||
|
app.SetArgs(os.Args[1:])
|
||||||
|
|
||||||
return app.RunContext(cfg.Context, os.Args)
|
return app.ExecuteContext(cfg.Context)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,21 +17,21 @@ import (
|
|||||||
"github.com/opencloud-eu/opencloud/services/groups/pkg/revaconfig"
|
"github.com/opencloud-eu/opencloud/services/groups/pkg/revaconfig"
|
||||||
"github.com/opencloud-eu/opencloud/services/groups/pkg/server/debug"
|
"github.com/opencloud-eu/opencloud/services/groups/pkg/server/debug"
|
||||||
"github.com/opencloud-eu/reva/v2/cmd/revad/runtime"
|
"github.com/opencloud-eu/reva/v2/cmd/revad/runtime"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server is the entry point for the server command.
|
// Server is the entry point for the server command.
|
||||||
func Server(cfg *config.Config) *cli.Command {
|
func Server(cfg *config.Config) *cobra.Command {
|
||||||
return &cli.Command{
|
return &cobra.Command{
|
||||||
Name: "server",
|
Use: "server",
|
||||||
Usage: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name),
|
Short: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name),
|
||||||
Category: "server",
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
Before: func(c *cli.Context) error {
|
|
||||||
return configlog.ReturnFatal(parser.ParseConfig(cfg))
|
return configlog.ReturnFatal(parser.ParseConfig(cfg))
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||||
traceProvider, err := tracing.GetTraceProvider(c.Context, cfg.Commons.TracesExporter, cfg.Service.Name)
|
traceProvider, err := tracing.GetTraceProvider(cmd.Context(), cfg.Commons.TracesExporter, cfg.Service.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,20 +6,19 @@ import (
|
|||||||
|
|
||||||
"github.com/opencloud-eu/opencloud/pkg/registry"
|
"github.com/opencloud-eu/opencloud/pkg/registry"
|
||||||
"github.com/opencloud-eu/opencloud/pkg/version"
|
"github.com/opencloud-eu/opencloud/pkg/version"
|
||||||
|
"github.com/opencloud-eu/opencloud/services/groups/pkg/config"
|
||||||
|
|
||||||
"github.com/olekukonko/tablewriter"
|
"github.com/olekukonko/tablewriter"
|
||||||
"github.com/olekukonko/tablewriter/tw"
|
"github.com/olekukonko/tablewriter/tw"
|
||||||
"github.com/opencloud-eu/opencloud/services/groups/pkg/config"
|
"github.com/spf13/cobra"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version prints the service versions of all running instances.
|
// Version prints the service versions of all running instances.
|
||||||
func Version(cfg *config.Config) *cli.Command {
|
func Version(cfg *config.Config) *cobra.Command {
|
||||||
return &cli.Command{
|
return &cobra.Command{
|
||||||
Name: "version",
|
Use: "version",
|
||||||
Usage: "print the version of this binary and the running service instances",
|
Short: "print the version of this binary and the running service instances",
|
||||||
Category: "info",
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
Action: func(c *cli.Context) error {
|
|
||||||
fmt.Println("Version: " + version.GetString())
|
fmt.Println("Version: " + version.GetString())
|
||||||
fmt.Printf("Compiled: %s\n", version.Compiled())
|
fmt.Printf("Compiled: %s\n", version.Compiled())
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
|
|||||||
Reference in New Issue
Block a user