Skip to content

Commit

Permalink
Simplify config
Browse files Browse the repository at this point in the history
  • Loading branch information
timdp committed Apr 25, 2018
1 parent 49db8ab commit 3cecfd9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
24 changes: 12 additions & 12 deletions internal/app/lwc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
const DEFAULT_INTERVAL int = 100

type Config struct {
CountLines bool
CountWords bool
CountChars bool
CountBytes bool
Lines bool
Words bool
Chars bool
Bytes bool
MaxLineLength bool
Interval time.Duration
Help bool
Expand All @@ -25,10 +25,10 @@ type Config struct {
func BuildConfig() Config {
var config Config
intervalMs := DEFAULT_INTERVAL
getopt.FlagLong(&config.CountLines, "lines", 'l', "print the newline counts")
getopt.FlagLong(&config.CountWords, "words", 'w', "print the word counts")
getopt.FlagLong(&config.CountChars, "chars", 'm', "print the character counts")
getopt.FlagLong(&config.CountBytes, "bytes", 'c', "print the byte counts")
getopt.FlagLong(&config.Lines, "lines", 'l', "print the newline counts")
getopt.FlagLong(&config.Words, "words", 'w', "print the word counts")
getopt.FlagLong(&config.Chars, "chars", 'm', "print the character counts")
getopt.FlagLong(&config.Bytes, "bytes", 'c', "print the byte counts")
getopt.FlagLong(&config.MaxLineLength, "max-line-length", 'L', "print the maximum display width")
getopt.FlagLong(&intervalMs, "interval", 'i',
fmt.Sprintf("set update interval in ms (default %d ms)", DEFAULT_INTERVAL))
Expand All @@ -37,10 +37,10 @@ func BuildConfig() Config {
getopt.Parse()
config.Interval = time.Duration(intervalMs * 1e6)
config.Files = getopt.Args()
if !(config.CountLines || config.CountWords || config.CountChars || config.CountBytes) {
config.CountLines = true
config.CountWords = true
config.CountBytes = true
if !(config.Lines || config.Words || config.Chars || config.Bytes) {
config.Lines = true
config.Words = true
config.Bytes = true
}
return config
}
Expand Down
8 changes: 4 additions & 4 deletions internal/app/lwc/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ type Processor struct {
func BuildProcessors(config *Config) []Processor {
var temp [5]Processor
i := 0
if config.CountLines {
if config.Lines {
temp[i] = Processor{bufio.ScanLines, ScanCount}
i++
}
if config.CountWords {
if config.Words {
temp[i] = Processor{bufio.ScanWords, ScanCount}
i++
}
if config.CountChars {
if config.Chars {
temp[i] = Processor{bufio.ScanRunes, ScanCount}
i++
}
if config.CountBytes {
if config.Bytes {
temp[i] = Processor{bufio.ScanBytes, ScanCount}
i++
}
Expand Down

0 comments on commit 3cecfd9

Please sign in to comment.