mirror of
https://github.com/onyx-and-iris/gignore.git
synced 2025-04-16 02:23:53 +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) {
|
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)
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
@ -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