diff --git a/cmd/new.go b/cmd/new.go index 6c50325..8c7980a 100644 --- a/cmd/new.go +++ b/cmd/new.go @@ -20,7 +20,8 @@ var newPasswordCommand = &cobra.Command{Use: "new", Short: "New Password", Long: "Create a secure password", Run: func(cmd *cobra.Command, args []string) { - pg := passgen.NewPasswordGenerator(passgen.Options{Length: Length, WithNumbers: WithNumbers}) + opts := passgen.Options{Length: Length, WithNumbers: WithNumbers} + pg := passgen.NewPasswordGenerator(opts.SetDefaults()) password := pg.NewPassword() display(password) }} diff --git a/passgen/passgen.go b/passgen/passgen.go index 1e84ee2..ef1b354 100644 --- a/passgen/passgen.go +++ b/passgen/passgen.go @@ -8,13 +8,13 @@ import ( // PasswordGenerator handles passwords creation. type PasswordGenerator struct { characters []rune - options Options + options *Options } // NewPasswordGenerator returns a valid PasswordGenerator given the specified Options. -func NewPasswordGenerator(opts Options) *PasswordGenerator { +func NewPasswordGenerator(opts *Options) *PasswordGenerator { pg := &PasswordGenerator{} - pg.options = *opts.SetDefaults() + pg.options = opts.SetDefaults() pg.characters = pg.shuffleCharacters(opts.WithNumbers) return pg } diff --git a/passgen/passgen_test.go b/passgen/passgen_test.go index f24b289..12cda6e 100644 --- a/passgen/passgen_test.go +++ b/passgen/passgen_test.go @@ -9,8 +9,8 @@ import ( ) func TestGeneratePasswordWithGivenCharacterNumber(t *testing.T) { - opts := passgen.Options{ - Length: rand.Intn(12), + opts := &passgen.Options{ + Length: rand.Intn(12), // nolint } pg := passgen.NewPasswordGenerator(opts) @@ -20,7 +20,7 @@ func TestGeneratePasswordWithGivenCharacterNumber(t *testing.T) { } func TestGeneratePasswordWithDefaultCharacterNumber(t *testing.T) { - pg := passgen.NewPasswordGenerator(passgen.Options{}) + pg := passgen.NewPasswordGenerator(&passgen.Options{}) if password := pg.NewPassword(); len(password) != 6 { t.Errorf("Expected a password to be %d characters long, got %d", 6, len(password)) @@ -28,7 +28,7 @@ func TestGeneratePasswordWithDefaultCharacterNumber(t *testing.T) { } func TestGeneratePasswordWithLettersAndNumbers(t *testing.T) { - opts := passgen.Options{ + opts := &passgen.Options{ WithNumbers: true, } pg := passgen.NewPasswordGenerator(opts)