Skip to content
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

file type not supported, path=Makefile #9

Open
ianlewis opened this issue Nov 26, 2024 · 3 comments · Fixed by #10
Open

file type not supported, path=Makefile #9

ianlewis opened this issue Nov 26, 2024 · 3 comments · Fixed by #10

Comments

@ianlewis
Copy link
Contributor

Is your feature request related to a problem? Please describe.

When running nwa on a repository it doesn't add license headers to Makefile.

# Makefile has no license header.
$ nwa add -c "Ian Lewis" -l apache .
[NWA SUMMARY] modified=0 skipped=0 failed=0

It also doesn't work when specifying the file directly.

$ nwa add -c "Ian Lewis" -l apache Makefile 
2024/11/26 06:34:42 WARN file type not supported, header generated failed path=Makefile
[NWA SUMMARY] modified=0 skipped=0 failed=1

Describe the solution you'd like

nwa should add license headers to the specified Makefile as well as process makefiles when given a directory as input.

Describe alternatives you've considered

n/a

Additional context

n/a

@justlorain
Copy link
Member

Thank you for your report!

BTW, since nwa uses patterns supported by doublestar for path matching, . actually does not match any pattern. In other words, nwa add -c "Ian Lewis" -l apache . will not operate on any files.

If you want to achieve the effect of ., you can use ** instead. Below is an example from the readme's Update section, which might help you understand:

nwa update -l apache -c "BINARY Members" -s "dirA/**" -s "dirB/**/*.py" "**"

The command in the example above updates the license header of all files in the current directory, except for all files under dirA and Python files under dirB, to:

  • License type: Apache 2.0
  • Copyright holder: BINARY Members
  • Copyright year: current year

regardless of the previous license header.

@ianlewis
Copy link
Contributor Author

Thank you for your report!

BTW, since nwa uses patterns supported by doublestar for path matching, . actually does not match any pattern. In other words, nwa add -c "Ian Lewis" -l apache . will not operate on any files.

If you want to achieve the effect of ., you can use ** instead. Below is an example from the readme's Update section, which might help you understand:

nwa update -l apache -c "BINARY Members" -s "dirA/**" -s "dirB/**/*.py" "**"

Indeed. I found this a bit unintuitive but I can understand the use of doublestar.

Also, since nwa always operates in the current directory nwa add ../path/to/file doesn't seem to work. This is due to filepath.WalkDir not traveling outside the root directory of '.'.

@justlorain
Copy link
Member

In versions up to and including v0.3.2, NWA directly passed the user-provided path to the filepath.WalkDir function. However, filepath.WalkDir does not support certain patterns, such as src/**/*.go, if you want to match .go files in the src folder and all its subfolders. To handle this kind of requirement, you might need to implement a solution similar to google/addlicense#136.

Starting from version v0.4.0, I switched to scanning the . directory and then using doublestar to match the user-provided patterns. This approach also aligns better with how the --skip flag is used.

Currently, I haven’t found a better implementation. I think the trade-off of not supporting paths outside . is acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants