mirror of
https://github.com/onyx-and-iris/gignore.git
synced 2025-04-16 02:23:53 +01:00
return err from createTemplate and check it
This commit is contained in:
parent
00641cdc85
commit
7a964a031c
@ -24,7 +24,8 @@ Example:
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
createTemplate(arg)
|
err := createTemplate(arg)
|
||||||
|
cobra.CheckErr(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -35,9 +36,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// createTemplate creates a new .gitignore file using the specified template.
|
// createTemplate creates a new .gitignore file using the specified template.
|
||||||
func createTemplate(template string) {
|
func createTemplate(template string) error {
|
||||||
err := client.Create(template)
|
err := client.Create(template)
|
||||||
cobra.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("√ created %s .gitignore file\n", template)
|
fmt.Printf("√ created %s .gitignore file\n", template)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -39,22 +39,22 @@ It supports various programming languages.
|
|||||||
|
|
||||||
// init initialises the root command and adds global flags.
|
// init initialises the root command and adds global flags.
|
||||||
func init() {
|
func init() {
|
||||||
|
getEnv := func(key, defaultValue string) string {
|
||||||
|
value := os.Getenv(key)
|
||||||
|
if value == "" {
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
rootCmd.PersistentFlags().
|
rootCmd.PersistentFlags().
|
||||||
StringP("root", "r", getEnv("GIGNORE_TEMPLATE_ROOT", gignore.DefaultTemplateDirectory), "Root directory to search for .gitignore files")
|
StringP("root", "r", getEnv("GIGNORE_TEMPLATE_ROOT", gignore.DefaultTemplateDirectory), "Root directory to search for .gitignore files")
|
||||||
rootCmd.PersistentFlags().
|
rootCmd.PersistentFlags().
|
||||||
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)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user