posh/cmd/execute.go
2023-01-12 07:30:12 +01:00

35 lines
764 B
Go

package cmd
import (
intconfig "github.com/foomo/posh/internal/config"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
// execCmd represents the exec command
var execCmd = &cobra.Command{
Use: "execute",
Short: "Execute a single Project Oriented Shell command",
Args: cobra.ArbitraryArgs,
SilenceUsage: true,
SilenceErrors: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := intconfig.Load(l); err != nil {
return err
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("missing [cmd] argument")
}
plg, err := pluginProvider(l)
if err != nil {
return err
}
return plg.Execute(cmd.Context(), args)
},
}