migrate postprocessing 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
131178e5d9
commit
b76d4fc661
@@ -2,15 +2,15 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/opencloud-eu/opencloud/services/postprocessing/pkg/config"
|
"github.com/opencloud-eu/opencloud/services/postprocessing/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
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -10,37 +10,21 @@ import (
|
|||||||
"github.com/opencloud-eu/reva/v2/pkg/events"
|
"github.com/opencloud-eu/reva/v2/pkg/events"
|
||||||
"github.com/opencloud-eu/reva/v2/pkg/events/stream"
|
"github.com/opencloud-eu/reva/v2/pkg/events/stream"
|
||||||
"github.com/opencloud-eu/reva/v2/pkg/utils"
|
"github.com/opencloud-eu/reva/v2/pkg/utils"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RestartPostprocessing cli command to restart postprocessing
|
// RestartPostprocessing cli command to restart postprocessing
|
||||||
func RestartPostprocessing(cfg *config.Config) *cli.Command {
|
func RestartPostprocessing(cfg *config.Config) *cobra.Command {
|
||||||
return &cli.Command{
|
restartPostprocessingCmd := &cobra.Command{
|
||||||
Name: "resume",
|
Use: "resume",
|
||||||
Aliases: []string{"restart"},
|
Aliases: []string{"restart"},
|
||||||
Usage: "resume postprocessing for an uploadID",
|
Short: "resume postprocessing for an uploadID",
|
||||||
Flags: []cli.Flag{
|
|
||||||
&cli.StringFlag{
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
Name: "upload-id",
|
|
||||||
Aliases: []string{"u"},
|
|
||||||
Usage: "the uploadid to resume. Ignored if unset.",
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "step",
|
|
||||||
Aliases: []string{"s"},
|
|
||||||
Usage: "resume all uploads in the given postprocessing step. Ignored if upload-id is set.",
|
|
||||||
Value: "finished",
|
|
||||||
},
|
|
||||||
&cli.BoolFlag{
|
|
||||||
Name: "restart",
|
|
||||||
Aliases: []string{"r"},
|
|
||||||
Usage: "restart postprocessing for the given uploadID. Ignores the step flag.",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
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 {
|
||||||
connName := generators.GenerateConnectionName(cfg.Service.Name, generators.NTypeBus)
|
connName := generators.GenerateConnectionName(cfg.Service.Name, generators.NTypeBus)
|
||||||
stream, err := stream.NatsFromConfig(connName, false, stream.NatsConfig{
|
stream, err := stream.NatsFromConfig(connName, false, stream.NatsConfig{
|
||||||
Endpoint: cfg.Postprocessing.Events.Endpoint,
|
Endpoint: cfg.Postprocessing.Events.Endpoint,
|
||||||
@@ -55,14 +39,14 @@ func RestartPostprocessing(cfg *config.Config) *cli.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
uid, step := c.String("upload-id"), ""
|
uid, step := cmd.Flag("upload-id").Value.String(), ""
|
||||||
if uid == "" {
|
if uid == "" {
|
||||||
step = c.String("step")
|
step = cmd.Flag("step").Value.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
var ev events.Unmarshaller
|
var ev events.Unmarshaller
|
||||||
switch {
|
switch {
|
||||||
case c.Bool("retrigger"):
|
case cmd.Flag("restart").Changed:
|
||||||
ev = events.RestartPostprocessing{
|
ev = events.RestartPostprocessing{
|
||||||
UploadID: uid,
|
UploadID: uid,
|
||||||
Timestamp: utils.TSNow(),
|
Timestamp: utils.TSNow(),
|
||||||
@@ -78,4 +62,25 @@ func RestartPostprocessing(cfg *config.Config) *cli.Command {
|
|||||||
return events.Publish(context.Background(), stream, ev)
|
return events.Publish(context.Background(), stream, ev)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restartPostprocessingCmd.Flags().StringP(
|
||||||
|
"upload-id",
|
||||||
|
"u",
|
||||||
|
"",
|
||||||
|
"the uploadid to resume. Ignored if unset.",
|
||||||
|
)
|
||||||
|
restartPostprocessingCmd.Flags().StringP(
|
||||||
|
"step",
|
||||||
|
"s",
|
||||||
|
"finished",
|
||||||
|
"resume all uploads in the given postprocessing step. Ignored if upload-id is set.",
|
||||||
|
)
|
||||||
|
restartPostprocessingCmd.Flags().BoolP(
|
||||||
|
"restart",
|
||||||
|
"r",
|
||||||
|
false,
|
||||||
|
"restart postprocessing for the given uploadID. Ignores the step flag.",
|
||||||
|
)
|
||||||
|
|
||||||
|
return restartPostprocessingCmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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/postprocessing/pkg/config"
|
"github.com/opencloud-eu/opencloud/services/postprocessing/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),
|
||||||
|
|
||||||
@@ -25,11 +26,12 @@ func GetCommands(cfg *config.Config) cli.Commands {
|
|||||||
|
|
||||||
// Execute is the entry point for the postprocessing command.
|
// Execute is the entry point for the postprocessing command.
|
||||||
func Execute(cfg *config.Config) error {
|
func Execute(cfg *config.Config) error {
|
||||||
app := clihelper.DefaultApp(&cli.App{
|
app := clihelper.DefaultAppCobra(&cobra.Command{
|
||||||
Name: "postprocessing",
|
Use: "postprocessing",
|
||||||
Usage: "starts postprocessing service",
|
Short: "starts postprocessing 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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
||||||
"github.com/opencloud-eu/reva/v2/pkg/store"
|
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
microstore "go-micro.dev/v4/store"
|
|
||||||
|
|
||||||
"github.com/opencloud-eu/opencloud/pkg/runner"
|
"github.com/opencloud-eu/opencloud/pkg/runner"
|
||||||
"github.com/opencloud-eu/opencloud/pkg/tracing"
|
"github.com/opencloud-eu/opencloud/pkg/tracing"
|
||||||
"github.com/opencloud-eu/opencloud/services/postprocessing/pkg/config"
|
"github.com/opencloud-eu/opencloud/services/postprocessing/pkg/config"
|
||||||
@@ -17,15 +13,18 @@ import (
|
|||||||
"github.com/opencloud-eu/opencloud/services/postprocessing/pkg/logging"
|
"github.com/opencloud-eu/opencloud/services/postprocessing/pkg/logging"
|
||||||
"github.com/opencloud-eu/opencloud/services/postprocessing/pkg/server/debug"
|
"github.com/opencloud-eu/opencloud/services/postprocessing/pkg/server/debug"
|
||||||
"github.com/opencloud-eu/opencloud/services/postprocessing/pkg/service"
|
"github.com/opencloud-eu/opencloud/services/postprocessing/pkg/service"
|
||||||
|
"github.com/opencloud-eu/reva/v2/pkg/store"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
microstore "go-micro.dev/v4/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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 %s service without runtime (unsupervised mode)", cfg.Service.Name),
|
Short: fmt.Sprintf("start %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 {
|
|
||||||
err := parser.ParseConfig(cfg)
|
err := parser.ParseConfig(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%v", err)
|
fmt.Printf("%v", err)
|
||||||
@@ -33,7 +32,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
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)
|
||||||
|
|
||||||
var cancel context.CancelFunc
|
var cancel context.CancelFunc
|
||||||
@@ -43,7 +42,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
ctx := cfg.Context
|
ctx := cfg.Context
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,15 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/opencloud-eu/opencloud/services/postprocessing/pkg/config"
|
"github.com/opencloud-eu/opencloud/services/postprocessing/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 extension instances",
|
Short: "print the version of this binary and the running extension 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