summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-05-14 16:20:35 +0100
committertechknowlogick <techknowlogick@gitea.io>2019-05-14 11:20:35 -0400
commite55c874dd2a6162a374a9fac46c55db57bd17c5f (patch)
tree0af648181cfc9c59aededfe0b56de21e79baf1dc
parent488d34691ad79bae13320f3e831a7ff46c245a89 (diff)
downloadgitea-e55c874dd2a6162a374a9fac46c55db57bd17c5f.tar.gz
gitea-e55c874dd2a6162a374a9fac46c55db57bd17c5f.zip
Add work path CLI option (#6922)
Makes it possible to set the work path as a CLI option instead of relying on environment variables which are somewhat opaque
-rw-r--r--contrib/pr/checkout.go2
-rw-r--r--docs/content/doc/usage/command-line.en-us.md8
-rw-r--r--integrations/integration_test.go2
-rw-r--r--main.go15
-rw-r--r--models/ssh_key_test.go2
-rw-r--r--modules/setting/setting.go5
6 files changed, 25 insertions, 9 deletions
diff --git a/contrib/pr/checkout.go b/contrib/pr/checkout.go
index 607a503189..7af27c2a9e 100644
--- a/contrib/pr/checkout.go
+++ b/contrib/pr/checkout.go
@@ -43,7 +43,7 @@ func runPR() {
if err != nil {
log.Fatal(err)
}
- setting.SetCustomPathAndConf("", "")
+ setting.SetCustomPathAndConf("", "", "")
setting.NewContext()
setting.RepoRootPath, err = ioutil.TempDir(os.TempDir(), "repos")
diff --git a/docs/content/doc/usage/command-line.en-us.md b/docs/content/doc/usage/command-line.en-us.md
index 9959ac30ab..ab52109e93 100644
--- a/docs/content/doc/usage/command-line.en-us.md
+++ b/docs/content/doc/usage/command-line.en-us.md
@@ -25,8 +25,12 @@ All global options can be placed at the command level.
- `--help`, `-h`: Show help text and exit. Optional.
- `--version`, `-v`: Show version and exit. Optional. (example: `Gitea version 1.1.0+218-g7b907ed built with: bindata, sqlite`).
-- `--custom-path path`, `-C path`: Location of the Gitea custom folder. Optional. (default: $PWD/custom).
-- `--config path`, `-c path`: Gitea configuration file path. Optional. (default: custom/conf/app.ini).
+- `--custom-path path`, `-C path`: Location of the Gitea custom folder. Optional. (default: `AppWorkPath`/custom or `$GITEA_CUSTOM`).
+- `--config path`, `-c path`: Gitea configuration file path. Optional. (default: `custom`/conf/app.ini).
+- `--work-path path`, `-w path`: Gitea `AppWorkPath`. Optional. (default: LOCATION_OF_GITEA_BINARY or `$GITEA_WORK_DIR`)
+
+NB: The defaults custom-path, config and work-path can also be
+changed at build time (if preferred).
### Commands
diff --git a/integrations/integration_test.go b/integrations/integration_test.go
index 93dacaf78a..80a42efb5c 100644
--- a/integrations/integration_test.go
+++ b/integrations/integration_test.go
@@ -118,7 +118,7 @@ func initIntegrationTest() {
setting.CustomConf = giteaConf
}
- setting.SetCustomPathAndConf("", "")
+ setting.SetCustomPathAndConf("", "", "")
setting.NewContext()
setting.CheckLFSVersion()
models.LoadConfigs()
diff --git a/main.go b/main.go
index 102450f906..4d94d00aba 100644
--- a/main.go
+++ b/main.go
@@ -68,7 +68,7 @@ arguments - which can alternatively be run by running the subcommand web.`
// Now adjust these commands to add our global configuration options
// First calculate the default paths and set the AppHelpTemplates in this context
- setting.SetCustomPathAndConf("", "")
+ setting.SetCustomPathAndConf("", "", "")
setAppHelpTemplates()
// default configuration flags
@@ -84,6 +84,11 @@ arguments - which can alternatively be run by running the subcommand web.`
Usage: "Custom configuration file path",
},
cli.VersionFlag,
+ cli.StringFlag{
+ Name: "work-path, w",
+ Value: setting.AppWorkPath,
+ Usage: "Set the gitea working path",
+ },
}
// 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
func establishCustomPath(ctx *cli.Context) error {
var providedCustom string
var providedConf string
+ var providedWorkPath string
currentCtx := ctx
for {
- if len(providedCustom) != 0 && len(providedConf) != 0 {
+ if len(providedCustom) != 0 && len(providedConf) != 0 && len(providedWorkPath) != 0 {
break
}
if currentCtx == nil {
@@ -129,10 +135,13 @@ func establishCustomPath(ctx *cli.Context) error {
if currentCtx.IsSet("config") && len(providedConf) == 0 {
providedConf = currentCtx.String("config")
}
+ if currentCtx.IsSet("work-path") && len(providedWorkPath) == 0 {
+ providedWorkPath = currentCtx.String("work-path")
+ }
currentCtx = currentCtx.Parent()
}
- setting.SetCustomPathAndConf(providedCustom, providedConf)
+ setting.SetCustomPathAndConf(providedCustom, providedConf, providedWorkPath)
setAppHelpTemplates()
diff --git a/models/ssh_key_test.go b/models/ssh_key_test.go
index f310935a32..82f5f9724b 100644
--- a/models/ssh_key_test.go
+++ b/models/ssh_key_test.go
@@ -14,7 +14,7 @@ import (
)
func init() {
- setting.SetCustomPathAndConf("", "")
+ setting.SetCustomPathAndConf("", "", "")
setting.NewContext()
}
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index d7f361c01e..461e394a62 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -479,7 +479,10 @@ func CheckLFSVersion() {
// SetCustomPathAndConf will set CustomPath and CustomConf with reference to the
// GITEA_CUSTOM environment variable and with provided overrides before stepping
// back to the default
-func SetCustomPathAndConf(providedCustom, providedConf string) {
+func SetCustomPathAndConf(providedCustom, providedConf, providedWorkPath string) {
+ if len(providedWorkPath) != 0 {
+ AppWorkPath = filepath.ToSlash(providedWorkPath)
+ }
if giteaCustom, ok := os.LookupEnv("GITEA_CUSTOM"); ok {
CustomPath = giteaCustom
}