cakephp-ide-helper icon indicating copy to clipboard operation
cakephp-ide-helper copied to clipboard

Annotate specific files only

Open vidrascus opened this issue 4 years ago • 15 comments

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.

vidrascus avatar Jul 28 '20 09:07 vidrascus

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.

dereuromark avatar Jul 28 '20 09:07 dereuromark

The idea is good, feel free to PR a git diff based filtering as e.g. --diff etc

dereuromark avatar Jul 28 '20 10:07 dereuromark

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?

vidrascus avatar Jul 28 '20 14:07 vidrascus

Sure But why not --diff then directly?

dereuromark avatar Jul 28 '20 14:07 dereuromark

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 

vidrascus avatar Jul 28 '20 14:07 vidrascus

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?

vidrascus avatar Jul 28 '20 15:07 vidrascus

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"

vidrascus avatar Jul 28 '20 15:07 vidrascus

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?

vidrascus avatar Jul 28 '20 15:07 vidrascus

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.

dereuromark avatar Jul 28 '20 15:07 dereuromark

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).

vidrascus avatar Jul 28 '20 15:07 vidrascus

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

vidrascus avatar Jul 28 '20 15:07 vidrascus

instead of space, comma separated might work

dereuromark avatar Jul 28 '20 15:07 dereuromark

Alright, as soon as I do the update, will open a PR

vidrascus avatar Jul 28 '20 15:07 vidrascus

Did you have a chance to look into this further?

dereuromark avatar Aug 13 '20 12:08 dereuromark

ping @vidrascus

dereuromark avatar Nov 25 '21 17:11 dereuromark