cakephp-ide-helper
cakephp-ide-helper copied to clipboard
Annotate specific files only
Hello, Is it feasible to annotate specific files only? I need to run the 'annotate' command only for the amended files, before doing a git commit, not always for all files.
Sure
right now you can already filter it using -f FooBar...
But you could also implement a git diff based run (only files that have been touched) etc.
The idea is good, feel free to PR a git diff based filtering as e.g. --diff
etc
Hi,
The command I need looks like bin/cake annotations all --filter edit
, but it will annotate all the 'edit.ctp' files, not only the file I amended.
Also we cannot pass multiple files to the command i.e: files with their paths, separated by a comma.
Could it be possbile to specify the file path instead of searching for the file?
Sure But why not --diff then directly?
To have an idea, here is what I currently implemented:
STAGED_FILES=$(git diff --name-only --cached --diff-filter=ACMR HEAD -- '*.php' '*.ctp')
for STAGED_FILE in $STAGED_FILES; do
FILE_NAME="${STAGED_FILE##*/}"
bin/cake annotations all --filter ${FILE_NAME%.*} // file name without path and extension, the way it works
done
The code above will also annotate the files which have exactly the same name as the amended files. The goal is to annotate the amended files only. To achieve that, we need to specify the file paths as well in the annotate command, is that right?
I was expecting to have just one line of code, as it is possible for the php-cs-fixer library:
bin/cake annotations all --filter "$STAGED_FILES"
My current issue is that when I specify the path as well, the file is not found to be annotated. May I know how could we handle that?
We could either make --filter smarter, or we use a different --path element to check specific paths only. Feel free to make a PR and see if that works.
Alright, since we need only specific files (with full paths and extensions) to be annotated, we could check, if the value entered in the --filter
, is a file and the file exists, then we just use the value instead of the search for the files (as currently it does).
We could also add the ability to handle multiple files with full paths (separated by a space) i.e:
bin/cake annotations all --filter /path/file1 /path/file2
instead of space, comma separated might work
Alright, as soon as I do the update, will open a PR
Did you have a chance to look into this further?
ping @vidrascus