Skip to content

Commit

Permalink
Fix lint, add word test
Browse files Browse the repository at this point in the history
  • Loading branch information
eandre committed Aug 9, 2023
1 parent 74c33ff commit 7a4a45e
Show file tree
Hide file tree
Showing 7 changed files with 1,355 additions and 1,306 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/encore/cmdutil/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Oneof struct {
func (o *Oneof) AddFlag(cmd *cobra.Command) {
name, short := o.FlagName()
cmd.Flags().VarP(o, name, short, o.Usage())
cmd.RegisterFlagCompletionFunc(name, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
_ = cmd.RegisterFlagCompletionFunc(name, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return o.Allowed, cobra.ShellCompDirectiveNoFileComp
})
}
Expand Down
8 changes: 4 additions & 4 deletions cli/cmd/encore/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func init() {
if err := json.Indent(&dst, buf.Bytes(), "", " "); err != nil {
cmdutil.Fatal(err)
}
fmt.Fprintln(os.Stdout, dst.String())
_, _ = fmt.Fprintln(os.Stdout, dst.String())
return
}

Expand Down Expand Up @@ -114,7 +114,7 @@ var createCmd = &cobra.Command{
if err != nil {
cmdutil.Fatal(err)
}
fmt.Fprintf(os.Stdout, "created namespace %s\n", ns.Name)
_, _ = fmt.Fprintf(os.Stdout, "created namespace %s\n", ns.Name)
},
}

Expand All @@ -139,7 +139,7 @@ var deleteCmd = &cobra.Command{
if err != nil {
cmdutil.Fatal(err)
}
fmt.Fprintf(os.Stdout, "deleted namespace %s\n", name)
_, _ = fmt.Fprintf(os.Stdout, "deleted namespace %s\n", name)
},
}

Expand Down Expand Up @@ -171,7 +171,7 @@ You can use '-' as the namespace name to switch back to the previously active na
if err != nil {
cmdutil.Fatal(err)
}
fmt.Fprintf(os.Stdout, "switched to namespace %s\n", ns.Name)
_, _ = fmt.Fprintf(os.Stdout, "switched to namespace %s\n", ns.Name)
},
}

Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/encore/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func init() {

// Words command
func init() {
sep := " "
var sep string
wordsCmd := &cobra.Command{
Use: "words [--sep=SEPARATOR] NUM",
Short: "Generates random 4-5 letter words for memorable passphrases",
Expand Down Expand Up @@ -181,6 +181,6 @@ func init() {
},
}

wordsCmd.Flags().StringVarP(&sep, "sep", "s", "-", "separator between words")
wordsCmd.Flags().StringVarP(&sep, "sep", "s", " ", "separator between words")
randCmd.AddCommand(wordsCmd)
}
6 changes: 4 additions & 2 deletions pkg/words/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import (
"math/big"
)

// Select selects n random words from the short word list.
func Select(n int) ([]string, error) {
selected := make([]string, n)
max := big.NewInt(int64(len(Words)))
words := shortWords.Get()
max := big.NewInt(int64(len(words)))
for i := 0; i < n; i++ {
j, err := rand.Int(rand.Reader, max)
if err != nil {
return nil, fmt.Errorf("wordlist.Select %d: %v", n, err)
}
selected[i] = Words[j.Int64()]
selected[i] = words[j.Int64()]
}
return selected, nil
}
Loading

0 comments on commit 7a4a45e

Please sign in to comment.