Skip to content

Commit

Permalink
feat: reuse existing license if user didn't set any
Browse files Browse the repository at this point in the history
GitHub now supports creating files like LICENSE for newly created repos.
Running `cobra-cli init` after cloning a newly created repo will now
empty that existing license.
  • Loading branch information
suzaku committed Nov 9, 2023
1 parent 1d43487 commit 4b53e45
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,17 @@ func (p *Project) createLicenseFile() error {
data := map[string]interface{}{
"copyright": copyrightLine(),
}
licenseFile, err := os.Create(fmt.Sprintf("%s/LICENSE", p.AbsolutePath))

licensePath := p.AbsolutePath + "/LICENSE"

if p.Legal.Name == "none" {
// If user didn't set any license and an existing license file is found, use that.
if _, err := os.Stat(licensePath); err == nil {
return nil
}
}

licenseFile, err := os.Create(licensePath)
if err != nil {
return err
}
Expand Down

0 comments on commit 4b53e45

Please sign in to comment.