From f8f317f5768f0b55798be7f131f91b3301b376d7 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sun, 15 Feb 2026 15:22:44 +0000 Subject: [PATCH] lint fixes --- main.go | 26 +++++++++++++++++++++----- new.go | 16 +++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 68a64a7..7a80be1 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "context" + "log" "os" "runtime/debug" "strings" @@ -45,16 +46,31 @@ func init() { viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) viper.SetEnvPrefix("IGNR") viper.AutomaticEnv() - viper.BindPFlag("token", rootCmd.PersistentFlags().Lookup("token")) - viper.BindPFlag("height", rootCmd.PersistentFlags().Lookup("height")) - viper.BindPFlag("filter", rootCmd.PersistentFlags().Lookup("filter")) - viper.BindPFlag("start-search", rootCmd.PersistentFlags().Lookup("start-search")) + if err := viper.BindPFlag("token", rootCmd.PersistentFlags().Lookup("token")); err != nil { + log.Fatal(err) + } + if err := viper.BindPFlag("height", rootCmd.PersistentFlags().Lookup("height")); err != nil { + log.Fatal(err) + } + if err := viper.BindPFlag("filter", rootCmd.PersistentFlags().Lookup("filter")); err != nil { + log.Fatal(err) + } + if err := viper.BindPFlag( + "start-search", + rootCmd.PersistentFlags().Lookup("start-search"), + ); err != nil { + log.Fatal(err) + } } // main is the entry point of the application. // It executes the root command and handles any errors. func main() { - if err := fang.Execute(context.Background(), rootCmd, fang.WithVersion(versionFromBuild())); err != nil { + if err := fang.Execute( + context.Background(), + rootCmd, + fang.WithVersion(versionFromBuild()), + ); err != nil { os.Exit(1) } } diff --git a/new.go b/new.go index 4d24302..f59c60e 100644 --- a/new.go +++ b/new.go @@ -20,9 +20,7 @@ var newCmd = &cobra.Command{ Use: "new", Short: "Create a new .gitignore file", Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runNewCommand(cmd, args) - }, + RunE: runNewCommand, } func init() { @@ -61,7 +59,11 @@ func runNewCommand(cmd *cobra.Command, _ []string) error { if err != nil { return fmt.Errorf("error opening file '%s': %w", gitignoreFileName, err) } - defer f.Close() + defer func() { + if err := f.Close(); err != nil { + fmt.Fprintf(os.Stderr, "error closing file '%s': %v\n", gitignoreFileName, err) + } + }() if err = commitGitignore(content, f); err != nil { return fmt.Errorf("error committing gitignore file: %w", err) @@ -108,7 +110,11 @@ func runPrompt(client *github.Client, pc *promptConfig) (*github.Gitignore, erro // commitGitignore writes the content of the selected gitignore template to the .gitignore file. func commitGitignore(content *github.Gitignore, w io.Writer) error { - if _, err := fmt.Fprintf(w, "# Generated by ignr: github.com/onyx-and-iris/ignr\n\n## %s ##\n", content.GetName()); err != nil { + if _, err := fmt.Fprintf( + w, + "# Generated by ignr: github.com/onyx-and-iris/ignr\n\n## %s ##\n", + content.GetName(), + ); err != nil { return fmt.Errorf("error writing header to file '%s': %w", gitignoreFileName, err) }