git-lfs/commands/command_init.go

55 lines
758 B
Go
Raw Normal View History

package commands
import (
"github.com/github/git-media/gitmedia"
2014-06-26 20:15:21 +00:00
"github.com/spf13/cobra"
)
2014-06-26 20:15:21 +00:00
var (
initCmd = &cobra.Command{
Use: "init",
2014-06-26 21:22:24 +00:00
Short: "Initialize the default Git Media configuration",
2014-06-26 20:15:21 +00:00
Run: initCommand,
}
)
2014-06-26 20:15:21 +00:00
func initCommand(cmd *cobra.Command, args []string) {
var sub string
2014-06-26 20:15:21 +00:00
if len(args) > 0 {
sub = args[0]
}
switch sub {
case "hooks":
2014-06-26 20:15:21 +00:00
hookInit()
default:
2014-06-26 20:15:21 +00:00
runInit()
}
Print("git media initialized")
}
2014-06-26 20:15:21 +00:00
func runInit() {
globalInit()
2014-06-03 21:05:58 +00:00
if gitmedia.InRepo() {
2014-06-26 20:15:21 +00:00
hookInit()
}
}
2014-06-26 20:15:21 +00:00
func globalInit() {
2014-06-05 18:48:23 +00:00
if err := gitmedia.InstallFilters(); err != nil {
Error(err.Error())
}
}
2014-06-26 20:15:21 +00:00
func hookInit() {
2014-06-05 18:48:23 +00:00
if err := gitmedia.InstallHooks(); err != nil {
Error(err.Error())
}
}
func init() {
2014-06-26 20:15:21 +00:00
RootCmd.AddCommand(initCmd)
}