Naming, layout and comments: descriptive full-word names, one item per line in wrapped calls and literals, and doc comments on exported names

Short and single-letter names in application code become full words (tests
keep theirs). Wrapped calls, signatures and composite literals put one item
per line, and one-line function bodies are expanded. Exported names and
groups of constants get doc comments, and comments refer to the renamed
identifiers.
This commit is contained in:
bwilliams committed 2026-10-15 16:12:56 +01:00
1 parent 043e307663
commit 465358609a
78 files changed
+2374 -1402

No files matched your search

+37 -25
View File
@@ -22,51 +22,63 @@ import (
// 1 applied 2026-10-07 10:12:01 00001_create_opportunities_table.sql
// ...
// 5 pending 00005_create_opportunity_classifications_table.sql
func printStatus(ctx context.Context, w io.Writer, m *goose.Provider) error {
statuses, err := m.Status(ctx)
func printStatus(ctx context.Context, out io.Writer, migrator *goose.Provider) error {
statuses, err := migrator.Status(ctx)
if err != nil {
return err
}
current, err := m.GetDBVersion(ctx)
current, err := migrator.GetDBVersion(ctx)
if err != nil {
return err
}
latest := store.LatestVersion(m)
latest := store.LatestVersion(migrator)
pending := 0
for _, s := range statuses {
if s.State == goose.StatePending {
for _, status := range statuses {
if status.State == goose.StatePending {
pending++
}
}
ew := &errWriter{w: w}
output := &errWriter{
w: out,
}
switch {
case current > latest:
ew.printf("Database version %d is newer than this build (latest %d)\n",
current, latest)
output.printf(
"Database version %d is newer than this build (latest %d)\n",
current,
latest,
)
case pending == 0:
ew.printf("Database version %d of %d (up-to-date)\n", current, latest)
output.printf("Database version %d of %d (up-to-date)\n", current, latest)
default:
ew.printf("Database version %d of %d (%d pending)\n", current, latest, pending)
output.printf("Database version %d of %d (%d pending)\n", current, latest, pending)
}
if ew.err != nil {
return ew.err
if output.err != nil {
return output.err
}
tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
ew = &errWriter{w: tw}
for _, s := range statuses {
applied := ""
if s.State == goose.StateApplied {
applied = s.AppliedAt.Local().Format("2006-01-02 15:04:05")
}
ew.printf(" %d\t%s\t%s\t%s\n",
s.Source.Version, s.State, applied, filepath.Base(s.Source.Path))
table := tabwriter.NewWriter(out, 0, 0, 2, ' ', 0)
output = &errWriter{
w: table,
}
return errors.Join(ew.err, tw.Flush())
for _, status := range statuses {
applied := ""
if status.State == goose.StateApplied {
applied = status.AppliedAt.Local().Format("2006-01-02 15:04:05")
}
output.printf(
" %d\t%s\t%s\t%s\n",
status.Source.Version,
status.State,
applied,
filepath.Base(status.Source.Path),
)
}
return errors.Join(output.err, table.Flush())
}
func commandStatus(opts *cli.Options) *cobra.Command {
@@ -83,13 +95,13 @@ func commandStatus(opts *cli.Options) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) (err error) {
slog.Debug("command run", "command", "migrate.status")
m, db, err := openMigrator(cmd, opts, false, false)
migrator, db, err := openMigrator(cmd, opts, false, false)
if err != nil {
return err
}
defer closeDB(db, &err)
return printStatus(cmd.Context(), cmd.OutOrStdout(), m)
return printStatus(cmd.Context(), cmd.OutOrStdout(), migrator)
},
}
}