Skip to content

Commit

Permalink
Move filter style option to a flag
Browse files Browse the repository at this point in the history
It's not a subcommand so it makes more sense to keep it as a flag for
now.
  • Loading branch information
ondrowan committed May 11, 2018
1 parent 4d5e252 commit 17b957e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ This is a simple tool for updating of [Neversink's loot filter](https://github.c
* In case you wish to use different style of filters:
* Create a shortcut of exe file.
* Right click it and select "Properties".
* In "Shortcut" section, append desired style name behind "Target".
Currently, valid choices are: `blue`, `purple`, `slick` and `streamsound`.
* In "Shortcut" section, append `--style`, followed by desired style name behind "Target".
Currently, valid choices are: `blue`, `purple`, `slick` and `streamsound`. The result
should look, for example, like: `C:\neversink-filter-updater.exe --style blue`

If you don't mind using command line, here is the usage:

```bash
Usage:
-help
Prints help.
-style string
Style of filters. Can be one of: blue, purple, slick, streamsound.
-version
Prints version.
```

This program was tested on 64-bit Windows 10.
50 changes: 22 additions & 28 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,29 @@ var poePath = filepath.Join(os.Getenv("USERPROFILE"), "Documents/My Games/Path o
var dotFilePath = filepath.Join(poePath, ".neversink-updater")

func main() {
var filterType string
filterStyle := flag.String(
"style",
"",
"Style of filters. Can be one of: blue, purple, slick, streamsound.")
helpPtr := flag.Bool("help", false, "Prints help.")
versionPtr := flag.Bool("version", false, "Prints version.")

if len(os.Args) > 1 {
filterType = os.Args[1]
flag.Usage = func() {
fmt.Fprintln(os.Stderr, "Usage:")
flag.PrintDefaults()
}

parseFlags()
flag.Parse()

if *versionPtr {
fmt.Fprintf(os.Stdout, version)
os.Exit(0)
}

if *helpPtr {
flag.PrintDefaults()
os.Exit(0)
}

if err := checkPoeDir(); err != nil {
exit(1, err.Error())
Expand All @@ -54,12 +70,12 @@ func main() {
}

tmpArchivePath := createTmpArchive(zipFile)
unzippedFileCount := unzipArchive(tmpArchivePath, filterType)
unzippedFileCount := unzipArchive(tmpArchivePath, *filterStyle)

if unzippedFileCount > 0 {
fmt.Fprintf(os.Stdout, "%d files were unzipped.\n", unzippedFileCount)
} else {
exit(1, fmt.Sprintf("No files were unzipped. Is \"%s\" correct filter type?", filterType))
exit(1, fmt.Sprintf("No files were unzipped. Is \"%s\" correct filter style?", *filterStyle))
}

writeToDotfile(*release.TagName)
Expand All @@ -73,28 +89,6 @@ func main() {
exit(0, "")
}

func parseFlags() {
helpPtr := flag.Bool("help", false, "Prints help")
versionPtr := flag.Bool("version", false, "Prints version")

flag.Usage = func() {
fmt.Fprintln(os.Stderr, "Usage:")
flag.PrintDefaults()
}

flag.Parse()

if *versionPtr {
fmt.Fprintf(os.Stdout, version)
os.Exit(0)
}

if *helpPtr {
flag.PrintDefaults()
os.Exit(0)
}
}

func exit(code int, message string) {
output := os.Stdout

Expand Down

0 comments on commit 17b957e

Please sign in to comment.