diff --git a/.gitignore b/.gitignore index 35a6362..5b5b6e9 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,6 @@ Thumbs.db .conventionalcommits/ -.okgit/ dist/ bin/ +.okgit/ diff --git a/cmd/init.go b/cmd/init.go new file mode 100644 index 0000000..998f8e3 --- /dev/null +++ b/cmd/init.go @@ -0,0 +1,45 @@ +package cmd + +import ( + "io/ioutil" + "path/filepath" + "strings" + + "github.com/rajnandan1/okgit/utils" + "github.com/spf13/cobra" +) + +var initCmd = &cobra.Command{ + Use: "init", + Short: "Add .okgit/ to the .gitignore file", + Run: func(cmd *cobra.Command, args []string) { + gitignorePath := filepath.Join(".", ".gitignore") + okgitPath := ".okgit/" + + // Read the contents of the .gitignore file + data, err := ioutil.ReadFile(gitignorePath) + if err != nil { + utils.LogFatal(err) + } + + // Append .okgit/ to the .gitignore file if it's not already present + contents := string(data) + if !strings.Contains(contents, okgitPath) { + contents += okgitPath + "\n" + + // Write the updated contents back to the .gitignore file + err = ioutil.WriteFile(gitignorePath, []byte(contents), 0644) + if err != nil { + utils.LogFatal(err) + } + + utils.LogOutput(".okgit/ added to .gitignore file") + } else { + utils.LogOutput(".okgit/ already present in .gitignore file") + } + }, +} + +func init() { + rootCmd.AddCommand(initCmd) +} diff --git a/cmd/root.go b/cmd/root.go index 0853f70..cee4efd 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,7 +17,7 @@ var rootCmd = &cobra.Command{ // Uncomment the following line if your bare application // has an action associated with it: // Run: func(cmd *cobra.Command, args []string) { }, - Version: "1.0.9", + Version: "1.0.10", } // Execute adds all child commands to the root command and sets flags appropriately.