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

How I can print something in console as a result? #3

Closed
bruha opened this issue Oct 27, 2022 · 7 comments
Closed

How I can print something in console as a result? #3

bruha opened this issue Oct 27, 2022 · 7 comments

Comments

@bruha
Copy link

bruha commented Oct 27, 2022

I added following post-merge husky hook:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx git-pull-run -p 'package-lock.json' -c 'echo "Some packages were changed. You may run npm install to update your dependencies..."'

Then run git reset --hard HEAD~20 && git pull to test it and got the following:

...
git-pull-run Started git-pull-run@1.0.2 +0ms
git-pull-run Found 1 change for pattern 'package-lock.json' +0ms
git-pull-run Running command 'echo "Some packages were changed. You may run npm install to update your dependencies..."' for change 'package-lock.json' in directory /Users/philip/Documents/nespresso/kissui... +1ms
git-pull-run Finished git-pull-run@1.0.2 +113ms

And I just want my text as an output, how can I do so?

@zirkelc
Copy link
Owner

zirkelc commented Oct 27, 2022

Hi @bruha

the command specified with -c is being executed in a separate child process and shell, that means any output is not available in the parent shell. If you add the debug flag -d (or --debug), you will also see the output from child processes:

npx git-pull-run --debug -p 'package-lock.json' -c 'echo "Some packages were changed. You may run npm install to update your dependencies..."'

Could you please try that and let me know if it works?

Nevertheless, I think what you want to achieve is a valid use case and I will implement a separate flag -e or --echo to print something into the console.

@bruha
Copy link
Author

bruha commented Oct 27, 2022

I got:

  git-pull-run:getChanges Match files with pattern 'package-lock.json': [ 'package-lock.json' ] +8ms
  git-pull-run Found 1 change for pattern 'package-lock.json' +0ms
  git-pull-run:getAbsolutePath Absolute path resolved:  +0ms
  git-pull-run Running command 'echo "Some packages were changed. You may run npm install to update your dependencies..."' for change 'package-lock.json' in directory ... +1ms
  git-pull-run:runCommand Running command 'echo "Some packages were changed. You may run npm install to update your dependencies..."' in directory +0ms
"Some packages were changed. You may run npm install to update your dependencies..."
  git-pull-run:runCommand Command executed with exit code: 0 +23ms
  git-pull-run Finished git-pull-run@1.0.2 +77ms

So yes, it would be great to have a special flag just for console output, thanks in advance @zirkelc !

@zirkelc
Copy link
Owner

zirkelc commented Oct 31, 2022

Hi @bruha,

I added a flag -m (--message) to print a message to console if changes for the given pattern were found. I published the package as release candidate to NPM. Could you try it and give me feedback?

You can install it with the @next tage like npm install git-pull-run@next.

I may add some coloring to make the message more apparent and I maybe I'll add some formatting options for the message in the future.

@bruha
Copy link
Author

bruha commented Nov 2, 2022

So I updated the hook to
npx git-pull-run@next -p 'package-lock.json' -m 'Some packages were changed. You may run "npm i" to update your dependencies'

and got basically what I need 🎉

git-pull-run Started git-pull-run@1.1.1-next.2 +0ms
git-pull-run Found 1 change for pattern 'package-lock.json' +0ms
git-pull-run Some packages were changed. You may run "npm i" to update your dependencies +1ms
git-pull-run Finished git-pull-run@1.1.1-next.2 +72ms

except these annoying git-pull-run Started and git-pull-run Finished 😁
I believe they should appear only with --debug flag

@zirkelc
Copy link
Owner

zirkelc commented Nov 2, 2022

Yes I agree that it is too verbose by default. I'm currently figuring out something else.

I will publish an update the next few days :-)

@zirkelc
Copy link
Owner

zirkelc commented Nov 8, 2022

@bruha I published an updated version as @next. The output now looks like that if only a message -m was specified:

2022-11-08_14-59-34

If a command -c or script -s was specified, these tasks will be listed separately:

2022-11-08_15-01-13

@bruha
Copy link
Author

bruha commented Nov 9, 2022

Thank you ❤️

@bruha bruha closed this as completed Nov 9, 2022
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

No branches or pull requests

2 participants