Merge pull request #25192 from panjf2000/master
Get licenses' names from reading the licenses dir dynamically
This commit is contained in:
@ -8,7 +8,7 @@ More importantly, the main purpose of this tool is to incorporate those aforesai
|
||||
a brand new license: 996.icu, defined by [996.icu](https://github.com/996icu/996.ICU).
|
||||
|
||||
## Usage
|
||||
There are three executable files of different operating systems: macOS, Linux and Windows, located in `bin` directory, you can pick the specific bin file based on your OS, then put the `licenses` directory and `gen-license-go` file into the same path.
|
||||
There are three executable files for different operating systems: macOS, Linux and Windows, located in `bin` directory, you can pick the specific bin file based on your OS, then put the `licenses` directory and `gen-license-go` file into the same path.
|
||||
```sh
|
||||
# Get the help from this tool:
|
||||
./gen-license-go -h
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -26,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
var template string
|
||||
var licensePathTemplate, icuPathTemplate = "licenses/%s.txt", "licenses/996.icu.template.%s.txt"
|
||||
var licensePathTemplate, icuPathTemplate = "licenses/%s.txt", "licenses/templates/996.icu.template.%s.txt"
|
||||
|
||||
// genCmd represents the gen command
|
||||
var genCmd = &cobra.Command{
|
||||
@ -72,6 +72,7 @@ gen-license-go gen mit --996icu en-us`,
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Add the 'gen' sub-command into root-command.
|
||||
rootCmd.AddCommand(genCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
@ -17,27 +17,16 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var LICENSES = []string{
|
||||
"agpl-3.0",
|
||||
"apache-2.0",
|
||||
"bsd-2-clause",
|
||||
"bsd-3-clause",
|
||||
"epl-2.0",
|
||||
"gpl-2.0",
|
||||
"gpl-3.0",
|
||||
"lgpl-2.1",
|
||||
"lgpl-3.0",
|
||||
"mit",
|
||||
"mpl-2.0",
|
||||
"unlicenses",
|
||||
"anti996icu-1.0",
|
||||
}
|
||||
var LICENSES []string
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
@ -64,8 +53,17 @@ func Execute() {
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.Flags().BoolP("list", "l", true, "list all licenses")
|
||||
rootCmd.MarkFlagRequired("list")
|
||||
// Read all filenames from licenses directory.
|
||||
files, err := ioutil.ReadDir("./licenses")
|
||||
handleError(err)
|
||||
for _, file := range files {
|
||||
if file.IsDir() {
|
||||
continue
|
||||
} else {
|
||||
LICENSES = append(LICENSES, strings.TrimSuffix(file.Name(), path.Ext(file.Name())))
|
||||
}
|
||||
}
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
// Cobra supports persistent flags, which, if defined here,
|
||||
// will be global for your application.
|
||||
@ -74,4 +72,6 @@ func init() {
|
||||
// Cobra also supports local flags, which will only run
|
||||
// when this action is called directly.
|
||||
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
rootCmd.Flags().BoolP("list", "l", true, "list all licenses")
|
||||
rootCmd.MarkFlagRequired("list")
|
||||
}
|
||||
|
Reference in New Issue
Block a user