diff --git a/internal/homesick/cli/cli.go b/internal/homesick/cli/cli.go index 701e508..4e90d75 100644 --- a/internal/homesick/cli/cli.go +++ b/internal/homesick/cli/cli.go @@ -163,7 +163,10 @@ type pushCmd struct { Castle string `arg:"" optional:"" name:"CASTLE" help:"Castle name."` } -type commitCmd struct{} +type commitCmd struct { + Message string `short:"m" required:"" name:"MESSAGE" help:"Commit message."` + Castle string `arg:"" optional:"" name:"CASTLE" help:"Castle name."` +} type destroyCmd struct{} @@ -183,14 +186,16 @@ type generateCmd struct{} func (c *pullCmd) Run(app *core.App) error { return app.Pull(defaultCastle(c.Castle)) } func (c *pushCmd) Run(app *core.App) error { return app.Push(defaultCastle(c.Castle)) } -func (c *commitCmd) Run() error { return notImplemented("commit") } -func (c *destroyCmd) Run() error { return notImplemented("destroy") } -func (c *cdCmd) Run() error { return notImplemented("cd") } -func (c *openCmd) Run() error { return notImplemented("open") } -func (c *execCmd) Run() error { return notImplemented("exec") } -func (c *execAllCmd) Run() error { return notImplemented("exec_all") } -func (c *rcCmd) Run(app *core.App) error { return app.Rc(defaultCastle(c.Castle)) } -func (c *generateCmd) Run() error { return notImplemented("generate") } +func (c *commitCmd) Run(app *core.App) error { + return app.Commit(defaultCastle(c.Castle), c.Message) +} +func (c *destroyCmd) Run() error { return notImplemented("destroy") } +func (c *cdCmd) Run() error { return notImplemented("cd") } +func (c *openCmd) Run() error { return notImplemented("open") } +func (c *execCmd) Run() error { return notImplemented("exec") } +func (c *execAllCmd) Run() error { return notImplemented("exec_all") } +func (c *rcCmd) Run(app *core.App) error { return app.Rc(defaultCastle(c.Castle)) } +func (c *generateCmd) Run() error { return notImplemented("generate") } func defaultCastle(castle string) string { if strings.TrimSpace(castle) == "" { diff --git a/internal/homesick/core/core.go b/internal/homesick/core/core.go index bd900f9..8b7a282 100644 --- a/internal/homesick/core/core.go +++ b/internal/homesick/core/core.go @@ -147,6 +147,24 @@ func (a *App) Push(castle string) error { return runGitWithIO(filepath.Join(a.ReposDir, castle), a.Stdout, a.Stderr, "push") } +func (a *App) Commit(castle string, message string) error { + if strings.TrimSpace(castle) == "" { + castle = "dotfiles" + } + + trimmedMessage := strings.TrimSpace(message) + if trimmedMessage == "" { + return errors.New("commit requires message") + } + + castledir := filepath.Join(a.ReposDir, castle) + if err := runGitWithIO(castledir, a.Stdout, a.Stderr, "add", "--all"); err != nil { + return err + } + + return runGitWithIO(castledir, a.Stdout, a.Stderr, "commit", "-m", trimmedMessage) +} + func (a *App) Link(castle string) error { if strings.TrimSpace(castle) == "" { castle = "dotfiles"