-
Notifications
You must be signed in to change notification settings - Fork 9
add two new flags for glob support #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ksdpmx
wants to merge
1
commit into
containerd:master
Choose a base branch
from
ksdpmx:glob
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,10 @@ type Applier interface { | |
|
|
||
| // TagContext keeps context info for Applier | ||
| type TagContext struct { | ||
| ppath string | ||
| excludeList []string | ||
| excludeDirs []string | ||
| excludeFiles []string | ||
| templatePath string | ||
| templateFiles TemplateFiles | ||
| dryRun bool | ||
|
|
@@ -44,6 +47,8 @@ type TemplateFiles struct { | |
| func main() { | ||
| ppath := flag.String("path", ".", "project path") | ||
| excludes := flag.String("excludes", "vendor", "exclude folders") | ||
| excludedirs := flag.String("exclude-dirs", ".git .svn vendor", "exclude dirs matching with glob patterns") | ||
| excludefiles := flag.String("exclude-files", "LICENSE MAINTAINERS", "exclude files matching with glob patterns") | ||
| tpath := flag.String("t", "./template", "template files path") | ||
| dryRun := flag.Bool("check", false, "check files missing header") | ||
| verbose := flag.Bool("v", false, "verbose output") | ||
|
|
@@ -82,6 +87,8 @@ func main() { | |
| } | ||
|
|
||
| excludeList := strings.Split(*excludes, " ") | ||
| excludeDirs := strings.Split(*excludedirs, " ") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if a file path contains a space?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to use https://pkg.go.dev/github.com/spf13/pflag#StringSlice |
||
| excludeFiles := strings.Split(*excludefiles, " ") | ||
|
|
||
| templateFiles := TemplateFiles{ | ||
| mTemplateFile: makeTFile, | ||
|
|
@@ -90,10 +97,14 @@ func main() { | |
| dTemplateFile: dTFile} | ||
|
|
||
| t := TagContext{ | ||
| ppath: *ppath, | ||
| excludeList: excludeList, | ||
| excludeDirs: excludeDirs, | ||
| excludeFiles: excludeFiles, | ||
| templateFiles: templateFiles, | ||
| templatePath: *tpath, | ||
| dryRun: *dryRun} | ||
| dryRun: *dryRun, | ||
| } | ||
|
|
||
| if err = filepath.Walk(*ppath, t.tagFiles); err != nil { | ||
| panic(err) | ||
|
|
@@ -118,10 +129,27 @@ func (t *TagContext) tagFiles(path string, f os.FileInfo, err error) error { | |
| var applier Applier | ||
| processed := false | ||
|
|
||
| relpath, err := filepath.Rel(t.ppath, path) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if (f.Mode() & os.ModeSymlink) != 0 { // skip symlinks | ||
| return nil | ||
| } | ||
|
|
||
| if f.IsDir() { | ||
| for _, dir := range t.excludeDirs { | ||
| if matched, err := filepath.Match(dir, relpath); err != nil { | ||
| return err | ||
| } else { | ||
| if matched { | ||
| return filepath.SkipDir | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (f.Name() == ".git" || f.Name() == ".svn" || f.Name() == "..") && f.IsDir() { | ||
| return filepath.SkipDir | ||
| } | ||
|
|
@@ -134,6 +162,18 @@ func (t *TagContext) tagFiles(path string, f os.FileInfo, err error) error { | |
| } | ||
| } | ||
|
|
||
| if !f.IsDir() && f.Size() > 0 { | ||
| for _, file := range t.excludeFiles { | ||
| if matched, err := filepath.Match(file, relpath); err != nil { | ||
| return err | ||
| } else { | ||
| if matched { | ||
| return nil | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if !f.IsDir() && f.Size() > 0 { | ||
|
|
||
| if f.Name() == "LICENSE" || f.Name() == "MAINTAINERS" { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the flag name it is not clear how this differs from
excludes