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).
|
a brand new license: 996.icu, defined by [996.icu](https://github.com/996icu/996.ICU).
|
||||||
|
|
||||||
## Usage
|
## 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
|
```sh
|
||||||
# Get the help from this tool:
|
# Get the help from this tool:
|
||||||
./gen-license-go -h
|
./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 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
|
// genCmd represents the gen command
|
||||||
var genCmd = &cobra.Command{
|
var genCmd = &cobra.Command{
|
||||||
@ -72,6 +72,7 @@ gen-license-go gen mit --996icu en-us`,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
// Add the 'gen' sub-command into root-command.
|
||||||
rootCmd.AddCommand(genCmd)
|
rootCmd.AddCommand(genCmd)
|
||||||
|
|
||||||
// Here you will define your flags and configuration settings.
|
// Here you will define your flags and configuration settings.
|
||||||
|
@ -17,27 +17,16 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
|
"fmt"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var LICENSES = []string{
|
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",
|
|
||||||
}
|
|
||||||
|
|
||||||
// rootCmd represents the base command when called without any subcommands
|
// rootCmd represents the base command when called without any subcommands
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
@ -64,8 +53,17 @@ func Execute() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.Flags().BoolP("list", "l", true, "list all licenses")
|
// Read all filenames from licenses directory.
|
||||||
rootCmd.MarkFlagRequired("list")
|
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.
|
// Here you will define your flags and configuration settings.
|
||||||
// Cobra supports persistent flags, which, if defined here,
|
// Cobra supports persistent flags, which, if defined here,
|
||||||
// will be global for your application.
|
// will be global for your application.
|
||||||
@ -74,4 +72,6 @@ func init() {
|
|||||||
// Cobra also supports local flags, which will only run
|
// Cobra also supports local flags, which will only run
|
||||||
// when this action is called directly.
|
// when this action is called directly.
|
||||||
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
// 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