Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add work path CLI option #6922

Merged
merged 8 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/pr/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 6 additions & 2 deletions docs/content/doc/usage/command-line.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion integrations/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func initIntegrationTest() {
setting.CustomConf = giteaConf
}

setting.SetCustomPathAndConf("", "")
setting.SetCustomPathAndConf("", "", "")
setting.NewContext()
setting.CheckLFSVersion()
models.LoadConfigs()
Expand Down
15 changes: 12 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion models/ssh_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func init() {
setting.SetCustomPathAndConf("", "")
setting.SetCustomPathAndConf("", "", "")
setting.NewContext()
}

Expand Down
5 changes: 4 additions & 1 deletion modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down