Documentation ¶
Index ¶
Constants ¶
View Source
const REMOVE_GITIGNORE_REPO_URL = "https://github.com/github/gitignore.git"
Variables ¶
View Source
var RootCmd = &cobra.Command{ Use: "git-ignore", Short: "Setup .gitignore file", Run: func(cmd *cobra.Command, args []string) { if listLangs == true { var localGitignoreRepoPath = getGitIgnoreRepoPath() cloneGitIgnoreRepoIfNecessary(localGitignoreRepoPath) langs := getGitIgnoreLangs(localGitignoreRepoPath) for _, lang := range langs { fmt.Println(strings.ToLower(lang)) } } else if language != "" { var localGitignoreRepoPath = getGitIgnoreRepoPath() cloneGitIgnoreRepoIfNecessary(localGitignoreRepoPath) langs := getGitIgnoreLangs(localGitignoreRepoPath) for _, lang := range langs { if strings.ToLower(lang) == strings.ToLower(language) { templateFilePath := fmt.Sprintf("%s/%s.gitignore", localGitignoreRepoPath, lang) cwd, err := os.Getwd() if err != nil { os.Stderr.WriteString(fmt.Sprintf("Cannot get CWD: %s", err)) } gitIgnoreFilePath := cwd + "/.gitignore" templateFileBody, err := ioutil.ReadFile(templateFilePath) if err != nil { os.Stderr.WriteString(fmt.Sprintf("Cannot read file %s: %s", templateFilePath, err)) return } mode := os.O_WRONLY | os.O_CREATE if shouldAppend == true { mode = mode | os.O_APPEND } f, err := os.OpenFile(gitIgnoreFilePath, mode, 0644) defer f.Close() if err != nil { os.Stderr.WriteString(fmt.Sprintf("Cannot open file %s for writing: %s", gitIgnoreFilePath, err)) return } if _, err := f.Write(templateFileBody); err != nil { os.Stderr.WriteString(fmt.Sprintf("Error while writing %s: %s", gitIgnoreFilePath, err)) return } return } } os.Stderr.WriteString(fmt.Sprintf("No template for %s", language)) } else { os.Stderr.WriteString("No action provided.\nPlease see git ignore -h for help\n") } }, }
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.