cmd/syncthing: Don't fail early on api setup error (fixes 7558) (#7591)

* cmd/syncthing: Don't fail early on api setup error (fixes 7558)

* switch to factory pattern

* refactor config command to show help on nothing

* wip

* wip

* already abort in before
This commit is contained in:
Simon Frei
2021-04-25 20:48:17 +01:00
committed by GitHub
parent 54e27f551d
commit ef4b8a2cf8
6 changed files with 185 additions and 103 deletions
+18 -5
View File
@@ -32,15 +32,21 @@ func responseToBArray(response *http.Response) ([]byte, error) {
func emptyPost(url string) cli.ActionFunc {
return func(c *cli.Context) error {
client := c.App.Metadata["client"].(*APIClient)
_, err := client.Post(url, "")
client, err := getClientFactory(c).getClient()
if err != nil {
return err
}
_, err = client.Post(url, "")
return err
}
}
func indexDumpOutput(url string) cli.ActionFunc {
return func(c *cli.Context) error {
client := c.App.Metadata["client"].(*APIClient)
client, err := getClientFactory(c).getClient()
if err != nil {
return err
}
response, err := client.Get(url)
if err != nil {
return err
@@ -51,7 +57,10 @@ func indexDumpOutput(url string) cli.ActionFunc {
func saveToFile(url string) cli.ActionFunc {
return func(c *cli.Context) error {
client := c.App.Metadata["client"].(*APIClient)
client, err := getClientFactory(c).getClient()
if err != nil {
return err
}
response, err := client.Get(url)
if err != nil {
return err
@@ -82,7 +91,7 @@ func saveToFile(url string) cli.ActionFunc {
}
}
func getConfig(c *APIClient) (config.Configuration, error) {
func getConfig(c APIClient) (config.Configuration, error) {
cfg := config.Configuration{}
response, err := c.Get("system/config")
if err != nil {
@@ -147,3 +156,7 @@ func nulString(bs []byte) string {
func normalizePath(path string) string {
return filepath.ToSlash(filepath.Clean(path))
}
func getClientFactory(c *cli.Context) *apiClientFactory {
return c.App.Metadata["clientFactory"].(*apiClientFactory)
}