Skip to content

Commit 1eca368

Browse files
committed
feat: rename migrate -> boxo-migrate, add extra pointers to output
1 parent b1046dd commit 1eca368

File tree

7 files changed

+54
-7
lines changed

7 files changed

+54
-7
lines changed

cmd/boxo-migrate/boxo-migrate

5.37 MB
Binary file not shown.

cmd/migrate/migrate.go renamed to cmd/boxo-migrate/boxomigrate.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77
"strings"
88

9-
migrate "github.com/ipfs/boxo/cmd/migrate/internal"
9+
migrate "github.com/ipfs/boxo/cmd/boxo-migrate/internal"
1010
"github.com/urfave/cli/v2"
1111
)
1212

@@ -64,10 +64,31 @@ func main() {
6464
if err != nil {
6565
return err
6666
}
67+
68+
fmt.Printf("\n\n")
69+
70+
if !dryrun {
71+
err := migrator.GoGet("github.com/ipfs/[email protected]")
72+
if err != nil {
73+
return err
74+
}
75+
}
76+
6777
if err := migrator.UpdateImports(); err != nil {
6878
return err
6979
}
7080

81+
if dryrun {
82+
return nil
83+
}
84+
85+
if err := migrator.GoModTidy(); err != nil {
86+
return err
87+
}
88+
89+
fmt.Printf("Your code has been successfully updated. Note that you might still need to manually fix up parts of your code.\n\n")
90+
fmt.Printf("You should also consider running the 'boxo-migrate check-dependencies' command to see if you have any other dependencies on migrated code.\n\n")
91+
7192
return nil
7293
},
7394
},
@@ -88,7 +109,7 @@ func main() {
88109
}
89110
if len(deps) > 0 {
90111
fmt.Println(strings.Join([]string{
91-
"You still have dependencies on repos which have migrated to go-libipfs.",
112+
"You still have dependencies on repos which have migrated to Boxo.",
92113
"You should consider not having these dependencies to avoid multiple versions of the same code.",
93114
"You can use 'go mod why' or 'go mod graph' to find the reason for these dependencies.",
94115
"",

cmd/migrate/go.mod renamed to cmd/boxo-migrate/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/ipfs/boxo/cmd/migrate
1+
module github.com/ipfs/boxo/cmd/boxo-migrate
22

33
go 1.19
44

File renamed without changes.
File renamed without changes.
File renamed without changes.

cmd/migrate/internal/migrator.go renamed to cmd/boxo-migrate/internal/migrator.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ func (m *Migrator) run(cmdName string, args ...string) (int, string, string, err
106106
return state.ExitCode(), strings.TrimSpace(stdout.String()), strings.TrimSpace(stderr.String()), nil
107107
}
108108

109+
func (m *Migrator) runOrErr(cmdName string, args ...string) (string, error) {
110+
exitCode, stdout, stderr, err := m.run(cmdName, args...)
111+
if err != nil {
112+
return "", err
113+
}
114+
if exitCode != 0 {
115+
return "", fmt.Errorf("non-zero exit code %d, stderr:\n%s", exitCode, stderr)
116+
}
117+
return stdout, nil
118+
}
119+
109120
// FindMigratedDependencies returns a list of dependent module versions like 'module v0.1.0' that have been migrated to go-libipfs.
110121
func (m *Migrator) FindMigratedDependencies() ([]string, error) {
111122
var modVersions []string
@@ -129,13 +140,10 @@ func (m *Migrator) FindMigratedDependencies() ([]string, error) {
129140
}
130141

131142
func (m *Migrator) findSourceFiles() ([]string, error) {
132-
exitCode, stdout, stderr, err := m.run("go", "list", "-json", "./...")
143+
stdout, err := m.runOrErr("go", "list", "-json", "./...")
133144
if err != nil {
134145
return nil, fmt.Errorf("finding source files: %w", err)
135146
}
136-
if exitCode != 0 {
137-
return nil, fmt.Errorf("non-zero exit code %d finding source files, stderr:\n%s", exitCode, stderr)
138-
}
139147

140148
var files []string
141149
dec := json.NewDecoder(strings.NewReader(stdout))
@@ -166,3 +174,21 @@ func (m *Migrator) UpdateImports() error {
166174
}
167175
return nil
168176
}
177+
178+
func (m *Migrator) GoModTidy() error {
179+
fmt.Printf("\n\nRunning 'go mod tidy'...\n\n")
180+
_, err := m.runOrErr("go", "mod", "tidy")
181+
if err != nil {
182+
return fmt.Errorf("running 'go mod tidy': %w", err)
183+
}
184+
return nil
185+
}
186+
187+
func (m *Migrator) GoGet(mod string) error {
188+
fmt.Printf("Adding module: %q\n\n", mod)
189+
_, err := m.runOrErr("go", "get", mod)
190+
if err != nil {
191+
return fmt.Errorf("running 'go get %s': %w", mod, err)
192+
}
193+
return nil
194+
}

0 commit comments

Comments
 (0)