Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
monomonedula committed Mar 28, 2023
1 parent dc2445d commit 07a2758
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 monomonedula

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# GoPdd

### PDD puzzle collector



A port of [the original PDD written in Ruby](https://github.com/cqfn/pdd/), but with JSON output and written in Go, so it compiles into a single pretty executable.

Expected formatting and most of the functionality is the same, so feel free to use documentation from the original repo for reference on how to write puzzles.

```
NAME:
GoPdd - Todo puzzle collector
USAGE:
GoPdd [global options] command [command options] [arguments...]
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--source value, -s value Source directory to parse ('.' by default) (default: ".")
--file value, -f value File to save JSON output into
--verbose, -v Enable verbose mode (a lot of logging) (default: false)
--skip-gitignore Don't look into .gitignore for excludes (default: false)
--skip-errors Suppress error as warning and skip badly formatted puzzles (default: false)
--rule value, -r value [ --rule value, -r value ] Rule to apply (can be used many times). Possible values: 'max-estimate:<int>', 'min-estimate:<int>', 'min-words:<int>', 'available-roles:<ROLENAME>,<ROLANME>...'
--include value, -n value [ --include value, -n value ] Glob pattern to include, e.g. "**/*.jpg"
--exclude value, -e value [ --exclude value, -e value ] Glob pattern to exclude, e.g. "**/*.jpg"
--help, -h show help
```
7 changes: 6 additions & 1 deletion cmd/gopdd/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"
"os"

Expand Down Expand Up @@ -87,6 +88,10 @@ func Run(ctx *cli.Context) error {
Rules: gopdd.RulesOf(rules),
Logger: logger,
}.JsonPuzzles(skipErrors)
err := os.WriteFile(file, []byte(output), 0644)
if file == "" {
fmt.Println(string(output))
return nil
}
err := os.WriteFile(file, output, 0644)
return err
}
7 changes: 5 additions & 2 deletions pkg/gopdd/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ func FindTodo(line string) (*TodoLine, error) {
if !strings.Contains(strings.ToLower(line), "todo") {
return nil, nil
}
re := regexp.MustCompile(`(.*(?:^|\s))(?:\x40todo|TODO:|TODO)\s+#([\w\-.:/]+)\s+(.+)`)
matches := re.FindStringSubmatch(line)
if len(matches) == 0 {
return nil, nil
}
formatErr := badFormat(line)
if formatErr != "" {
return nil, errors.New(formatErr)
}
re := regexp.MustCompile(`(.*(?:^|\s))(?:\x40todo|TODO:|TODO)\s+#([\w\-.:/]+)\s+(.+)`)
matches := re.FindStringSubmatch(line)
return &TodoLine{
line: matches[0],
prefix: matches[1],
Expand Down

0 comments on commit 07a2758

Please sign in to comment.