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

Check if LICENSE exists. #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

harjyotbagga
Copy link

In continuation to PR #1605

Signed off by: Harjyot Bagga baggaharjyot@gmail.com
PR to resolve Issue #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:
cobra-cli-sandbox-test

Post Checks:

  • Built Successfully
  • All tests passed successfully

@CLAassistant
Copy link

CLAassistant commented Feb 21, 2022

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


harjyotbagga seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@@ -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.

Confirms 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.

Copy link
Author

@harjyotbagga harjyotbagga left a comment

Choose a reason for hiding this comment

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

Changes proposed.
@johnSchnake please have a look.

@johnSchnake
Copy link
Collaborator

LGTM; built locally and overwrites it when I say 'y', doesn't otherwise.

Going to ping someone else for final merging only because of the change of default license; being new to the project I want to be extra cautious about that.

@jpmcb Can you confirm if changing the default license to empty is appropriate? E.g. default to leaving the license files alone. Maybe a nit would be naming; would ignore or something else be more appropriate? Functionality here seems fine though.

@harjyotbagga
Copy link
Author

I was thinking on similar lines, but as far I remember I came across an issue in cobra suggesting to keep an empty license as the default one.
However I am up for anything.

Copy link
Collaborator

@jpmcb jpmcb left a comment

Choose a reason for hiding this comment

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

This is looking great! Thanks for bringing this feature over so quickly.

We still need to tag this repo so that downstream users can consume it. After that happens, we can start to talk about bringing in features, etc. Blocking on this PR review for now until we go ahead with that.

@harjyotbagga
Copy link
Author

Sure. Whenever that's done, we can add this feature.
If there are any changes to be done from my end, please HMU. 🙌🏻

@harjyotbagga
Copy link
Author

Heyy, since it's been more than I month. I just wanted to check upon this PR. Is there anything to be done from my end? Or what is the plan that we are looking at ahead?

@github-actions
Copy link

github-actions bot commented Jun 5, 2022

This PR is being marked as stale due to a long period of inactivity

@jpmcb
Copy link
Collaborator

jpmcb commented Jul 27, 2022

@harjyotbagga - my apologies, it's been a crazy summer here and I haven't had alot of time to dedicate into cobra.

We'll get this in soon - this is a great feature add and thank you for your patience!

@jpmcb jpmcb self-requested a review July 27, 2022 20:48
@harjyotbagga
Copy link
Author

Thank you so much for the reply! Super happy to contribute. Please let me know if there are any changes to be done from my end!

@github-actions
Copy link

This PR is being marked as stale due to a long period of inactivity

@github-actions
Copy link

This PR is being marked as stale due to a long period of inactivity

@harjyotbagga
Copy link
Author

@jpmcb Is there anything to be done from my end?

@github-actions
Copy link

This PR is being marked as stale due to a long period of inactivity

@github-actions
Copy link

github-actions bot commented Apr 2, 2023

This PR is being marked as stale due to a long period of inactivity

@github-actions
Copy link

github-actions bot commented Jun 2, 2023

This PR is being marked as stale due to a long period of inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants