I got tired of seeing red messages in my provisioning script out, so I set 
out looking for a solution.

The problem, red lines from non errors makes it difficult to spot some 
genuine errors.

The requirements for a solution, accept any command and show green output 
for all commands that succeed.

The solution: a shell function that accepts a description and command, 
returns success messages for commands with a zero exit code, returns the 
output of a command for non zero exit codes.

I have decided to share the function with the vagrant community in the hope 
some of you find it useful. You can find the project on Github:

https://github.com/michaelward82/vagrant-provisioning-shell-function-helper

Example usage:

exe "Update apt indexes" \
    sudo apt-get update

Provisioning output:

==> Execute: Update apt indexes
==> ...      
==> ...      
==> ...      
==> ✔ Success

Example of the default vagrant output from a fully functioning provisioning 
script that calls openssl and php composer command:

<https://camo.githubusercontent.com/7033337f6da9b82c242f9bd029fd84e9b2c0151e/687474703a2f2f692e737461636b2e696d6775722e636f6d2f46334936582e706e67>

Example of the same script using my exe function:

<https://camo.githubusercontent.com/4ca5fea1131504b4adeab598abe9c9088e744168/687474703a2f2f692e737461636b2e696d6775722e636f6d2f757942726c2e706e67>

And output should there be a genuine error in your script:

<https://camo.githubusercontent.com/6812d9cef5b1838aef4cb93c88ddc37165b45349/687474703a2f2f692e737461636b2e696d6775722e636f6d2f36364564302e706e67>

This script function has only been used by myself and isn't widely battle 
tested. I'd love feedback and fixes for edge cases through Github. Hope 
this makes a few lives a little easier :)

-- 
This mailing list is governed under the HashiCorp Community Guidelines - 
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of 
those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
--- 
You received this message because you are subscribed to the Google Groups 
"Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vagrant-up/de91808d-6670-498e-ae09-a8c3123fd073%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to