I am building a cli app in GoLang . I am using cobra for doing that and I have the following code for that:
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// pullCmd represents the pull command
var pullCmd = &cobra.Command{
Use: "pull",
Short: "Take pull from repo",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("pull called")
},
}
func init() {
rootCmd.AddCommand(pullCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// pullCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// pullCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
I want the pull
command to run git pull
command internally whenever I run my pull command. How can I do that ? I am new to GoLang & Cobra library.
Thanks