migrate audit 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
eb6d2dc0c4
commit
4bcc4b9ab3
@@ -2,15 +2,15 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/opencloud-eu/opencloud/services/audit/pkg/config"
|
"github.com/opencloud-eu/opencloud/services/audit/pkg/config"
|
||||||
"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",
|
||||||
Action: func(c *cli.Context) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
// Not implemented
|
// Not implemented
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import (
|
|||||||
|
|
||||||
"github.com/opencloud-eu/opencloud/pkg/clihelper"
|
"github.com/opencloud-eu/opencloud/pkg/clihelper"
|
||||||
"github.com/opencloud-eu/opencloud/services/audit/pkg/config"
|
"github.com/opencloud-eu/opencloud/services/audit/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 +24,12 @@ func GetCommands(cfg *config.Config) cli.Commands {
|
|||||||
|
|
||||||
// Execute is the entry point for the audit command.
|
// Execute is the entry point for the audit command.
|
||||||
func Execute(cfg *config.Config) error {
|
func Execute(cfg *config.Config) error {
|
||||||
app := clihelper.DefaultApp(&cli.App{
|
app := clihelper.DefaultAppCobra(&cobra.Command{
|
||||||
Name: "audit",
|
Use: "audit",
|
||||||
Usage: "starts audit service",
|
Short: "starts audit service",
|
||||||
Commands: GetCommands(cfg),
|
|
||||||
})
|
})
|
||||||
|
app.AddCommand(GetCommands(cfg)...)
|
||||||
|
app.SetArgs(os.Args[1:])
|
||||||
|
|
||||||
return app.RunContext(cfg.Context, os.Args)
|
return app.ExecuteContext(cfg.Context)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
||||||
"github.com/opencloud-eu/reva/v2/pkg/events"
|
|
||||||
"github.com/opencloud-eu/reva/v2/pkg/events/stream"
|
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
|
|
||||||
"github.com/opencloud-eu/opencloud/pkg/config/configlog"
|
"github.com/opencloud-eu/opencloud/pkg/config/configlog"
|
||||||
"github.com/opencloud-eu/opencloud/pkg/generators"
|
"github.com/opencloud-eu/opencloud/pkg/generators"
|
||||||
"github.com/opencloud-eu/opencloud/pkg/runner"
|
"github.com/opencloud-eu/opencloud/pkg/runner"
|
||||||
@@ -18,18 +14,21 @@ import (
|
|||||||
"github.com/opencloud-eu/opencloud/services/audit/pkg/server/debug"
|
"github.com/opencloud-eu/opencloud/services/audit/pkg/server/debug"
|
||||||
svc "github.com/opencloud-eu/opencloud/services/audit/pkg/service"
|
svc "github.com/opencloud-eu/opencloud/services/audit/pkg/service"
|
||||||
"github.com/opencloud-eu/opencloud/services/audit/pkg/types"
|
"github.com/opencloud-eu/opencloud/services/audit/pkg/types"
|
||||||
|
"github.com/opencloud-eu/reva/v2/pkg/events"
|
||||||
|
"github.com/opencloud-eu/reva/v2/pkg/events/stream"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server is the entrypoint for the server command.
|
// Server is the entrypoint 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 {
|
||||||
var cancel context.CancelFunc
|
var cancel context.CancelFunc
|
||||||
if cfg.Context == nil {
|
if cfg.Context == nil {
|
||||||
cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...)
|
cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...)
|
||||||
|
|||||||
@@ -2,16 +2,15 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/opencloud-eu/opencloud/services/audit/pkg/config"
|
"github.com/opencloud-eu/opencloud/services/audit/pkg/config"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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 {
|
|
||||||
// not implemented
|
// not implemented
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user