-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.go
55 lines (44 loc) · 1.25 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"os"
"github.com/coderjojo/gogit/internal/repository"
"github.com/spf13/cobra"
)
// initCmd represents the init command
var initCmd = &cobra.Command{
Use: "init",
Short: "Initialize a new, empty repository",
Long: `Initialize a new, emptry respository by default at current
working directory
Specify the path to Initialize at different location
gogit init path`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var path string
if len(args) > 0 {
path = args[0]
} else {
path, _ = os.Getwd()
}
repo, err := repository.RepoCreate(path)
if err != nil {
fmt.Println("Error Creating Repository: ", err)
return
}
fmt.Printf("Initializing Repository at %s\n", repo.GitDir)
},
}
func init() {
rootCmd.AddCommand(initCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// initCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// initCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}