-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checks if LICENSE exists. #1605
Conversation
@@ -41,6 +41,7 @@ type License struct { | |||
func init() { | |||
// Allows a user to not use a license. | |||
Licenses["none"] = License{"None", []string{"none", "false"}, "", ""} | |||
Licenses["empty"] = License{"Empty", []string{"empty", "blank"}, "", ""} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New License type. Also set as the default type.
None License type used to omit License creation.
// If user didn't set any license, use none by default | ||
return Licenses["none"] | ||
// If user didn't set any license, use empty by default | ||
return Licenses["empty"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed Default License type.
if info.IsDir() && filepath.Ext(path) != ".txt" && filepath.Ext(path) != ".md" && filepath.Ext(path) != "" { | ||
return nil | ||
} | ||
reg := regexp.MustCompile(`(?i).*license\.?.*`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used Regex to find License in the project directory.
Regex: Should contain the word license and should not have an extension / should be a .txt
or .md
for _, license := range licensesExist { | ||
fmt.Printf(" %s\n", license) | ||
} | ||
fmt.Print("Would you like still to add a license? [Y/n] ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ask user to add a LICENSE if one exists.
} | ||
} | ||
if licenseFound { | ||
fmt.Print("LICENSE exists. Would you like to overwrite it? [Y/n] ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ask user to overwrite the LICENSE file if exists.
@@ -50,7 +50,7 @@ func init() { | |||
cobra.CheckErr(viper.BindPFlag("author", rootCmd.PersistentFlags().Lookup("author"))) | |||
cobra.CheckErr(viper.BindPFlag("useViper", rootCmd.PersistentFlags().Lookup("viper"))) | |||
viper.SetDefault("author", "NAME HERE <EMAIL ADDRESS>") | |||
viper.SetDefault("license", "none") | |||
viper.SetDefault("license", "empty") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default License changed.
Just peeked over it this evening and looks good. I'm going to build locally and try it out tomorrow. I think all the CLI bits just got extracted to https://github.com/spf13/cobra-cli though; so let's move the PR over to there. You can tag me in the PR and I'll be sure to review it officially there too. Leaving this open for the moment though; once the other one gets up we can close this. |
Have created a PR in the cobra-cli repository: PR spf13/cobra#4 |
Thanks @harjyotbagga! So let's close this one. |
Signed off by: Harjyot Bagga [email protected]
PR to resolve Issue spf13/cobra-cli#39
LICENSE["empty"]
instead ofLICENSE["none"]
LICENSE["none"]
would be used if a user is unwilling to create a license.Commands:
To create a project with no LICENSE:
cobra init proj-name -l none
In case of existing LICENSE:
Post Checks: