Skip to content

Commit

Permalink
docs: adds example for restrict to files.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcchavezs committed Sep 30, 2023
1 parent 6a5fe7f commit 01e8919
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ If you just want to list the files that porto would change vanity import, run:
```bash
porto -l path/to/library
```

## Inclusion/exclusion rules

`porto` skips autogenerated, internal, third party and vendored files by default. You can customize what files get included using some flags:
Expand All @@ -38,13 +39,22 @@ porto -l path/to/library
```bash
porto --skip-files ".*\\.pb\\.go$" path/to/library
```

- If you want to ignore directories (e.g. tooling directories), pass the `--skip-dirs` flag:

```bash
porto --skip-dirs "^tools$" path/to/library
```

- If you want to include `internal` folders and directories skipped by default:

```bash
porto --include-internal --skip-dirs-use-default=false path/to/library
```

- If you want to restrict to certain files e.g. `doc.go` you
can use:

```bash
porto --restrict-to-files "doc.go$" path/to/library
```
4 changes: 2 additions & 2 deletions cmd/porto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {
flagSkipDirs := flag.String("skip-dirs", "", "Regexps of directories to skip")
flagSkipDefaultDirs := flag.Bool("skip-dirs-use-default", true, "Use default skip directory list")
flagIncludeInternal := flag.Bool("include-internal", false, "Include internal folders")
restrictToFiles := flag.String("restrict-to-files", "", "Regexps of files to restrict the inspection on. It takes precedence over -skip-files and -skip-dirs")
flagRestrictToFiles := flag.String("restrict-to-files", "", "Regexps of files to restrict the inspection on. It takes precedence over -skip-files and -skip-dirs")
flag.Parse()

baseDir := flag.Arg(0)
Expand Down Expand Up @@ -49,7 +49,7 @@ Add import path to a folder
log.Fatalf("failed to build files regexes to exclude: %v", err)
}

restrictToFilesRegex, err := porto.GetRegexpList(*restrictToFiles)
restrictToFilesRegex, err := porto.GetRegexpList(*flagRestrictToFiles)
if err != nil {
log.Fatalf("failed to build files regexes to include: %v", err)
}
Expand Down

0 comments on commit 01e8919

Please sign in to comment.