mirror of
https://github.com/onyx-and-iris/gogn.git
synced 2026-03-29 21:49:11 +00:00
lint fixes
This commit is contained in:
parent
736d940d4e
commit
8cb1b8168f
22
main.go
22
main.go
@ -4,6 +4,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
@ -42,15 +43,28 @@ func init() {
|
|||||||
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
|
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
|
||||||
viper.SetEnvPrefix("GOGN")
|
viper.SetEnvPrefix("GOGN")
|
||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
viper.BindPFlag("height", rootCmd.PersistentFlags().Lookup("height"))
|
if err := viper.BindPFlag("height", rootCmd.PersistentFlags().Lookup("height")); err != nil {
|
||||||
viper.BindPFlag("filter", rootCmd.PersistentFlags().Lookup("filter"))
|
log.Fatal("error binding height flag: %w", err)
|
||||||
viper.BindPFlag("start-search", rootCmd.PersistentFlags().Lookup("start-search"))
|
}
|
||||||
|
if err := viper.BindPFlag("filter", rootCmd.PersistentFlags().Lookup("filter")); err != nil {
|
||||||
|
log.Fatal("error binding filter flag: %w", err)
|
||||||
|
}
|
||||||
|
if err := viper.BindPFlag(
|
||||||
|
"start-search",
|
||||||
|
rootCmd.PersistentFlags().Lookup("start-search"),
|
||||||
|
); err != nil {
|
||||||
|
log.Fatal("error binding start-search flag: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// main is the entry point of the application.
|
// main is the entry point of the application.
|
||||||
// It executes the root command and handles any errors.
|
// It executes the root command and handles any errors.
|
||||||
func main() {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
new.go
15
new.go
@ -19,9 +19,7 @@ const gitignoreFileName string = ".gitignore"
|
|||||||
var newCmd = &cobra.Command{
|
var newCmd = &cobra.Command{
|
||||||
Use: "new",
|
Use: "new",
|
||||||
Short: "Create a new .gitignore file",
|
Short: "Create a new .gitignore file",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: runNewCommand,
|
||||||
return runNewCommand(cmd, args)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -55,7 +53,11 @@ func runNewCommand(cmd *cobra.Command, _ []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error opening file '%s': %w", gitignoreFileName, err)
|
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 {
|
if err = commitGitignore(content, f); err != nil {
|
||||||
return fmt.Errorf("error committing gitignore file: %w", err)
|
return fmt.Errorf("error committing gitignore file: %w", err)
|
||||||
@ -98,7 +100,10 @@ func runPrompt(client *gogi.Client, pc *promptConfig) (string, error) {
|
|||||||
|
|
||||||
// commitGitignore writes the content of the selected gitignore template to the .gitignore file.
|
// commitGitignore writes the content of the selected gitignore template to the .gitignore file.
|
||||||
func commitGitignore(content string, w io.Writer) error {
|
func commitGitignore(content string, w io.Writer) error {
|
||||||
if _, err := fmt.Fprintf(w, "# Generated by gogn: github.com/onyx-and-iris/gogn\n"); err != nil {
|
if _, err := fmt.Fprintf(
|
||||||
|
w,
|
||||||
|
"# Generated by gogn: github.com/onyx-and-iris/gogn\n",
|
||||||
|
); err != nil {
|
||||||
return fmt.Errorf("error writing header to file '%s': %w", gitignoreFileName, err)
|
return fmt.Errorf("error writing header to file '%s': %w", gitignoreFileName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user