refactor: outputFilename -> licenseFilename

main
sudo pacman -Syu 2022-08-16 14:22:21 +07:00
parent a17e3ff2a1
commit cbb3c44210
No known key found for this signature in database
GPG Key ID: D6CB5C6C567C47B0
2 changed files with 6 additions and 6 deletions

View File

@ -24,7 +24,7 @@ var embedFS embed.FS
var templates = map[string]templateInfo{ var templates = map[string]templateInfo{
"MIT": { "MIT": {
templateFilename: "mit.txt", templateFilename: "mit.txt",
outputFilename: "LICENSE", licenseFilename: "LICENSE",
args: []string{ args: []string{
"[year]", "[year]",
"[fullname]", "[fullname]",
@ -32,13 +32,13 @@ var templates = map[string]templateInfo{
}, },
"GNU GPLv3": { "GNU GPLv3": {
templateFilename: "gnu_gplv3.txt", templateFilename: "gnu_gplv3.txt",
outputFilename: "COPYING", licenseFilename: "COPYING",
}, },
} }
type templateInfo struct { type templateInfo struct {
templateFilename string templateFilename string
outputFilename string licenseFilename string
args []string args []string
} }
@ -78,5 +78,5 @@ func generateLicense(name string) (string, string, error) {
licenseData = strings.ReplaceAll(licenseData, arg, value) licenseData = strings.ReplaceAll(licenseData, arg, value)
} }
return licenseData, templateInfo.outputFilename, nil return licenseData, templateInfo.licenseFilename, nil
} }

View File

@ -78,12 +78,12 @@ func (a *action) RunGenerate(c *cli.Context) error {
fmt.Printf("What LICENSE do you chose: ") fmt.Printf("What LICENSE do you chose: ")
licenseName := ioe.ReadInput() licenseName := ioe.ReadInput()
licenseData, outputFilename, err := generateLicense(licenseName) licenseData, licenseFilename, err := generateLicense(licenseName)
if err != nil { if err != nil {
return fmt.Errorf("failed to generate license %s: %w", licenseName, err) return fmt.Errorf("failed to generate license %s: %w", licenseName, err)
} }
outputFile := filepath.Join(a.flags.output, outputFilename) outputFile := filepath.Join(a.flags.output, licenseFilename)
if err := os.WriteFile(outputFile, []byte(licenseData), os.ModePerm); err != nil { if err := os.WriteFile(outputFile, []byte(licenseData), os.ModePerm); err != nil {
return fmt.Errorf("failed to write file %s: %w", outputFile, err) return fmt.Errorf("failed to write file %s: %w", outputFile, err)
} }