wagoodman / bashful

Use a yaml file to stitch together commands and bash snippits and run them with a bit of style. Why? Because your bash script should be quiet and shy-like (...and not such a loud mouth).
MIT License
1.15k stars 47 forks source link

Show stdout instead of stderr? #62

Open alexislefebvre opened 6 years ago

alexislefebvre commented 6 years ago

Here is my script:

tasks:
    - name: phpqa
      parallel-tasks: 
        - name: PHPStan
          cmd: docker run -t -w /project jakzal/phpqa:alpine phpstan analyse --no-progress EXAMPLE

Here is the output:

Running /home/alexis/scripts/phpqa.yaml
    • phpqa                     
      ╰─ PHPStan                   Exited with error (1)
      100.00% Complete  Tasks[1/1] See log for details (/dev/null) Runtime[00:00:00]
 ...Some tasks failed, see below for details.

⏺ Failed task: PHPStan
  ├─ command: docker run -t -w /project jakzal/phpqa:alpine phpstan analyse --no-progress EXAMPLE
  ├─ return code: 1
  ╰─ stderr: 

There's no output.


I add 1>&2 to the end of the command.

Here is the output:

$ bashful run ~/scripts/phpqa.yaml
Running /home/alexis/scripts/phpqa.yaml
    • phpqa                     
      ╰─ PHPStan                   Exited with error (1)
      100.00% Complete  Tasks[1/1] See log for details (/dev/null)    Runtime[00:00:01]
 ...Some tasks failed, see below for details.

⏺ Failed task: PHPStan
  ├─ command: docker run -t -w /project jakzal/phpqa:alpine phpstan analyse --no-progress EXAMPLE 1>&2
  ├─ return code: 1
  ╰─ stderr:  ------ -------------------------------------- 
  Line   EXAMPLE                               
 ------ -------------------------------------- 
         Path /project/EXAMPLE does not exist  
 ------ -------------------------------------- 

 [ERROR] Found 1 error                                                                          

I have to use 1>&2 because the command outputs result on stdout instead of stderr.

Is it possible to display stdout instead of strerr id a command fails? Could it be configurable for each command?

wagoodman commented 6 years ago

It is possible to do this, but it already is questionable to buffer the stderr as it is. That is, if there is a substantial amount of stdout from an application (which is more typically expected than a lot of stderr output) then you'l start running out of memory for tracking the output for several tasks that have a lot of output.

That being said, it is certainly possible and there are some simple steps that can be taken to capturing "just enough" output (such as a circular buffer like this: https://github.com/armon/circbuf). We could add options for capturing either or both stdout and stderr on failure:

tasks:
    - name: phpqa
      parallel-tasks: 
        - name: PHPStan
          cmd: ...
          stderr-on-failure: false
          stdout-on-failure: true

or globally for all tasks:

config:
  stderr-on-failure: false
  stdout-on-failure: true
tasks:
    - name: phpqa
      parallel-tasks: 
        - name: PHPStan
          cmd: ...