-
Notifications
You must be signed in to change notification settings - Fork 177
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
add supporting wildcard in windows #6
base: master
Are you sure you want to change the base?
Conversation
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.
Could you provide a command sample which would work with this change but otherwise doesn't.
main.go
Outdated
@@ -127,7 +137,7 @@ func addLicense(path string, fmode os.FileMode, typ string, data *copyrightData) | |||
lic, err = prefix(typ, data, "", ";; ", "") | |||
case ".erl": | |||
lic, err = prefix(typ, data, "", "% ", "") | |||
case ".hs": | |||
case ".hs", ".sql": |
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.
This is already added in #7
@@ -95,7 +95,17 @@ type file struct { | |||
mode os.FileMode | |||
} | |||
|
|||
func walk(ch chan<- *file, start string) { | |||
func walk(ch chan<- *file, path string) { | |||
matches, _ := filepath.Glob(path) |
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.
So, executing addlicense *
doesn't work on Windows?
What kind of "glob" works/doesn't natively on Windows and how much is it different from filepath.Glob
?
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.
Windows wildcards are handled by the program itself, so the program receives the *
text instead of matching files.
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.
Ok, sounds reasonable. Although PowerShell does support expansion.
Either way, I wonder what the implications are for the cases were a file name contains meta/expansion characters recognized by filepath.Match
. Currently, filepath.Glob
does this check:
// hasMeta reports whether path contains any of the magic characters
// recognized by Match.
func hasMeta(path string) bool {
// TODO(niemeyer): Should other magic characters be added here?
return strings.ContainsAny(path, "*?[")
}
What if a path is something like ./mydir[hello]
and it's passed verbatim in a shell which supports expansion like bash:
addlicense ./mydir\[hello\]/*
It might have undesirable effect, triggering filepath.Glob
to try and expand ./mydir[hello]
.
We could add separate files with +build
tags for Windows and Linux, but even on Windows, how would that work in DOS vs PowerShell without a confusion what expands/doesn't and at which point the expansion is done? Because I'm pretty sure filepath.Match
has different set of expansion rules compared to PowerShell.
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.
An alternative for Windows, when not in PowerShell, could be to have another separate little program called expand
and then feed the output of the expand
to addlicense
. It is probably out of scope for addlicense
repo though.
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.
@marcacohen maybe you have other ideas?
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.
PowerShell is also only partial command support, which is also command itself support, not PowerShell support.
So I don't think you have to worry about the difference DOS vs PowerShell.
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.
Passed verbatim in a shell which supports expansion, this is a problem.
Another alternative is to add a cmd line flag like -expand or -expand-glob,
false by default. Then, Windows users can enable it explicitly, whenever
needed.
…On Sun, 22 Jul 2018, 12:03 Shiming Zhang, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In main.go
<#6 (comment)>:
> @@ -95,7 +95,17 @@ type file struct {
mode os.FileMode
}
-func walk(ch chan<- *file, start string) {
+func walk(ch chan<- *file, path string) {
+ matches, _ := filepath.Glob(path)
Passed verbatim in a shell which supports expansion, this is a problem.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#6 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AABjPYKg1eQbZ7zYXT7Cs-DmGjMq_xn4ks5uJE3kgaJpZM4VT9tA>
.
|
If the use case here is 'addlicense *', then would a non-globbing work around would be 'addlicense .' ? I realize that does help the case of more refined globs (e.g. *.js) but I also feel like using Powershell (or Cygwin) might be acceptable vs. having to build essentially another mode into this comment ("local file globbing") or jump through other hoops for a limited range of use cases. How bad would it be to document this as a limitation of using addlicense with the dos shell? |
Another way to solve this is to move |
This also needs to distinguish between shells, preferably only in the case of dos shell. |
I thought last time you said:
Or did you mean something else? |
I got it wrong. no problem. |
No description provided.