feat(cli): implement exec and exec_all commands
This commit is contained in:
@@ -180,9 +180,14 @@ type openCmd struct {
|
||||
Castle string `arg:"" optional:"" name:"CASTLE" help:"Castle name."`
|
||||
}
|
||||
|
||||
type execCmd struct{}
|
||||
type execCmd struct {
|
||||
Castle string `arg:"" name:"CASTLE" help:"Castle name."`
|
||||
Command []string `arg:"" name:"COMMAND" help:"Shell command to execute in the castle root."`
|
||||
}
|
||||
|
||||
type execAllCmd struct{}
|
||||
type execAllCmd struct {
|
||||
Command []string `arg:"" name:"COMMAND" help:"Shell command to execute in each castle root."`
|
||||
}
|
||||
|
||||
type rcCmd struct {
|
||||
Castle string `arg:"" optional:"" name:"CASTLE" help:"Castle name."`
|
||||
@@ -200,8 +205,8 @@ func (c *commitCmd) Run(app *core.App) error {
|
||||
func (c *destroyCmd) Run(app *core.App) error { return app.Destroy(defaultCastle(c.Castle)) }
|
||||
func (c *cdCmd) Run(app *core.App) error { return app.ShowPath(defaultCastle(c.Castle)) }
|
||||
func (c *openCmd) Run(app *core.App) error { return app.Open(defaultCastle(c.Castle)) }
|
||||
func (c *execCmd) Run() error { return notImplemented("exec") }
|
||||
func (c *execAllCmd) Run() error { return notImplemented("exec_all") }
|
||||
func (c *execCmd) Run(app *core.App) error { return app.Exec(c.Castle, c.Command) }
|
||||
func (c *execAllCmd) Run(app *core.App) error { return app.ExecAll(c.Command) }
|
||||
func (c *rcCmd) Run(app *core.App) error { return app.Rc(defaultCastle(c.Castle)) }
|
||||
func (c *generateCmd) Run(app *core.App) error { return app.Generate(c.Path) }
|
||||
|
||||
|
||||
@@ -68,6 +68,17 @@ func (s *CLISuite) TestRun_Cd_ExplicitCastle() {
|
||||
require.Empty(s.T(), s.stderr.String())
|
||||
}
|
||||
|
||||
func (s *CLISuite) TestRun_Exec_RunsCommandInCastleRoot() {
|
||||
castleRoot := filepath.Join(s.homeDir, ".homesick", "repos", "dotfiles")
|
||||
require.NoError(s.T(), os.MkdirAll(castleRoot, 0o755))
|
||||
|
||||
exitCode := cli.Run([]string{"exec", "dotfiles", "pwd"}, s.stdout, s.stderr)
|
||||
|
||||
require.Equal(s.T(), 0, exitCode)
|
||||
require.Contains(s.T(), s.stdout.String(), castleRoot)
|
||||
require.Empty(s.T(), s.stderr.String())
|
||||
}
|
||||
|
||||
func (s *CLISuite) TestRun_CloneSubcommandHelp() {
|
||||
exitCode := cli.Run([]string{"clone", "--help"}, s.stdout, s.stderr)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user