mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-23 22:29:59 -05:00
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 (
|
||||
"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.
|
||||
func Health(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "health",
|
||||
Usage: "Check health status",
|
||||
Action: func(c *cli.Context) error {
|
||||
func Health(cfg *config.Config) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "health",
|
||||
Short: "Check health status",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
// Not implemented
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -10,37 +10,21 @@ import (
|
||||
"github.com/opencloud-eu/reva/v2/pkg/events"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/events/stream"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/utils"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// RestartPostprocessing cli command to restart postprocessing
|
||||
func RestartPostprocessing(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "resume",
|
||||
func RestartPostprocessing(cfg *config.Config) *cobra.Command {
|
||||
restartPostprocessingCmd := &cobra.Command{
|
||||
Use: "resume",
|
||||
Aliases: []string{"restart"},
|
||||
Usage: "resume postprocessing for an uploadID",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
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 {
|
||||
Short: "resume postprocessing for an uploadID",
|
||||
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
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)
|
||||
stream, err := stream.NatsFromConfig(connName, false, stream.NatsConfig{
|
||||
Endpoint: cfg.Postprocessing.Events.Endpoint,
|
||||
@@ -55,14 +39,14 @@ func RestartPostprocessing(cfg *config.Config) *cli.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
uid, step := c.String("upload-id"), ""
|
||||
uid, step := cmd.Flag("upload-id").Value.String(), ""
|
||||
if uid == "" {
|
||||
step = c.String("step")
|
||||
step = cmd.Flag("step").Value.String()
|
||||
}
|
||||
|
||||
var ev events.Unmarshaller
|
||||
switch {
|
||||
case c.Bool("retrigger"):
|
||||
case cmd.Flag("restart").Changed:
|
||||
ev = events.RestartPostprocessing{
|
||||
UploadID: uid,
|
||||
Timestamp: utils.TSNow(),
|
||||
@@ -78,4 +62,25 @@ func RestartPostprocessing(cfg *config.Config) *cli.Command {
|
||||
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/services/postprocessing/pkg/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// GetCommands provides all commands for this service
|
||||
func GetCommands(cfg *config.Config) cli.Commands {
|
||||
return []*cli.Command{
|
||||
func GetCommands(cfg *config.Config) []*cobra.Command {
|
||||
return []*cobra.Command{
|
||||
// start this service
|
||||
Server(cfg),
|
||||
|
||||
@@ -25,11 +26,12 @@ func GetCommands(cfg *config.Config) cli.Commands {
|
||||
|
||||
// Execute is the entry point for the postprocessing command.
|
||||
func Execute(cfg *config.Config) error {
|
||||
app := clihelper.DefaultApp(&cli.App{
|
||||
Name: "postprocessing",
|
||||
Usage: "starts postprocessing service",
|
||||
Commands: GetCommands(cfg),
|
||||
app := clihelper.DefaultAppCobra(&cobra.Command{
|
||||
Use: "postprocessing",
|
||||
Short: "starts postprocessing service",
|
||||
})
|
||||
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/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/tracing"
|
||||
"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/server/debug"
|
||||
"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.
|
||||
func Server(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "server",
|
||||
Usage: fmt.Sprintf("start %s service without runtime (unsupervised mode)", cfg.Service.Name),
|
||||
Category: "server",
|
||||
Before: func(c *cli.Context) error {
|
||||
func Server(cfg *config.Config) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "server",
|
||||
Short: fmt.Sprintf("start %s service without runtime (unsupervised mode)", cfg.Service.Name),
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
err := parser.ParseConfig(cfg)
|
||||
if err != nil {
|
||||
fmt.Printf("%v", err)
|
||||
@@ -33,7 +32,7 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
}
|
||||
return err
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
var cancel context.CancelFunc
|
||||
@@ -43,7 +42,7 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
}
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,16 +2,15 @@ package command
|
||||
|
||||
import (
|
||||
"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.
|
||||
func Version(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "version",
|
||||
Usage: "print the version of this binary and the running extension instances",
|
||||
Category: "info",
|
||||
Action: func(c *cli.Context) error {
|
||||
func Version(cfg *config.Config) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "print the version of this binary and the running extension instances",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
// not implemented
|
||||
return nil
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user