Skip to content

Commit 7d396f0

Browse files
zeripathjeffliu27
authored andcommitted
Add work path CLI option (go-gitea#6922)
Makes it possible to set the work path as a CLI option instead of relying on environment variables which are somewhat opaque
1 parent 5b86f46 commit 7d396f0

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

contrib/pr/checkout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func runPR() {
4343
if err != nil {
4444
log.Fatal(err)
4545
}
46-
setting.SetCustomPathAndConf("", "")
46+
setting.SetCustomPathAndConf("", "", "")
4747
setting.NewContext()
4848

4949
setting.RepoRootPath, err = ioutil.TempDir(os.TempDir(), "repos")

docs/content/doc/usage/command-line.en-us.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ All global options can be placed at the command level.
2525

2626
- `--help`, `-h`: Show help text and exit. Optional.
2727
- `--version`, `-v`: Show version and exit. Optional. (example: `Gitea version 1.1.0+218-g7b907ed built with: bindata, sqlite`).
28-
- `--custom-path path`, `-C path`: Location of the Gitea custom folder. Optional. (default: $PWD/custom).
29-
- `--config path`, `-c path`: Gitea configuration file path. Optional. (default: custom/conf/app.ini).
28+
- `--custom-path path`, `-C path`: Location of the Gitea custom folder. Optional. (default: `AppWorkPath`/custom or `$GITEA_CUSTOM`).
29+
- `--config path`, `-c path`: Gitea configuration file path. Optional. (default: `custom`/conf/app.ini).
30+
- `--work-path path`, `-w path`: Gitea `AppWorkPath`. Optional. (default: LOCATION_OF_GITEA_BINARY or `$GITEA_WORK_DIR`)
31+
32+
NB: The defaults custom-path, config and work-path can also be
33+
changed at build time (if preferred).
3034

3135
### Commands
3236

integrations/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func initIntegrationTest() {
118118
setting.CustomConf = giteaConf
119119
}
120120

121-
setting.SetCustomPathAndConf("", "")
121+
setting.SetCustomPathAndConf("", "", "")
122122
setting.NewContext()
123123
setting.CheckLFSVersion()
124124
models.LoadConfigs()

main.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ arguments - which can alternatively be run by running the subcommand web.`
6868
// Now adjust these commands to add our global configuration options
6969

7070
// First calculate the default paths and set the AppHelpTemplates in this context
71-
setting.SetCustomPathAndConf("", "")
71+
setting.SetCustomPathAndConf("", "", "")
7272
setAppHelpTemplates()
7373

7474
// default configuration flags
@@ -84,6 +84,11 @@ arguments - which can alternatively be run by running the subcommand web.`
8484
Usage: "Custom configuration file path",
8585
},
8686
cli.VersionFlag,
87+
cli.StringFlag{
88+
Name: "work-path, w",
89+
Value: setting.AppWorkPath,
90+
Usage: "Set the gitea working path",
91+
},
8792
}
8893

8994
// Set the default to be equivalent to cmdWeb and add the default flags
@@ -114,10 +119,11 @@ func setFlagsAndBeforeOnSubcommands(command *cli.Command, defaultFlags []cli.Fla
114119
func establishCustomPath(ctx *cli.Context) error {
115120
var providedCustom string
116121
var providedConf string
122+
var providedWorkPath string
117123

118124
currentCtx := ctx
119125
for {
120-
if len(providedCustom) != 0 && len(providedConf) != 0 {
126+
if len(providedCustom) != 0 && len(providedConf) != 0 && len(providedWorkPath) != 0 {
121127
break
122128
}
123129
if currentCtx == nil {
@@ -129,10 +135,13 @@ func establishCustomPath(ctx *cli.Context) error {
129135
if currentCtx.IsSet("config") && len(providedConf) == 0 {
130136
providedConf = currentCtx.String("config")
131137
}
138+
if currentCtx.IsSet("work-path") && len(providedWorkPath) == 0 {
139+
providedWorkPath = currentCtx.String("work-path")
140+
}
132141
currentCtx = currentCtx.Parent()
133142

134143
}
135-
setting.SetCustomPathAndConf(providedCustom, providedConf)
144+
setting.SetCustomPathAndConf(providedCustom, providedConf, providedWorkPath)
136145

137146
setAppHelpTemplates()
138147

models/ssh_key_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func init() {
17-
setting.SetCustomPathAndConf("", "")
17+
setting.SetCustomPathAndConf("", "", "")
1818
setting.NewContext()
1919
}
2020

modules/setting/setting.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,10 @@ func CheckLFSVersion() {
479479
// SetCustomPathAndConf will set CustomPath and CustomConf with reference to the
480480
// GITEA_CUSTOM environment variable and with provided overrides before stepping
481481
// back to the default
482-
func SetCustomPathAndConf(providedCustom, providedConf string) {
482+
func SetCustomPathAndConf(providedCustom, providedConf, providedWorkPath string) {
483+
if len(providedWorkPath) != 0 {
484+
AppWorkPath = filepath.ToSlash(providedWorkPath)
485+
}
483486
if giteaCustom, ok := os.LookupEnv("GITEA_CUSTOM"); ok {
484487
CustomPath = giteaCustom
485488
}

0 commit comments

Comments
 (0)