style: add blank lines between declarations and statement blocks
Separate top-level declarations and multi-line statements with blank lines, keeping an "if err != nil" check next to the statement it belongs to. Expand semicolon one-liners, group the nativeTransport fields by purpose, and format the cgo preamble as readable C. Apart from the expanded one-liners and the C preamble, the change is whitespace only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ec0297fd23
commit
a6fda8f8d3
25 files changed
+929
-41
No files matched your search
@@ -46,21 +46,26 @@ func run(ctx context.Context, args []string, out, log io.Writer) error {
|
||||
if len(args) == 0 {
|
||||
return errors.New(usage)
|
||||
}
|
||||
|
||||
if args[0] == "help" || args[0] == "--help" || args[0] == "-h" {
|
||||
fmt.Fprintln(out, usage)
|
||||
return nil
|
||||
}
|
||||
|
||||
if args[0] == "doctor" {
|
||||
if len(args) != 1 {
|
||||
return errors.New(usage)
|
||||
}
|
||||
|
||||
return doctor(ctx, out, log)
|
||||
}
|
||||
|
||||
switch args[0] {
|
||||
case "inspect", "sync", "finalize", "status":
|
||||
default:
|
||||
return errors.New(usage)
|
||||
}
|
||||
|
||||
flags := flag.NewFlagSet(args[0], flag.ContinueOnError)
|
||||
flags.SetOutput(log)
|
||||
configPath := flags.String("config", "", "JSON migration configuration")
|
||||
@@ -70,62 +75,79 @@ func run(ctx context.Context, args []string, out, log io.Writer) error {
|
||||
if errors.Is(err, flag.ErrHelp) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
if flags.NArg() != 0 {
|
||||
return errors.New("unexpected positional arguments")
|
||||
}
|
||||
|
||||
if args[0] == "status" {
|
||||
if *statePath == "" {
|
||||
return errors.New("--state is required")
|
||||
}
|
||||
|
||||
s, err := migration.LoadState(*statePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return json.NewEncoder(out).Encode(s)
|
||||
}
|
||||
|
||||
if *configPath == "" {
|
||||
return errors.New("--config is required")
|
||||
}
|
||||
|
||||
c, err := migration.ReadConfig(*configPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
process := migration.Process{Stderr: log}
|
||||
if args[0] != "inspect" && *statePath == "" {
|
||||
return errors.New("--state is required")
|
||||
}
|
||||
|
||||
if args[0] == "finalize" && !*stopped {
|
||||
return errors.New("finalize requires --writers-stopped; stop and flush all application writers first")
|
||||
}
|
||||
|
||||
if args[0] != "finalize" && *stopped {
|
||||
return errors.New("--writers-stopped is only valid with finalize")
|
||||
}
|
||||
|
||||
if c.Backend != "native" && args[0] != "inspect" {
|
||||
if _, err = exec.LookPath("rsync"); err != nil {
|
||||
return fmt.Errorf("rsync is required: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
engine, closeEngine, err := migration.NewEngine(ctx, c, process, log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer closeEngine.Close()
|
||||
if args[0] == "inspect" {
|
||||
info, err := engine.Inspect(ctx, c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return json.NewEncoder(out).Encode(info)
|
||||
}
|
||||
|
||||
if err = engine.Sync(ctx, c, *statePath, args[0] == "finalize"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s, err := migration.LoadState(*statePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return json.NewEncoder(out).Encode(s)
|
||||
}
|
||||
|
||||
@@ -138,6 +160,7 @@ func doctor(ctx context.Context, out, log io.Writer) error {
|
||||
{"docker", []string{"compose", "version"}},
|
||||
{"docker", []string{"info", "--format", "Docker server: {{.ServerVersion}}"}},
|
||||
}
|
||||
|
||||
for _, check := range checks {
|
||||
checkCtx, cancel := context.WithTimeout(ctx, 15*time.Second)
|
||||
cmd := exec.CommandContext(checkCtx, check.name, check.args...)
|
||||
@@ -148,5 +171,6 @@ func doctor(ctx context.Context, out, log io.Writer) error {
|
||||
return fmt.Errorf("check %s: %w", check.name, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -14,14 +14,17 @@ func TestCLIRejectsFinalizationWithoutWriterStop(t *testing.T) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCLIUsage(t *testing.T) {
|
||||
var out, log bytes.Buffer
|
||||
if err := run(context.Background(), []string{"--help"}, &out, &log); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !strings.Contains(out.String(), "finalize") {
|
||||
t.Fatal("help missing")
|
||||
}
|
||||
|
||||
for _, args := range [][]string{nil, {"unknown"}, {"sync"}, {"status"}, {"sync", "--config", "x", "extra"}} {
|
||||
if err := run(context.Background(), args, &out, &log); err == nil {
|
||||
t.Fatalf("accepted %v", args)
|
||||
|
||||
@@ -35,29 +35,36 @@ func run(out io.Writer, config, root, rel, from, to string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var c struct{ Source storage.Options }
|
||||
if err = json.Unmarshal(data, &c); err != nil {
|
||||
return fmt.Errorf("config: %w", err)
|
||||
}
|
||||
|
||||
fs, err := cephfsnative.Open(c.Source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer fs.Close()
|
||||
n, err := fs.Stat(root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = json.NewEncoder(out).Encode(n); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if from == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
d, err := fs.SnapDiff(root, rel, from, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer d.Close()
|
||||
for {
|
||||
name, err := d.Next()
|
||||
@@ -67,6 +74,7 @@ func run(out io.Writer, config, root, rel, from, to string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(out, "diff: %q\n", name)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user