summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorEarl Warren <contact@earl-warren.org>2024-02-25 09:54:25 +0100
committerEarl Warren <contact@earl-warren.org>2024-02-25 09:54:25 +0100
commit8a5a7a88be7a5a4d11d0f482f84b9275534d0837 (patch)
treef006f41e504e1e528a1fc0fabf55fdbc7c3979be /cmd
parentMerge pull request 'Fixes #2452 - Skipping SHA256 tests if unsupported' (#245... (diff)
downloadforgejo-8a5a7a88be7a5a4d11d0f482f84b9275534d0837.tar.xz
forgejo-8a5a7a88be7a5a4d11d0f482f84b9275534d0837.zip
[REFACTOR] cli: prepareWorkPathAndCustomConf is not just for actions
Split prepareWorkPathAndCustomConf out of the actions sub-command. In the CLI prepareWorkPathAndCustomConf is a preparation step that is needed before running the sub-command actions in the Forgejo CLI. It is currently specific to this sub-command but it will be useful for other sub-commands such as F3.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/forgejo/actions.go28
-rw-r--r--cmd/forgejo/forgejo.go22
2 files changed, 26 insertions, 24 deletions
diff --git a/cmd/forgejo/actions.go b/cmd/forgejo/actions.go
index afda831227..fc6b5f70f7 100644
--- a/cmd/forgejo/actions.go
+++ b/cmd/forgejo/actions.go
@@ -35,7 +35,8 @@ func SubcmdActionsGenerateRunnerToken(ctx context.Context) *cli.Command {
return &cli.Command{
Name: "generate-runner-token",
Usage: "Generate a new token for a runner to use to register with the server",
- Action: prepareWorkPathAndCustomConf(ctx, func(cliCtx *cli.Context) error { return RunGenerateActionsRunnerToken(ctx, cliCtx) }),
+ Before: prepareWorkPathAndCustomConf(ctx),
+ Action: func(cliCtx *cli.Context) error { return RunGenerateActionsRunnerToken(ctx, cliCtx) },
Flags: []cli.Flag{
&cli.StringFlag{
Name: "scope",
@@ -59,7 +60,8 @@ func SubcmdActionsRegister(ctx context.Context) *cli.Command {
return &cli.Command{
Name: "register",
Usage: "Idempotent registration of a runner using a shared secret",
- Action: prepareWorkPathAndCustomConf(ctx, func(cliCtx *cli.Context) error { return RunRegister(ctx, cliCtx) }),
+ Before: prepareWorkPathAndCustomConf(ctx),
+ Action: func(cliCtx *cli.Context) error { return RunRegister(ctx, cliCtx) },
Flags: []cli.Flag{
&cli.StringFlag{
Name: "secret",
@@ -219,25 +221,3 @@ func RunGenerateActionsRunnerToken(ctx context.Context, cliCtx *cli.Context) err
}
return nil
}
-
-func prepareWorkPathAndCustomConf(ctx context.Context, action cli.ActionFunc) func(cliCtx *cli.Context) error {
- return func(cliCtx *cli.Context) error {
- if !ContextGetNoInit(ctx) {
- var args setting.ArgWorkPathAndCustomConf
- // from children to parent, check the global flags
- for _, curCtx := range cliCtx.Lineage() {
- if curCtx.IsSet("work-path") && args.WorkPath == "" {
- args.WorkPath = curCtx.String("work-path")
- }
- if curCtx.IsSet("custom-path") && args.CustomPath == "" {
- args.CustomPath = curCtx.String("custom-path")
- }
- if curCtx.IsSet("config") && args.CustomConf == "" {
- args.CustomConf = curCtx.String("config")
- }
- }
- setting.InitWorkPathAndCommonConfig(os.Getenv, args)
- }
- return action(cliCtx)
- }
-}
diff --git a/cmd/forgejo/forgejo.go b/cmd/forgejo/forgejo.go
index affb39157a..710996e1c0 100644
--- a/cmd/forgejo/forgejo.go
+++ b/cmd/forgejo/forgejo.go
@@ -145,3 +145,25 @@ func handleCliResponseExtra(ctx context.Context, extra private.ResponseExtra) er
}
return cli.Exit(extra.Error, 1)
}
+
+func prepareWorkPathAndCustomConf(ctx context.Context) func(c *cli.Context) error {
+ return func(c *cli.Context) error {
+ if !ContextGetNoInit(ctx) {
+ var args setting.ArgWorkPathAndCustomConf
+ // from children to parent, check the global flags
+ for _, curCtx := range c.Lineage() {
+ if curCtx.IsSet("work-path") && args.WorkPath == "" {
+ args.WorkPath = curCtx.String("work-path")
+ }
+ if curCtx.IsSet("custom-path") && args.CustomPath == "" {
+ args.CustomPath = curCtx.String("custom-path")
+ }
+ if curCtx.IsSet("config") && args.CustomConf == "" {
+ args.CustomConf = curCtx.String("config")
+ }
+ }
+ setting.InitWorkPathAndCommonConfig(os.Getenv, args)
+ }
+ return nil
+ }
+}