Skip to content

Commit

Permalink
Merge pull request 996icu#25192 from panjf2000/master
Browse files Browse the repository at this point in the history
Get licenses' names from reading the licenses dir dynamically
  • Loading branch information
996icu authored Apr 5, 2019
2 parents 7d069f2 + a48d3ae commit 7de6d94
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion archived/licenses[WIP]/tools/gen-license-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion archived/licenses[WIP]/tools/gen-license-go/cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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.
Expand Down
36 changes: 18 additions & 18 deletions archived/licenses[WIP]/tools/gen-license-go/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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.
Expand All @@ -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")
}

0 comments on commit 7de6d94

Please sign in to comment.