mirror of
https://github.com/kopia/kopia.git
synced 2026-01-25 06:48:48 -05:00
This is mostly mechanical and changes how loggers are instantiated. Logger is now associated with a context, passed around all methods, (most methods had ctx, but had to add it in a few missing places). By default Kopia does not produce any logs, but it can be overridden, either locally for a nested context, by calling ctx = logging.WithLogger(ctx, newLoggerFunc) To override logs globally, call logging.SetDefaultLogger(newLoggerFunc) This refactoring allowed removing dependency from Kopia repo and go-logging library (the CLI still uses it, though). It is now also possible to have all test methods emit logs using t.Logf() so that they show up in failure reports, which should make debugging of test failures suck less.
39 lines
828 B
Go
39 lines
828 B
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/kopia/kopia/internal/serverapi"
|
|
)
|
|
|
|
var (
|
|
serverStartUploadCommand = serverCommands.Command("upload", "Trigger upload for one or more sources")
|
|
)
|
|
|
|
func init() {
|
|
serverStartUploadCommand.Action(serverAction(runServerStartUpload))
|
|
}
|
|
|
|
func runServerStartUpload(ctx context.Context, cli *serverapi.Client) error {
|
|
return triggerActionOnMatchingSources(ctx, cli, "sources/upload")
|
|
}
|
|
|
|
func triggerActionOnMatchingSources(ctx context.Context, cli *serverapi.Client, path string) error {
|
|
var resp serverapi.MultipleSourceActionResponse
|
|
|
|
if err := cli.Post(ctx, path, &serverapi.Empty{}, &resp); err != nil {
|
|
return err
|
|
}
|
|
|
|
for src, resp := range resp.Sources {
|
|
if resp.Success {
|
|
fmt.Println("SUCCESS", src)
|
|
} else {
|
|
fmt.Println("FAILED", src)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|