https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112014-07-18T22:03:40ZRuby Issue Tracking SystemRuby master - Feature #10065: Make `gem env` command output valid YAMLhttps://bugs.ruby-lang.org/issues/10065?journal_id=478732014-07-18T22:03:40Zdrbrain (Eric Hodel)drbrain@segment7.net
<ul><li><strong>Category</strong> set to <i>lib/rubygems</i></li><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li><li><strong>Assignee</strong> set to <i>drbrain (Eric Hodel)</i></li></ul><p>Why does it need to be YAML?</p>
<p>I don't think it was ever intended to be YAML and with your change it will be too clumsy to be useful.</p> Ruby master - Feature #10065: Make `gem env` command output valid YAMLhttps://bugs.ruby-lang.org/issues/10065?journal_id=478742014-07-18T23:01:51Zdavid_macmahon (David MacMahon)davidm@astro.berkeley.edu
<ul></ul><p>It doesn't <em>need</em> to be YAML, but does it need <em>not</em> to be YAML? It is sooooo close already why not make it YAML? Besides, much of the info in the <code>GEM CONFIGURATION</code> section (where the only non-YAML syntax exists) comes from YAML files already (i.e. <code>${HOME}/.gemrc</code> and the system-wide <code>gemrc</code> file), so why output that in a different format?</p>
<p>How would the proposed change make it too clumsy to be useful? If anything, it makes it less clumsy to use. The current output of <code>gem environment</code> cannot be eval'd by Ruby, so what benefit does the rocket ship provide over the colon?</p>
<p>Without the proposed patch:</p>
<pre><code class="bash syntaxhl" data-language="bash"><span class="nv">$ </span>ruby <span class="nt">-r</span> pp <span class="nt">-r</span> yaml <span class="nt">-e</span> <span class="s1">'pp YAML.load `gem env`'</span>
/Users/davidm/local/lib/ruby/2.1.0/psych.rb:370:in <span class="sb">`</span>parse<span class="s1">': (<unknown>): did not find expected '</span>-<span class="s1">' indicator while parsing a block collection at line 16 column 6 (Psych::SyntaxError)
from /Users/davidm/local/lib/ruby/2.1.0/psych.rb:370:in `parse_stream'</span>
from /Users/davidm/local/lib/ruby/2.1.0/psych.rb:318:in <span class="sb">`</span>parse<span class="s1">'
from /Users/davidm/local/lib/ruby/2.1.0/psych.rb:245:in `load'</span>
from <span class="nt">-e</span>:1:in <span class="sb">`</span><main><span class="s1">'
</span></code></pre>
<p>Emulating the proposed patch at runtime:</p>
<pre><code class="bash syntaxhl" data-language="bash"><span class="nv">$ </span>ruby <span class="nt">-r</span> pp <span class="nt">-r</span> yaml <span class="nt">-e</span> <span class="s1">'pp YAML.load `gem env`.gsub(" =>",":")'</span>
<span class="o">{</span><span class="s2">"RubyGems Environment"</span><span class="o">=></span>
<span class="o">[{</span><span class="s2">"RUBYGEMS VERSION"</span><span class="o">=></span><span class="s2">"2.4.1"</span><span class="o">}</span>,
<span class="c"># etc...</span>
</code></pre> Ruby master - Feature #10065: Make `gem env` command output valid YAMLhttps://bugs.ruby-lang.org/issues/10065?journal_id=478782014-07-19T00:06:45Zdavid_macmahon (David MacMahon)davidm@astro.berkeley.edu
<ul></ul><p>I just realized that the current output is actually valid Markdown (at least Github Flavored Markdown). The proposed patch does not change that at all. It just makes the output valid (Github Flavored) Markdown <em>and</em> valid YAML!</p>
<p>The other ideas I allude to at the end of the original post would affect the Markdown aspect of the output, but let's keep those out of the current discussion (for now).</p> Ruby master - Feature #10065: Make `gem env` command output valid YAMLhttps://bugs.ruby-lang.org/issues/10065?journal_id=479402014-07-20T22:10:31Zdrbrain (Eric Hodel)drbrain@segment7.net
<ul></ul><p>I don't understand the value of loading the output of <code>gem env</code> as YAML when you can query the fields directly from RubyGems itself.</p>
<p>With the exception of subcommands of <code>gem env</code> such as <code>gem env path</code> and <code>gem env home</code> the output of gem commands is not API. I don't want to encourage parsing the output as YAML and I don't want people to clumsily jump through hoops (Hash inside a single-element Array) when real API exists.</p> Ruby master - Feature #10065: Make `gem env` command output valid YAMLhttps://bugs.ruby-lang.org/issues/10065?journal_id=479422014-07-20T22:54:42Zdavid_macmahon (David MacMahon)davidm@astro.berkeley.edu
<ul></ul><p>Eric Hodel wrote:</p>
<blockquote>
<p>I don't understand the value of loading the output of <code>gem env</code> as YAML when you can query the fields directly from RubyGems itself.</p>
</blockquote>
<p>In "Ruby-only" or "Ruby-dominant" environments I agree that there is little value. It would allow passing the RubyGems config to something (e.g. a diagnostic logger) that doesn't know about the RubyGems API.</p>
<p>In "Ruby-barely-tolerated" environments it is one small way to make RubyGems "play nicely" with the less enlightened.</p>
<blockquote>
<p>I don't want to encourage parsing the output as YAML</p>
</blockquote>
<p>Not encouraging and actively preventing are two different things. One of the great things about Ruby (IMHO) is that it gives developers lots of freedom to do what they want (even if it's not the "right" way to do things).</p>
<p>If you still feel strongly about actively preventing it from being valid YAML, then please feel free to reject this feature request.</p>