Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

harjyotbagga
Copy link

Signed off by: Harjyot Bagga [email protected]

PR to resolve Issue spf13/cobra-cli#39

  • Checks if a LICENSE exists in the Project Directory, if so it lists and asks the user if they want to still add another LICENSE.
  • If LICENSE exists, confirms if the user wishes to over-write the existing LICENSE.
  • Changed default LICENSE to be LICENSE["empty"] instead of LICENSE["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:
image

Post Checks:

  • Built Successfully
  • All tests passed successfully

@CLAassistant
Copy link

CLAassistant commented Feb 19, 2022

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the area/cli [deprecated] For the cobra CLI !!! moved to spf13/cobra-cli label Feb 19, 2022
@@ -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"}, "", ""}
Copy link
Author

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"]
Copy link
Author

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\.?.*`)
Copy link
Author

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] ")
Copy link
Author

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] ")
Copy link
Author

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")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default License changed.

@johnSchnake
Copy link
Collaborator

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.

@johnSchnake johnSchnake self-assigned this Feb 21, 2022
@harjyotbagga
Copy link
Author

Have created a PR in the cobra-cli repository: PR spf13/cobra#4

@marckhouzam
Copy link
Collaborator

Have created a PR in the cobra-cli repository: PR spf13/cobra#4

Thanks @harjyotbagga! So let's close this one.

@jpmcb jpmcb added the triage/duplicate A duplicate issue. These issues are usually closed after receiving this label label Feb 24, 2022
@harjyotbagga harjyotbagga deleted the license-check branch March 1, 2022 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli [deprecated] For the cobra CLI !!! moved to spf13/cobra-cli triage/duplicate A duplicate issue. These issues are usually closed after receiving this label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants