mirror of
https://github.com/restic/restic.git
synced 2026-08-30 17:27:15 +00:00
init: cleanup json print code
This commit is contained in:
+8
-18
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
@@ -51,12 +50,6 @@ func init() {
|
||||
}
|
||||
|
||||
func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, args []string) error {
|
||||
type JSONSuccess struct {
|
||||
Status string `json:"status"`
|
||||
ID string `json:"id"`
|
||||
Repository string `json:"repository"`
|
||||
}
|
||||
|
||||
var version uint
|
||||
if opts.RepositoryVersion == "latest" || opts.RepositoryVersion == "" {
|
||||
version = restic.MaxRepoVersion
|
||||
@@ -116,26 +109,17 @@ func runInit(ctx context.Context, opts InitOptions, gopts GlobalOptions, args []
|
||||
Verbosef("irrecoverably lost.\n")
|
||||
|
||||
} else {
|
||||
status := JSONSuccess{
|
||||
status := initSuccess{
|
||||
Status: "success",
|
||||
ID: s.Config().ID,
|
||||
Repository: location.StripPassword(gopts.Repo),
|
||||
}
|
||||
Verbosef(toJSONString(status))
|
||||
return json.NewEncoder(gopts.stdout).Encode(status)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func toJSONString(status interface{}) string {
|
||||
buf := new(bytes.Buffer)
|
||||
err := json.NewEncoder(buf).Encode(status)
|
||||
if err != nil {
|
||||
panic("ERROR: Could not encode JSON string")
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func maybeReadChunkerPolynomial(ctx context.Context, opts InitOptions, gopts GlobalOptions) (*chunker.Pol, error) {
|
||||
if opts.CopyChunkerParameters {
|
||||
otherGopts, _, err := fillSecondaryGlobalOpts(opts.secondaryRepoOptions, gopts, "secondary")
|
||||
@@ -157,3 +141,9 @@ func maybeReadChunkerPolynomial(ctx context.Context, opts InitOptions, gopts Glo
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type initSuccess struct {
|
||||
Status string `json:"status"` // "success"
|
||||
ID string `json:"id"`
|
||||
Repository string `json:"repository"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user