mirror of
https://github.com/onyx-and-iris/gignore.git
synced 2025-04-15 18:13:54 +01:00
move getEnv into main.go
This commit is contained in:
parent
478a172588
commit
00641cdc85
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -1,11 +0,0 @@
|
||||
package main
|
||||
|
||||
import "os"
|
||||
|
||||
func getEnv(key, defaultValue string) string {
|
||||
value := os.Getenv(key)
|
||||
if value == "" {
|
||||
return defaultValue
|
||||
}
|
||||
return value
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user