File tree Expand file tree Collapse file tree 3 files changed +47
-2
lines changed Expand file tree Collapse file tree 3 files changed +47
-2
lines changed Original file line number Diff line number Diff line change 25
25
Thumbs.db
26
26
27
27
.conventionalcommits /
28
- .okgit /
29
28
dist /
30
29
bin /
30
+ .okgit /
Original file line number Diff line number Diff line change
1
+ package cmd
2
+
3
+ import (
4
+ "io/ioutil"
5
+ "path/filepath"
6
+ "strings"
7
+
8
+ "github.com/rajnandan1/okgit/utils"
9
+ "github.com/spf13/cobra"
10
+ )
11
+
12
+ var initCmd = & cobra.Command {
13
+ Use : "init" ,
14
+ Short : "Add .okgit/ to the .gitignore file" ,
15
+ Run : func (cmd * cobra.Command , args []string ) {
16
+ gitignorePath := filepath .Join ("." , ".gitignore" )
17
+ okgitPath := ".okgit/"
18
+
19
+ // Read the contents of the .gitignore file
20
+ data , err := ioutil .ReadFile (gitignorePath )
21
+ if err != nil {
22
+ utils .LogFatal (err )
23
+ }
24
+
25
+ // Append .okgit/ to the .gitignore file if it's not already present
26
+ contents := string (data )
27
+ if ! strings .Contains (contents , okgitPath ) {
28
+ contents += okgitPath + "\n "
29
+
30
+ // Write the updated contents back to the .gitignore file
31
+ err = ioutil .WriteFile (gitignorePath , []byte (contents ), 0644 )
32
+ if err != nil {
33
+ utils .LogFatal (err )
34
+ }
35
+
36
+ utils .LogOutput (".okgit/ added to .gitignore file" )
37
+ } else {
38
+ utils .LogOutput (".okgit/ already present in .gitignore file" )
39
+ }
40
+ },
41
+ }
42
+
43
+ func init () {
44
+ rootCmd .AddCommand (initCmd )
45
+ }
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ var rootCmd = &cobra.Command{
17
17
// Uncomment the following line if your bare application
18
18
// has an action associated with it:
19
19
// Run: func(cmd *cobra.Command, args []string) { },
20
- Version : "1.0.9 " ,
20
+ Version : "1.0.10 " ,
21
21
}
22
22
23
23
// Execute adds all child commands to the root command and sets flags appropriately.
You can’t perform that action at this time.
0 commit comments