From 4b53e45de43b7a296c67c3834fa5808cc8e2a0cf 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..4efbccc 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 }