From efba9c9f3a1ddd89559e8f2c303bf89344961b2d Mon Sep 17 00:00:00 2001 From: xliao Date: Thu, 9 Nov 2023 11:56:22 +0800 Subject: [PATCH] feat: reuse existing license if user didn't set any 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. --- cmd/project.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/project.go b/cmd/project.go index ec8980e..9890822 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -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 }