move getEnv into main.go

This commit is contained in:
onyx-and-iris 2025-04-13 17:03:57 +01:00
parent 478a172588
commit 00641cdc85
4 changed files with 15 additions and 14 deletions

View File

@ -38,5 +38,6 @@ func init() {
func createTemplate(template string) { func createTemplate(template string) {
err := client.Create(template) err := client.Create(template)
cobra.CheckErr(err) cobra.CheckErr(err)
fmt.Printf("√ created %s .gitignore file\n", template) fmt.Printf("√ created %s .gitignore file\n", template)
} }

View File

@ -19,9 +19,8 @@ You can use this command to quickly find all available .gitignore templates.
Example: Example:
gignore --root=<path> list`, gignore --root=<path> list`,
Run: func(_ *cobra.Command, _ []string) { Run: func(_ *cobra.Command, _ []string) {
if err := listTemplates(); err != nil { err := listTemplates()
cobra.CheckErr(err) cobra.CheckErr(err)
}
}, },
} }
@ -37,10 +36,12 @@ func listTemplates() error {
if err != nil { if err != nil {
return err return err
} }
var output strings.Builder var output strings.Builder
for _, template := range templates { for _, template := range templates {
output.WriteString(template + "\n") output.WriteString(template + "\n")
} }
fmt.Print(output.String()) fmt.Print(output.String())
return nil return nil
} }

View File

@ -3,6 +3,8 @@
package main package main
import ( import (
"os"
"github.com/onyx-and-iris/gignore" "github.com/onyx-and-iris/gignore"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -43,6 +45,14 @@ func init() {
StringP("loglevel", "l", getEnv("GIGNORE_LOGLEVEL", "warn"), "Log level (trace, debug, info, warn, error, fatal, panic)") StringP("loglevel", "l", getEnv("GIGNORE_LOGLEVEL", "warn"), "Log level (trace, debug, info, warn, error, fatal, panic)")
} }
func getEnv(key, defaultValue string) string {
value := os.Getenv(key)
if value == "" {
return defaultValue
}
return value
}
func main() { func main() {
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
panic(err) panic(err)

View File

@ -1,11 +0,0 @@
package main
import "os"
func getEnv(key, defaultValue string) string {
value := os.Getenv(key)
if value == "" {
return defaultValue
}
return value
}