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) {
err := client.Create(template)
cobra.CheckErr(err)
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:
gignore --root=<path> list`,
Run: func(_ *cobra.Command, _ []string) {
if err := listTemplates(); err != nil {
cobra.CheckErr(err)
}
err := listTemplates()
cobra.CheckErr(err)
},
}
@ -37,10 +36,12 @@ func listTemplates() error {
if err != nil {
return err
}
var output strings.Builder
for _, template := range templates {
output.WriteString(template + "\n")
}
fmt.Print(output.String())
return nil
}

View File

@ -3,6 +3,8 @@
package main
import (
"os"
"github.com/onyx-and-iris/gignore"
log "github.com/sirupsen/logrus"
"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)")
}
func getEnv(key, defaultValue string) string {
value := os.Getenv(key)
if value == "" {
return defaultValue
}
return value
}
func main() {
if err := rootCmd.Execute(); err != nil {
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
}