aboutsummaryrefslogtreecommitdiffstats
path: root/internal/commands/create.go
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2024-01-13 18:23:48 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2024-01-13 18:23:48 -0500
commit00aa327eb204d504f1e03dbe5a7cdec4af4ec913 (patch)
tree571a5bc5ce52a11e0039f9763c89b9316e7bf9d4 /internal/commands/create.go
parentTweak readme (diff)
downloadcli-00aa327eb204d504f1e03dbe5a7cdec4af4ec913.zip
Rework docs, add more output, and tweak tests
Diffstat (limited to '')
-rw-r--r--internal/commands/new.go (renamed from internal/commands/create.go)42
1 files changed, 26 insertions, 16 deletions
diff --git a/internal/commands/create.go b/internal/commands/new.go
index 57f4c69..be1f49c 100644
--- a/internal/commands/create.go
+++ b/internal/commands/new.go
@@ -3,67 +3,77 @@ package commands
import (
"context"
"flag"
- "fmt"
- "os"
"time"
"github.com/eugenetriguba/bolt/internal/configloader"
"github.com/eugenetriguba/bolt/internal/models"
+ "github.com/eugenetriguba/bolt/internal/output"
"github.com/eugenetriguba/bolt/internal/repositories"
"github.com/eugenetriguba/bolt/internal/services"
"github.com/google/subcommands"
)
-type CreateCmd struct {
+type NewCmd struct {
message string
}
-func (*CreateCmd) Name() string { return "create" }
-func (*CreateCmd) Synopsis() string {
- return "Create a new database migration."
+func (*NewCmd) Name() string {
+ return "new"
}
-func (*CreateCmd) Usage() string {
- return `create [-message]:
- Create a new database migration.
+
+func (*NewCmd) Synopsis() string {
+ return "create a new database migration"
+}
+
+func (*NewCmd) Usage() string {
+ return `create [-message|-m]:
+ Create a new database migration
`
}
-func (cmd *CreateCmd) SetFlags(f *flag.FlagSet) {
+func (cmd *NewCmd) SetFlags(f *flag.FlagSet) {
f.StringVar(
&cmd.message,
"message",
"autogenerated",
"Message to use for the migration",
)
+ f.StringVar(&cmd.message, "m", cmd.message, "alias for -message")
}
-func (cmd *CreateCmd) Execute(
+func (cmd *NewCmd) Execute(
_ context.Context,
f *flag.FlagSet,
_ ...interface{},
) subcommands.ExitStatus {
+ consoleOutputter := output.ConsoleOutputter{}
+
cfg, err := configloader.NewConfig()
if err != nil {
- fmt.Fprintln(os.Stderr, err)
+ consoleOutputter.Error(err.Error())
return subcommands.ExitFailure
}
migrationFsRepo, err := repositories.NewMigrationFsRepo(cfg.MigrationsDir)
if err != nil {
- fmt.Fprintln(os.Stderr, err)
+ consoleOutputter.Error(err.Error())
return subcommands.ExitFailure
}
- migrationService := services.NewMigrationService(nil, migrationFsRepo)
+ migrationService := services.NewMigrationService(
+ nil,
+ migrationFsRepo,
+ consoleOutputter,
+ )
if err != nil {
- fmt.Fprintln(os.Stderr, err)
+ consoleOutputter.Error(err.Error())
return subcommands.ExitFailure
}
migration := models.NewMigration(time.Now(), cmd.message)
err = migrationService.CreateMigration(migration)
if err != nil {
- fmt.Fprintln(os.Stderr, err)
+ consoleOutputter.Error(err.Error())
return subcommands.ExitFailure
}