Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #18 from jmillerv/refactor
Browse files Browse the repository at this point in the history
Refactor: Remove packr dependency
  • Loading branch information
jmillerv authored Aug 15, 2022
2 parents 66016a9 + 5cdd8f1 commit 098be00
Show file tree
Hide file tree
Showing 43 changed files with 289 additions and 233 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*.idea
cmd/gophrase/gophrase
src/gophrase
4 changes: 0 additions & 4 deletions assets/defaults.json

This file was deleted.

24 changes: 0 additions & 24 deletions cmd/gophrase/main.go

This file was deleted.

10 changes: 0 additions & 10 deletions go.mod

This file was deleted.

16 changes: 0 additions & 16 deletions internal/constant.go

This file was deleted.

47 changes: 0 additions & 47 deletions pkg/config/config.go

This file was deleted.

14 changes: 0 additions & 14 deletions pkg/config/config_test.go

This file was deleted.

73 changes: 0 additions & 73 deletions pkg/corpus/corpus.go

This file was deleted.

5 changes: 5 additions & 0 deletions src/assets/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
WordCount: 5
WordList: assets/wordlists/eff_short_wordlist_1.json
Capital: false
Special: false
Number: false
4 changes: 2 additions & 2 deletions assets/list_options.txt → src/assets/list_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Wordlist Options

To set the list `gophrase gen 5 a` or `gophrase gen a` if you are okay with a three word passphrase.

a: EFF Short Wordlist 2
b: EFF Short Wordlist 1
a: EFF Short Wordlist 1
b: EFF Short Wordlist 2
c: EFF Large Wordlist
d: Reinhold Wordlist

Expand Down
File renamed without changes.
83 changes: 57 additions & 26 deletions internal/argument/command.go → src/command/command.go
Original file line number Diff line number Diff line change
@@ -1,48 +1,53 @@
package argument
package command

import (
"fmt"
"github.com/gophrase/pkg/config"
"github.com/gophrase/pkg/corpus"
"github.com/gophrase/pkg/entropy"
"github.com/gophrase/pkg/generate"
"github.com/jmillerv/gophrase/config"
"github.com/jmillerv/gophrase/corpus"
"github.com/jmillerv/gophrase/entropy"
"github.com/jmillerv/gophrase/generate"
"github.com/urfave/cli/v2"
"strconv"
)

const (
defaultWordCount = 5
)

// Commands hold an array of cli.Commands which are used to run the CLI application.
var Commands = []*cli.Command{
{
Name: "generate",
Aliases: []string{"gen"},
Usage: "gen [int]",
Action: func(c *cli.Context) error {
// TODO input validator to clean up section
config.LoadConfigDefaults()
p := generate.Params{}
config.LoadConfig()
p := &generate.Params{}
p.WordCount, _ = strconv.Atoi(c.Args().Get(0))
if p.WordCount == 0 {
p.WordCount = config.Defaults.WordCount
p.WordCount = config.LoadedConfig.WordCount
}
p.WordList = c.Args().Get(1)
if p.WordList == "" {
p.WordList = config.Defaults.WordList
p.WordList = config.LoadedConfig.WordList
}
if c.Bool("capital") {
if c.Bool("capital") || config.LoadedConfig.Capital {
p.Capitals = true
} else {
p.Capitals = false
}
if c.Bool("special") {
if c.Bool("special") || config.LoadedConfig.Special {
p.SpecialChars = true
} else {
p.SpecialChars = false
}
if c.Bool("number") {
if c.Bool("number") || config.LoadedConfig.Number {
p.Numbers = true
} else {
p.Numbers = false
}
password := generate.Password(&p)
password := generate.Password(p)
entropy.PrintEntropy(password)
return nil
},
Expand All @@ -65,7 +70,7 @@ var Commands = []*cli.Command{
},
},
{
Name: "Wordlist Options",
Name: "wordlist-options",
Aliases: []string{"opts"},
Usage: "View the wordlist options for passphrase generation",
Action: func(c *cli.Context) error {
Expand All @@ -74,30 +79,56 @@ var Commands = []*cli.Command{
},
},
{
Name: "Set Defaults",
Name: "set-defaults",
Aliases: []string{"sd"},
Usage: "Set default options for word count and word list",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "capital",
Aliases: []string{"c"},
Usage: "Add random capitalization to your passwords",
},
&cli.BoolFlag{
Name: "special",
Aliases: []string{"s"},
Usage: "Add random special characters to your passwords",
},
&cli.BoolFlag{
Name: "number",
Aliases: []string{"n"},
Usage: "Add numbers to your passwords",
},
},
Action: func(c *cli.Context) error {
p := generate.Params{}
p.WordCount, _ = strconv.Atoi(c.Args().Get(0))
if p.WordCount == 0 {
p.WordCount = config.Defaults.WordCount
conf := &config.Config{}
conf.WordCount, _ = strconv.Atoi(c.Args().Get(0))
if conf.WordCount == 0 {
conf.WordCount = defaultWordCount
}
p.WordList = corpus.SetWordList(c.Args().Get(1))
if p.WordList == "" {
p.WordList = config.Defaults.WordList
conf.WordList = corpus.SetWordList(c.Args().Get(1))
if conf.WordList == "" {
conf.WordList = config.EffShort1
}
if c.Bool("capital") {
conf.Capital = true
}
if c.Bool("special") {
conf.Special = true
}
if c.Bool("number") {
conf.Number = true
}
config.SetConfigDefaults(config.Defaults, p.WordCount, p.WordList)
config.SetConfig(conf)
return nil
},
},
{
Name: "List Defaults",
Name: "list-defaults",
Aliases: []string{"ld"},
Usage: "Print default options for word count and word list",
Action: func(c *cli.Context) error {
config.LoadConfigDefaults()
config.PrintConfigDefaults(config.Defaults)
config.LoadConfig()
config.LoadedConfig.PrintConfig()
return nil
},
},
Expand Down
Loading

0 comments on commit 098be00

Please sign in to comment.