homebrew-bundle icon indicating copy to clipboard operation
homebrew-bundle copied to clipboard

Feature Request: Respect `--quiet`/`-q` cli flag

Open maxcbc opened this issue 1 year ago • 9 comments

Problem Homebrew bundle has quite verbose output at times, such as the Using package_x output (source) when running brew bundle install.

brew bundle --help lists the standard homebrew --quiet/-q flag in its output, which is intended for use cases where the user wishes to suppress extraneous output. Currently homebrew bundle does not appear to respect this flag.

My Usecase I use homebrew bundle as part as my standard dotfiles setup to maintain a consistent development setup across multiple macos devices and to minimise disaster recovery time. As part of this, I run brew install --global --quiet --cleanup on every call to brew which would potentially change the state of my brewfile. I'd like the --quiet flag to reduce the output from this command, so that it only tells me if it is installing/uninstalling packages/casks from my system.

Solution Update homebrew bundle to respect the --quiet/-q flag by replacing relevant direct calls to puts with a custom log function which acts as a noop if the flag is active.

maxcbc avatar May 02 '23 08:05 maxcbc

Thanks for the good write-up. What would you expect the output to be with --quiet? Nothing unless there are errors?

MikeMcQuaid avatar May 02 '23 08:05 MikeMcQuaid

I think it is best to mirror the behaviour of the brew command, which I think would mean "Nothing unless there are errors" as you say.

Though, that aside, just as a cli user I'd expect:

  • quiet: log errors or prompts for input only (i.e. if something goes wrong or the user needs to elevate to sudo etc)
  • default: same as quiet, plus logging changes to the system (i.e. things being installed or removed).
  • verbose: same as default, plus logging where changes to the system aren't required (i.e. where something is already installed, etc).

The specific problem I'm trying to solve is that, when the system is already up to date with the brewfile, brew bundle install --global --quiet --cleanup will currently output $x+1$ lines i.e.

  • $x \times$ "Using <cask/package name>"
  • $1 \times$ "Homebrew Bundle complete! $x$ Brewfile dependencies now installed"

maxcbc avatar May 03 '23 06:05 maxcbc

  • quiet: log errors or prompts for input only (i.e. if something goes wrong or the user needs to elevate to sudo etc)

Agreed. I think the default and verbose already behaves as described so I think that'd be good scope for this issue.

@maxcbc Do you want to give this a go implementing it yourself? Happy to provide review and help on a partially working/CI failing draft PR?

MikeMcQuaid avatar May 03 '23 10:05 MikeMcQuaid

@MikeMcQuaid Sure. It'll probably be a few weeks before I can get to it, but a good opportunity to refresh my ruby skills. Watch this space 🙂

maxcbc avatar May 04 '23 06:05 maxcbc

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] avatar May 26 '23 00:05 github-actions[bot]

I'd like this as well.

hermitmaster avatar Jul 07 '23 14:07 hermitmaster

Let us know if you made some progress and stuck on something!

osalbahr avatar Jul 22 '23 07:07 osalbahr

Taking a look at this, there are 61 places we're using puts instead of calling a logging function.

@MikeMcQuaid Is there a reason not to use ohai for the majority of these? I see that at least cmd/bundle.rb uses onoe in a few places, implying that ohai is available.

colindean avatar Sep 17 '23 02:09 colindean

Taking a look at this, there are 61 places we're using puts instead of calling a logging function.

@MikeMcQuaid Is there a reason not to use ohai for the majority of these? I see that at least cmd/bundle.rb uses onoe in a few places, implying that ohai is available.

@colindean Yes. We should be using puts instead. This is what Homebrew/brew does. ohai is not any more of a logging function: it's just a puts with a prefix. Homebrew/brew also uses puts all over the place, intentionally.

MikeMcQuaid avatar Sep 18 '23 18:09 MikeMcQuaid