From 82e2e17b4524900ae5afd68ec3ea23d58cabba54 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Fri, 8 Sep 2023 14:28:48 +0200 Subject: [PATCH] [F3] implement --quiet, --debug, --verbose --- cmd/forgejo/f3.go | 2 ++ cmd/forgejo/forgejo.go | 6 +++++- cmd/main.go | 17 +++++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cmd/forgejo/f3.go b/cmd/forgejo/f3.go index 75a1bd4ba6..a3a7356a8a 100644 --- a/cmd/forgejo/f3.go +++ b/cmd/forgejo/f3.go @@ -7,6 +7,8 @@ import ( "code.gitea.io/gitea/modules/git" + _ "code.gitea.io/gitea/services/f3/driver" // register the driver + "github.com/urfave/cli/v2" f3_cmd "lab.forgefriends.org/friendlyforgeformat/gof3/cmd" ) diff --git a/cmd/forgejo/forgejo.go b/cmd/forgejo/forgejo.go index 1b7e16ca8f..5dc2c261c4 100644 --- a/cmd/forgejo/forgejo.go +++ b/cmd/forgejo/forgejo.go @@ -33,7 +33,11 @@ func CmdForgejo(ctx context.Context) *cli.Command { return &cli.Command{ Name: "forgejo-cli", Usage: "Forgejo CLI", - Flags: []cli.Flag{}, + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "debug", + }, + }, Subcommands: []*cli.Command{ CmdActions(ctx), CmdF3(ctx), diff --git a/cmd/main.go b/cmd/main.go index 5e5ba3b31f..adb9b404ad 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -130,6 +130,7 @@ func NewMainApp(version, versionExtra string) *cli.App { var subCmdsStandalone []*cli.Command = make([]*cli.Command, 0, 10) var subCmdWithConfig []*cli.Command = make([]*cli.Command, 0, 10) + var globalFlags []cli.Flag = make([]cli.Flag, 0, 10) // // If the executable is forgejo-cli, provide a Forgejo specific CLI @@ -138,6 +139,17 @@ func NewMainApp(version, versionExtra string) *cli.App { if executable == "forgejo-cli" { subCmdsStandalone = append(subCmdsStandalone, forgejo.CmdActions(context.Background())) subCmdWithConfig = append(subCmdWithConfig, forgejo.CmdF3(context.Background())) + globalFlags = append(globalFlags, []cli.Flag{ + &cli.BoolFlag{ + Name: "quiet", + }, + &cli.BoolFlag{ + Name: "verbose", + }, + &cli.BoolFlag{ + Name: "debug", + }, + }...) } else { // // Otherwise provide a Gitea compatible CLI which includes Forgejo @@ -149,10 +161,10 @@ func NewMainApp(version, versionExtra string) *cli.App { subCmdWithConfig = append(subCmdWithConfig, CmdActions) } - return innerNewMainApp(version, versionExtra, subCmdsStandalone, subCmdWithConfig) + return innerNewMainApp(version, versionExtra, subCmdsStandalone, subCmdWithConfig, globalFlags) } -func innerNewMainApp(version, versionExtra string, subCmdsStandaloneArgs, subCmdWithConfigArgs []*cli.Command) *cli.App { +func innerNewMainApp(version, versionExtra string, subCmdsStandaloneArgs, subCmdWithConfigArgs []*cli.Command, globalFlagsArgs []cli.Flag) *cli.App { app := cli.NewApp() app.Name = "Gitea" app.Usage = "A painless self-hosted Git service" @@ -194,6 +206,7 @@ func innerNewMainApp(version, versionExtra string, subCmdsStandaloneArgs, subCmd app.DefaultCommand = CmdWeb.Name globalFlags := appGlobalFlags() + globalFlags = append(globalFlags, globalFlagsArgs...) app.Flags = append(app.Flags, cli.VersionFlag) app.Flags = append(app.Flags, globalFlags...) app.HideHelp = true // use our own help action to show helps (with more information like default config)