github.com/lenfree/buffalo@v0.7.3-0.20170207163156-891616ea4064/buffalo/cmd/task.go (about)

     1  package cmd
     2  
     3  import (
     4  	"errors"
     5  	"os"
     6  	"os/exec"
     7  
     8  	"github.com/spf13/cobra"
     9  )
    10  
    11  // task command is a forward to grift tasks
    12  var taskCommand = &cobra.Command{
    13  	Use:     "task",
    14  	Aliases: []string{"t"},
    15  	Short:   "Runs your grift tasks",
    16  	RunE: func(c *cobra.Command, args []string) error {
    17  		_, err := exec.LookPath("grift")
    18  		if err != nil {
    19  			return errors.New("we could not find \"grift\" in your path.\n You must first install \"grift\" in order to use the Buffalo console:\n\n $ go get github.com/markbates/grift")
    20  		}
    21  
    22  		_, err = os.Stat("grifts")
    23  		if err != nil {
    24  			return errors.New("seems there is no grift folder on your current directory, please ensure you're inside your buffalo app root")
    25  		}
    26  
    27  		cmd := exec.Command("grift", args...)
    28  		cmd.Stdin = os.Stdin
    29  		cmd.Stderr = os.Stderr
    30  		cmd.Stdout = os.Stdout
    31  
    32  		return cmd.Run()
    33  
    34  	},
    35  }
    36  
    37  func init() {
    38  	RootCmd.AddCommand(taskCommand)
    39  }