Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ddddddO committed Jul 26, 2023
1 parent a185278 commit 035aa9a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ USAGE:
gtree [global options] command [command options] [arguments...]

VERSION:
1.9.2 / revision 136b147
1.9.3 / revision 136b147

COMMANDS:
output, o, out Outputs tree from markdown.
Expand Down Expand Up @@ -529,13 +529,11 @@ $ cat testdata/sample9.md
- main.go
~/github.com/ddddddO/gtree
$ cat testdata/sample9.md | gtree verify --strict
2023/07/25 01:04:04
Extra paths exist:
example/noexist
example/noexist/xxx
Required paths does not exist:
example/like_cli/kkk
exit status 1
```


Expand Down
5 changes: 5 additions & 0 deletions cmd/gtree/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const (
exitCodeErrOpen
exitCodeErrOutput
exitCodeErrMkdir
exitCodeErrVerify
)

func exitErrOpts(err error) cli.ExitCoder {
Expand All @@ -24,3 +25,7 @@ func exitErrOutput(err error) cli.ExitCoder {
func exitErrMkdir(err error) cli.ExitCoder {
return cli.Exit(err, exitCodeErrMkdir)
}

func exitErrVerify(err error) cli.ExitCoder {
return cli.Exit(err, exitCodeErrVerify)
}
8 changes: 2 additions & 6 deletions cmd/gtree/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"log"
"os"
"time"

Expand Down Expand Up @@ -206,7 +205,7 @@ func main() {
}

if err := app.Run(os.Args); err != nil {
log.Fatal(err)
fmt.Fprint(os.Stderr, err)
}
}

Expand Down Expand Up @@ -328,10 +327,7 @@ func actionVerify(c *cli.Context) error {
}

if err := verify(in, options); err != nil {
if errors.As(err, &gtree.VerifyError{}) {
return errors.New(fmt.Sprintf("\n%s", err.Error()))
}
return err
return exitErrVerify(err)
}
return nil
}
Expand Down
11 changes: 6 additions & 5 deletions simple_tree_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"io/fs"
"os"
"path/filepath"
"strings"
)

func newVerifierSimple(dir string, strict bool) verifierSimple {
targetDir := "."
if len(targetDir) != 0 {
if len(dir) != 0 {
targetDir = dir
}

Expand Down Expand Up @@ -48,7 +49,7 @@ func (dv *defaultVerifierSimple) verifyRoot(root *Node) ([]string, []string, err
}

dirsFilesystem := map[string]struct{}{}
existDirs := []string{}
extraDirs := []string{}
rootPath := root.path()
fileSystem := os.DirFS(filepath.Join(dv.targetDir, rootPath))
err := fs.WalkDir(fileSystem, ".", func(path string, d fs.DirEntry, err error) error {
Expand All @@ -64,7 +65,7 @@ func (dv *defaultVerifierSimple) verifyRoot(root *Node) ([]string, []string, err

if _, ok := dirsMarkdown[dir]; !ok {
// Markdownに無いパスがディレクトリに有る => strictモードでエラー
existDirs = append(existDirs, dir)
extraDirs = append(extraDirs, dir)
}

dirsFilesystem[dir] = struct{}{}
Expand All @@ -82,7 +83,7 @@ func (dv *defaultVerifierSimple) verifyRoot(root *Node) ([]string, []string, err
}
}

return existDirs, noExistDirs, nil
return extraDirs, noExistDirs, nil
}

func (dv *defaultVerifierSimple) recursive(node *Node, dirs map[string]struct{}) error {
Expand Down Expand Up @@ -129,5 +130,5 @@ func (v VerifyError) Error() string {
if len(v.noExists) != 0 {
msg += fmt.Sprintf("Required paths does not exist:\n%s", tabPrefix(v.noExists))
}
return msg
return strings.TrimSuffix(msg, "\n")
}
Binary file modified verify.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 035aa9a

Please sign in to comment.