Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlo Strokov <pstrokov@gitlab.com>2023-05-24 23:55:18 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2023-06-01 14:40:38 +0300
commit242b2548fa9bf0d573416de8bdbe94a25b52e297 (patch)
tree4211b158bccb3942f0e41fa6034e8728e413c303
parent5f25aa43d8dc2b4549aba5c695d9ec76dea3c7c3 (diff)
praefect: Remove old sub-command implementation leftovers
All sub-commands of Praefect were moved to a third party urfave/cli/v2 library. The old helper functions and an interface are removed as they are not used anymore. Also, the help text generated by new library now contains information about all sub-commands and doesn't need to be modified. The 'serve' sub-command can now be restricted to disallow arguments to be passed for it. Part of: #5001
-rw-r--r--internal/cli/praefect/main.go22
-rw-r--r--internal/cli/praefect/serve.go22
-rw-r--r--internal/cli/praefect/subcmd.go43
3 files changed, 6 insertions, 81 deletions
diff --git a/internal/cli/praefect/main.go b/internal/cli/praefect/main.go
index 874a2cac0..1b2ec299e 100644
--- a/internal/cli/praefect/main.go
+++ b/internal/cli/praefect/main.go
@@ -15,8 +15,6 @@ import (
"fmt"
"log"
"os"
- "sort"
- "strings"
"github.com/urfave/cli/v2"
"gitlab.com/gitlab-org/gitaly/v16/internal/praefect/service"
@@ -80,7 +78,6 @@ func NewApp() *cli.App {
Usage: "load configuration from `FILE`",
},
},
- CustomAppHelpTemplate: helpTextTemplate(),
}
}
@@ -100,22 +97,3 @@ func mustProvideConfigFlag(ctx *cli.Context, command string) string {
return pathToConfigFile
}
-
-func helpTextTemplate() string {
- var cmds []string
- for k := range subcommands(nil) {
- cmds = append(cmds, k)
- }
- sort.Strings(cmds)
-
- // Because not all sub-commands are registered with the new approach they won't be shown
- // with the -help. To have them in the output we inject a simple list of their names into
- // the template to have them presented.
- return strings.Replace(
- cli.AppHelpTemplate,
- `COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}`,
- `COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}`+
- "\n "+strings.Join(cmds, "\n "),
- 1,
- )
-}
diff --git a/internal/cli/praefect/serve.go b/internal/cli/praefect/serve.go
index 328459ef6..7e5b93a3e 100644
--- a/internal/cli/praefect/serve.go
+++ b/internal/cli/praefect/serve.go
@@ -7,7 +7,6 @@ import (
"fmt"
"math/rand"
"net/http"
- "os"
"runtime/debug"
"time"
@@ -47,26 +46,17 @@ func newServeCommand() *cli.Command {
Usage: "launch the server daemon",
Action: serveAction,
HideHelpCommand: true,
+ Before: func(context *cli.Context) error {
+ if context.Args().Present() {
+ return unexpectedPositionalArgsError{Command: context.Command.Name}
+ }
+ return nil
+ },
}
}
func serveAction(ctx *cli.Context) error {
logger := log.Default()
- // In order to support execution of all sub-commands not yet migrated to use a new cli
- // implementation the invocation is done manually here.
- subCmd := ctx.Args().First()
- if subCmd != "" {
- // It doesn't make difference if we provide command name to the invocation below
- // or not as there won't be any output printed, because sub-commands are not yet
- // registered.
- pathToConfigFile := mustProvideConfigFlag(ctx, "")
- conf, err := getConfig(logger, pathToConfigFile)
- if err != nil {
- return err
- }
- os.Exit(subCommand(conf, logger, subCmd, ctx.Args().Slice()[1:]))
- }
-
// The ctx.Command.Name can't be used here because if `praefect -config FILE` is used
// it will be set to 'praefect' instead of 'serve'.
pathToConfigFile := mustProvideConfigFlag(ctx, "serve")
diff --git a/internal/cli/praefect/subcmd.go b/internal/cli/praefect/subcmd.go
index 2767c4b42..537edaea9 100644
--- a/internal/cli/praefect/subcmd.go
+++ b/internal/cli/praefect/subcmd.go
@@ -4,13 +4,10 @@ import (
"context"
"database/sql"
"errors"
- "flag"
"fmt"
"os"
- "os/signal"
"time"
- "github.com/sirupsen/logrus"
gitalyauth "gitlab.com/gitlab-org/gitaly/v16/auth"
"gitlab.com/gitlab-org/gitaly/v16/client"
internalclient "gitlab.com/gitlab-org/gitaly/v16/internal/grpc/client"
@@ -19,11 +16,6 @@ import (
"google.golang.org/grpc"
)
-type subcmd interface {
- FlagSet() *flag.FlagSet
- Exec(flags *flag.FlagSet, config config.Config) error
-}
-
const (
defaultDialTimeout = 10 * time.Second
paramVirtualStorage = "virtual-storage"
@@ -31,41 +23,6 @@ const (
paramAuthoritativeStorage = "authoritative-storage"
)
-func subcommands(logger *logrus.Entry) map[string]subcmd {
- return map[string]subcmd{}
-}
-
-// subCommand returns an exit code, to be fed into os.Exit.
-func subCommand(conf config.Config, logger *logrus.Entry, arg0 string, argRest []string) int {
- interrupt := make(chan os.Signal, 1)
- signal.Notify(interrupt, os.Interrupt)
-
- go func() {
- <-interrupt
- os.Exit(130) // indicates program was interrupted
- }()
-
- subcmd, ok := subcommands(logger)[arg0]
- if !ok {
- printfErr("%s: unknown subcommand: %q\n", progname, arg0)
- return 1
- }
-
- flags := subcmd.FlagSet()
-
- if err := flags.Parse(argRest); err != nil {
- printfErr("%s\n", err)
- return 1
- }
-
- if err := subcmd.Exec(flags, conf); err != nil {
- printfErr("%s\n", err)
- return 1
- }
-
- return 0
-}
-
func getNodeAddress(cfg config.Config) (string, error) {
switch {
case cfg.SocketPath != "":