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

[hab,studio] Add noninteractive & no coloring modes via environment variables. #1682

Merged
merged 1 commit into from
Jan 31, 2017

Conversation

fnichol
Copy link
Collaborator

@fnichol fnichol commented Jan 27, 2017

The primary use case driving this feature is running builds in a CI environment. Some logging streams do not cope well with progress bar style output which behave by using carriage returns to the terminal to set its cursor back to the start of the line and "redraw" the current line. These logging streams frequently start outputting each progress tick/redraw as a full new line and very quickly consume a large amount of output. In systems such as Travis there is a upper bound to the number of log lines provided back to the user. As we care about the build output not spinners of doom, we needed a way to turn these off.

This change adds a way for users of Habitat tooling (such as hab, hab pkg build, hab studio, etc.) to explicitly drop single-line progress bar indicators or to disable text coloring by setting 2 new environment variables. As this feature is targeted for CI environments, environment variables were used so that the command issued in CI is virtually identical to the command issued on a developer's workstation. Additionally, running a hab pkg build will invoke a hab process which invokes a hab-studio process which may contain further hab subprocess before completing. The amount of work required to only support explicit flags on all the related tools would have made this feature much more complex and error prone. The choice of prefixing these environment variables with HAB_ ensures that there's almost no chance these variables would affect the build of any software and so can be safely passed over the Studio's barrier of isolation.

Currently, hab's UI system will check 2 things to determine its behavior:

  • Coloring is determined by checking the TERM environment variable to check the local terminfo database. If the TERM supports color, then hab will add ansi coloring.
  • Progress bars is determined by checking if the input and output streams (i.e. stdin, stdout, stderr) have a TTY assigned (using libc::isatty() or equivalent depending in platform).

This change checks an environment variable HAB_NONINTERACTIVE which if set to "true", will override the default detection logic and tell the UI that it does not have a TTY assigned. As a consequence, downloading and uploading progress bars will be disabled.

Additionally, another environment variable HAB_NOCOLORING is checked, and if set to "true" will disable all coloring from hab, hab-studio, hab-plan-build, etc.

tl;dr

To skip spinners in CI either:

env HAB_NONINTERACTIVE=true hab pkg build ...

or

export HAB_NONINTERACTIVE=true
hab pkg build ...

References #1280

gif-keyboard-4359273550099528466

@fnichol fnichol force-pushed the fnichol/noninteractive-mode branch from adc0548 to 33a2221 Compare January 28, 2017 12:15
VERBOSE Prints more verbose output (\`-v' flag overrides)
http_proxy Sets an http_proxy environment variable inside the Studio
https_proxy Sets an https_proxy environment variable inside the Studio
no_proxy Sets a no_proxy environment variable inside the Studio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mwrock
Copy link
Contributor

mwrock commented Jan 30, 2017

This is super great. I'd merge but think its important not to forget about the web docs.

…ariables.

The primary use case driving this feature is running builds in a CI
environment. Some logging streams do not cope well with progress bar
style output which behave by using carriage returns to the terminal to
set its cursor back to the start of the line and "redraw" the current
line. These logging streams frequently start outputting each progress
tick/redraw as a full new line and very quickly consume a large amount
of output. In systems such as Travis there is a upper bound to the
number of log lines provided back to the user. As we care about the
build output not spinners of doom, we needed a way to turn these off.

This change adds a way for users of Habitat tooling (such as `hab`, `hab
pkg build`, `hab studio`, etc.) to explicitly drop single-line progress
bar indicators or to disable text coloring by setting 2 new environment
variables. As this feature is targeted for CI environments, environment
variables were used so that the command issued in CI is virtually
identical to the command issued on a developer's workstation.
Additionally, running a `hab pkg build` will invoke a `hab` process
which invokes a `hab-studio` process which may contain further `hab`
subprocess before completing. The amount of work required to only
support explicit flags on all the related tools would have made this
feature much more complex and error prone. The choice of prefixing these
environment variables with `HAB_` ensures that there's almost no chance
these variables would affect the build of any software and so can be
safely passed over the Studio's barrier of isolation.

Currently, `hab`'s  UI system will check 2 things to determine its
behavior:

* Coloring is determined by checking the `TERM` environment variable to
  check the local terminfo database. If the `TERM` supports color, then
  `hab` will add ansi coloring.
* Progress bars is determined by checking if the input and output
  streams (i.e. stdin, stdout, stderr) have a TTY assigned (using
  `libc::isatty()` or equivalent depending in platform).

This change checks an environment variable `HAB_NONINTERACTIVE` which
if set to `"true"`, will override the default detection logic and tell
the UI that it does *not* have a TTY assigned. As a consequence,
downloading and uploading progress bars will be disabled.

Additionally, another environment variable `HAB_NOCOLORING` is checked,
and if set to `"true"` will disable all coloring from `hab`,
`hab-studio`, `hab-plan-build`, etc.

tl;dr
-----

To skip spinners in CI either:

    env HAB_NONINTERACTIVE=true hab pkg build ...

or

    export HAB_NONINTERACTIVE=true
    hab pkg build ...

References #1280

Signed-off-by: Fletcher Nichol <[email protected]>
@fnichol fnichol force-pushed the fnichol/noninteractive-mode branch from 33a2221 to 1c1a0e6 Compare January 31, 2017 18:47
@fnichol
Copy link
Collaborator Author

fnichol commented Jan 31, 2017

@mwrock Good call--I updated the docs and rebased. In all honesty it was a fluke that I found our hab-studio usage output and realized we were missing a couple entries. All better now!

@smurawski
Copy link
Contributor

@thesentinels approve

@thesentinels
Copy link
Contributor

🤘 I am testing your branch against master before merging it. We do this to ensure that the master branch is never failing tests.

@thesentinels
Copy link
Contributor

:neckbeard: Travis CI has started testing this PR.

@thesentinels
Copy link
Contributor

💖 Travis CI reports this PR passed.

It always makes me feel nice when humans approve of one anothers work. I'm merging this PR now.

I just want you and the contributor to answer me one question:

gif-keyboard-3280869874741411265

@thesentinels thesentinels merged commit 52dc949 into master Jan 31, 2017
@thesentinels thesentinels deleted the fnichol/noninteractive-mode branch January 31, 2017 19:49
@smith smith mentioned this pull request May 29, 2017
@eeyun eeyun added A-studio and removed Studio labels Jun 6, 2017
@bixu
Copy link
Contributor

bixu commented Feb 27, 2019

@fnichol / @eeyun, I think this is still broken-feeling. When I set HAB_NOCOLORING=true in my shell, I still see colored text in my Studio prompts. For me specifically this is a style issue (I prefer black-on-white text in my terminal for eye strain reasons), but I can also imaging this being an actual accessibility issue as well as problematic for certain types of automation.

Also a personal preference: I feel fairly strongly that a low-level tool like Habitat should have color turned OFF by default and only be toggled on by a user config/env var. Colored output has been a constant source of annoyance for me and my colleagues (for various reasons) since we adopted Habitat.
https://s3media.247sports.com/Uploads/Assets/762/405/3405762.gif

@christophermaier christophermaier added Focus: Studio Related to the Habitat Studio (core/hab-studio) component Type: Feature Issues that describe a new desired feature and removed A-studio labels Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Focus: Studio Related to the Habitat Studio (core/hab-studio) component Type: Feature Issues that describe a new desired feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants