summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorChuck <chuck@intelligence.org>2019-09-16 09:36:00 -0700
committerLinus Heckemann <git@sphalerite.org>2019-11-04 15:11:45 +0100
commit84d55716a9899954bc05b000287a54a59ee5aefe (patch)
tree6d3fa6e1c64610526adc7ec7079df4335dfc674c /nixos
parent2ddd2d07601d11f31f9bffa61060d680a1708b4c (diff)
downloadnixpkgs-84d55716a9899954bc05b000287a54a59ee5aefe.tar
nixpkgs-84d55716a9899954bc05b000287a54a59ee5aefe.tar.gz
nixpkgs-84d55716a9899954bc05b000287a54a59ee5aefe.tar.bz2
nixpkgs-84d55716a9899954bc05b000287a54a59ee5aefe.tar.lz
nixpkgs-84d55716a9899954bc05b000287a54a59ee5aefe.tar.xz
nixpkgs-84d55716a9899954bc05b000287a54a59ee5aefe.tar.zst
nixpkgs-84d55716a9899954bc05b000287a54a59ee5aefe.zip
Don't print header on stderr
Automated consumers can use 'sed 1d' or similar to remove this header.

This probably makes this output *easier* to consume correctly.  Having
this header show up in consumers' terminal or log output is probably not
useful, but hiding it without hiding all error messages would have been
more troublesome that just stripping it from stdout.

I.e., previously, unsophisticated use would show undesired output:
  $ some-other-tool
  This attribute set contains:
  This attribute set contains:
  This attribute set contains:
  This attribute set contains:
  <Actual some-other-tool output>

The simplest way to hide this undesired output would have been
nixos-option ... 2>/dev/null, which would hide all error messages.
We do not wish to encourage that.

Correct use would have been something like:
  nixos-option ... 2> >( grep --line-buffered -v 'This attribute set contains:')

After this change, correct use is simpler:
  nixos-option ... | sed 1d
or
  nixos-option ... | sed '1/This attribute set contains:/d'
if the caller don't know if this invocation of nixos-option will yield
an attribute listing or an option description.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/installer/tools/nixos-option/nixos-option.cc4
1 files changed, 1 insertions, 3 deletions
diff --git a/nixos/modules/installer/tools/nixos-option/nixos-option.cc b/nixos/modules/installer/tools/nixos-option/nixos-option.cc
index 174b7a0cbb6..2b95f9c9833 100644
--- a/nixos/modules/installer/tools/nixos-option/nixos-option.cc
+++ b/nixos/modules/installer/tools/nixos-option/nixos-option.cc
@@ -430,9 +430,7 @@ void printOption(Context & ctx, Out & out, const std::string & path, Value & opt
 
 void printListing(Out & out, Value & v)
 {
-    // Print this header on stderr rather than stdout, presumably to make it
-    // slightly easier to consume this output in other tools.
-    std::cerr << "This attribute set contains:\n";
+    out << "This attribute set contains:\n";
     for (const auto & a : v.attrs->lexicographicOrder()) {
         std::string name = a->name;
         if (!name.empty() && name[0] != '_') {