lesser-evil/shell-verbosity-is-evil 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lesser-evil/shell-verbosity-is-evil

最新稳定版本:v1.0.0

Composer 安装命令:

composer require lesser-evil/shell-verbosity-is-evil

包简介

README 文档

README

The SHELL_VERBOSITY environment variable was introduced in symfony/console 3.4 and still appears in symfony/console 6.2. It defines a gooey, sticky form of verbosity.

The theory seems to be: if you call a command in verbose mode (-v), and if it calls any subcommands, then all those subcommands should also run in verbose mode. I suppose this is OK if the various commands follow simple, sequential procedures with outputs shown to a human.

But this convention is actively harmful when programs are composed in Unix-style. For simplicity, consider a Symfony Console command (snafu) which invokes a subcommand:

class SnafuCommand extends Command {
  public function execute(...) {
    shell_exec('find_data | filter_data > /tmp/my_data.json');
    $data = json_decode(file_get_contents('/tmp/my_data.json'));
  }
}

If you call snafu -v, then Symfony surrepetitiously sets SHELL_VERBOSITY=1 and propagates it to each subprocess. So filter_data receives SHELL_VERBOSITY=1 and begins outputting a processing log -- in addition to its regular JSON output. Now, the file /tmp/my_data.json is no longer JSON -- it is JSON plus random noise. So anything reading my_data.json will break.

The overall effect is to make the system flaky. Any Symfony-based command can cause this problem (by setting SHELL_VERBOSITY) or become broken by it (by accepting SHELL_VERBOSITY). If something breaks, you have to trawl the process-graph to find the two parties to the breakage. The breakage only happens when running snafu -v. If you run commands individually, or if you run snafu normally, then it works -- which will confound debugging efforts.

Of course, the reason to use -v is to debug something. If -v itself causes another bug, then you're investigating the combined behavior of two bugs.

How to remove SHELL_VERBOSITY

Friends don't let friends use SHELL_VERBOSITY. This repo defines an adapter to kill SHELL_VERBOSITY.

composer require lesser-evil/shell-verbosity-is-evil

In Symfony 3.4 - 6.2, the SHELL_VERBOSITY behavior is defined by Application::configureIO(). Override this:

use LesserEvil\ShellVerbosityIsEvil;

class MyApplication extends Application {
  protected function configureIO(InputInterface $input, OutputInterface $output) {
    ShellVerbosityIsEvil::doWithoutEvil(function() use ($input, $output) {
      parent::configureIO($input, $output);
    });
  }
}

统计信息

  • 总下载量: 77.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-02