Skip to content

Commit

Permalink
tech: fix golangci-lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sylviamoss committed Mar 26, 2024
1 parent a17adc8 commit 64a515c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
6 changes: 3 additions & 3 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
func init() {
// Deprecated flags
configCmd.Flags().BoolVar(&config.AddLang, "add-lang", false, "add new config language")
configCmd.Flags().MarkDeprecated("add-lang", "please use the equivalent flag in the 'dictionary' command instead")
_ = configCmd.Flags().MarkDeprecated("add-lang", "please use the equivalent flag in the 'dictionary' command instead")

configCmd.Flags().StringVar(&config.Source, "source", "", "dictionary source file")
configCmd.Flags().MarkDeprecated("source", "please use the equivalent flag in the 'dictionary' command instead")
_ = configCmd.Flags().MarkDeprecated("source", "please use the equivalent flag in the 'dictionary' command instead")

configCmd.Flags().StringVar(&config.Name, "name", "", "language name")
configCmd.Flags().MarkDeprecated("name", "please use the equivalent flag in the 'dictionary' command instead")
_ = configCmd.Flags().MarkDeprecated("name", "please use the equivalent flag in the 'dictionary' command instead")

configCmd.AddCommand(generateConfigCmd)
rootCmd.AddCommand(configCmd)
Expand Down
14 changes: 7 additions & 7 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ func init() {
generateCmd.Flags().StringVarP(&generate.configFile, "config", "c", "", "config file (default is $HOME/.diceware-cli.yaml)")

// Configure viper to read from the config file, if set
viper.BindPFlag("generate.lang", generateCmd.Flags().Lookup("lang"))
viper.BindPFlag("generate.separator", generateCmd.Flags().Lookup("separator"))
viper.BindPFlag("generate.size", generateCmd.Flags().Lookup("size"))
viper.BindPFlag("generate.copy", generateCmd.Flags().Lookup("copy"))
viper.BindPFlag("generate.hide", generateCmd.Flags().Lookup("hide"))
viper.BindPFlag("generate.lower", generateCmd.Flags().Lookup("lower"))
viper.BindPFlag("generate.remove-number", generateCmd.Flags().Lookup("remove-number"))
_ = viper.BindPFlag("generate.lang", generateCmd.Flags().Lookup("lang"))
_ = viper.BindPFlag("generate.separator", generateCmd.Flags().Lookup("separator"))
_ = viper.BindPFlag("generate.size", generateCmd.Flags().Lookup("size"))
_ = viper.BindPFlag("generate.copy", generateCmd.Flags().Lookup("copy"))
_ = viper.BindPFlag("generate.hide", generateCmd.Flags().Lookup("hide"))
_ = viper.BindPFlag("generate.lower", generateCmd.Flags().Lookup("lower"))
_ = viper.BindPFlag("generate.remove-number", generateCmd.Flags().Lookup("remove-number"))

rootCmd.AddCommand(generateCmd)
}
Expand Down
10 changes: 6 additions & 4 deletions diceware/diceware.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"os/exec"
"path/filepath"
"strconv"
"strings"
"unicode"

"golang.org/x/text/cases"
"golang.org/x/text/language"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
Expand Down Expand Up @@ -76,7 +77,7 @@ func (c *Config) Generate() error {
}

if words == "" {
return fmt.Errorf("unable to generate passphrase.")
return fmt.Errorf("unable to generate passphrase")
}

fmt.Println(words)
Expand Down Expand Up @@ -130,7 +131,8 @@ func (c *Config) findDicewareWord(number string, lang string) (string, error) {
if c.Lower {
return transformedWord, nil
}
return strings.Title(transformedWord), nil

return cases.Title(language.Und, cases.NoLower).String(transformedWord), nil
}

func findCustomDicewareWord(wordPath string) (string, error) {
Expand All @@ -150,5 +152,5 @@ func findCustomDicewareWord(wordPath string) (string, error) {
return scanner.Text(), nil
}

return "", fmt.Errorf("couldn't read word from custom dictionary.\n")
return "", fmt.Errorf("couldn't read word from custom dictionary")
}
14 changes: 10 additions & 4 deletions diceware/dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (c *Dictionary) Configure() error {

func (c *Dictionary) newLanguage() error {
if c.Source == "" || c.Name == "" {
return fmt.Errorf("Please provide both dictionary source file and language name (--source, --name)")
return fmt.Errorf("please provide both dictionary source file and language name (--source, --name)")
}

file, err := os.Open(c.Source)
Expand All @@ -41,7 +41,7 @@ func (c *Dictionary) newLanguage() error {
}

dicewarePath := home + "/.diceware-cli.d/diceware_words_" + c.Name
if _, err := os.Stat(dicewarePath); os.IsNotExist(err) {
if _, err = os.Stat(dicewarePath); os.IsNotExist(err) {
err = os.MkdirAll(dicewarePath, os.ModePerm)
}
if err != nil && !os.IsNotExist(err) {
Expand All @@ -62,8 +62,14 @@ func (c *Dictionary) newLanguage() error {
if err != nil {
return err
}
f.WriteString(words[1])
f.Sync()
_, err = f.WriteString(words[1])
if err != nil {
return err
}
err = f.Sync()
if err != nil {
return err
}
f.Close()
}
bar.Finish()
Expand Down

0 comments on commit 64a515c

Please sign in to comment.