mirror of
https://github.com/syncthing/syncthing.git
synced 2026-05-11 00:26:31 -04:00
Consistently use double dashes and fix typos -conf, -data-dir and -verify. Applies also to tests running the syncthing binary for consistency. * Fix mismatched option name --conf in cli subcommand. According to the source code comments, the cli option flags should mirror those from the serve subcommand where applicable. That one is actually called --config though. * cli: Fix help text option placeholders. The urfave/cli package uses the Value field of StringFlag to provide a default value, not to name the placeholder. That is instead done with backticks around some part of the Usage field. * cli: Add missing --data flag in subcommand help text. The urfave/cli based option parsing uses a fake flags collection to generate help texts matching the used global options. But the --data option was omitted from it, although it is definitely required when using --config as well. Note that it cannot just be ignored, as some debug stuff actually uses the DB: syncthing cli --data=/bar --config=/foo debug index dump
36 lines
1014 B
Go
36 lines
1014 B
Go
// Copyright (C) 2014 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
package cmdutil
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/syncthing/syncthing/lib/locations"
|
|
)
|
|
|
|
func SetConfigDataLocationsFromFlags(homeDir, confDir, dataDir string) error {
|
|
homeSet := homeDir != ""
|
|
confSet := confDir != ""
|
|
dataSet := dataDir != ""
|
|
switch {
|
|
case dataSet != confSet:
|
|
return errors.New("either both or none of --config and --data must be given, use --home to set both at once")
|
|
case homeSet && dataSet:
|
|
return errors.New("--home must not be used together with --config and --data")
|
|
case homeSet:
|
|
confDir = homeDir
|
|
dataDir = homeDir
|
|
fallthrough
|
|
case dataSet:
|
|
if err := locations.SetBaseDir(locations.ConfigBaseDir, confDir); err != nil {
|
|
return err
|
|
}
|
|
return locations.SetBaseDir(locations.DataBaseDir, dataDir)
|
|
}
|
|
return nil
|
|
}
|