Permalink
Browse files

Fix --fetch. s/stdin\.txt/stdout.txt/

When piping to stdin without a file name, call the file stdout.txt as
that is the name of the source usually.

Fetch wasn't calling .join(), it was returning it. This is now fixed.

Signed-off-by: Tim Smart <tim@fostle.com>
  • Loading branch information...
1 parent 2393c21 commit adf64684cf87b89ad6832dde807df5a321826c5f @tim-smart committed Jul 3, 2012
Showing with 28 additions and 27 deletions.
  1. +4 −9 bin/gista
  2. +12 −9 docs/gista.html
  3. +12 −9 src/gista.coffee
View
@@ -84,7 +84,7 @@ ensureGistId = function(id) {
if (options.fetch) {
client = new Client;
return client.get("/" + (ensureGistId(options.fetch)), function(error, gist) {
- var buf, file, files, multiple, ret, _i, _len;
+ var file, files, multiple, ret, _i, _len;
if (error) {
throw error;
}
@@ -98,16 +98,11 @@ if (options.fetch) {
return process.stdout.write(gist.files[files[0]].content);
}
ret = [];
- buf = '';
for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i];
- buf += file + '\n';
- buf += new Array(file.length + 1).join('=');
- buf += '\n\n' + gist.files[file].content;
- ret.push(buf);
- buf = '';
+ ret.push([file, '\n', new Array(file.length + 1).join('='), '\n\n', gist.files[file].content].join(''));
}
- return console.log(ret.join);
+ return console.log(ret.join('\r\n'));
});
}
@@ -233,7 +228,7 @@ fromStdin = function() {
}
return createGist([
{
- name: options.name || 'stdin.txt',
+ name: options.name || 'stdout.txt',
content: data
}
]);
View
@@ -98,15 +98,18 @@
<span class="k">return</span> <span class="nx">process</span><span class="p">.</span><span class="nx">stdout</span><span class="p">.</span><span class="nx">write</span> <span class="nx">gist</span><span class="p">.</span><span class="nx">files</span><span class="p">[</span><span class="nx">files</span><span class="p">[</span><span class="mi">0</span><span class="p">]].</span><span class="nx">content</span>
<span class="nv">ret = </span><span class="p">[]</span>
- <span class="nv">buf = </span><span class="s">&#39;&#39;</span>
<span class="k">for</span> <span class="nx">file</span> <span class="k">in</span> <span class="nx">files</span>
- <span class="nx">buf</span> <span class="o">+=</span> <span class="nx">file</span> <span class="o">+</span> <span class="s">&#39;\n&#39;</span>
- <span class="nx">buf</span> <span class="o">+=</span> <span class="k">new</span> <span class="nb">Array</span><span class="p">(</span><span class="nx">file</span><span class="p">.</span><span class="nx">length</span> <span class="o">+</span> <span class="mi">1</span><span class="p">).</span><span class="nx">join</span> <span class="s">&#39;=&#39;</span>
- <span class="nx">buf</span> <span class="o">+=</span> <span class="s">&#39;\n\n&#39;</span> <span class="o">+</span> <span class="nx">gist</span><span class="p">.</span><span class="nx">files</span><span class="p">[</span><span class="nx">file</span><span class="p">].</span><span class="nx">content</span>
- <span class="nx">ret</span><span class="p">.</span><span class="nx">push</span> <span class="nx">buf</span>
- <span class="nv">buf = </span><span class="s">&#39;&#39;</span>
-
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="nx">ret</span><span class="p">.</span><span class="nx">join</span>
+ <span class="nx">ret</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span>
+ <span class="p">[</span> <span class="nx">file</span>
+ <span class="p">,</span> <span class="s">&#39;\n&#39;</span>
+ <span class="p">,</span> <span class="k">new</span> <span class="nb">Array</span><span class="p">(</span><span class="nx">file</span><span class="p">.</span><span class="nx">length</span> <span class="o">+</span> <span class="mi">1</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s">&#39;=&#39;</span><span class="p">)</span>
+ <span class="p">,</span> <span class="s">&#39;\n\n&#39;</span>
+ <span class="p">,</span> <span class="nx">gist</span><span class="p">.</span><span class="nx">files</span><span class="p">[</span><span class="nx">file</span><span class="p">].</span><span class="nx">content</span>
+ <span class="p">]</span>
+ <span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">)</span>
+ <span class="p">)</span>
+
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="nx">ret</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s">&#39;\r\n&#39;</span><span class="p">)</span>
<span class="nv">files = </span><span class="nx">options</span><span class="p">.</span><span class="nx">argv</span><span class="p">.</span><span class="nx">remain</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Are we generating a oauth token?</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">is_gentoken = </span><span class="nx">options</span><span class="p">.</span><span class="nx">gentoken</span> <span class="o">is</span> <span class="kc">yes</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Are we reading from stdin, or reading from a list of files?</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">is_stdin = </span><span class="nx">options</span><span class="p">.</span><span class="nx">argv</span><span class="p">.</span><span class="nx">remain</span><span class="p">.</span><span class="nx">length</span> <span class="o">is</span> <span class="mi">0</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>We need to exhaust all the cases where the github user and token
could be stored.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">loadConfig = </span><span class="nf">(callback) -&gt;</span>
@@ -182,7 +185,7 @@
<span class="nx">data</span> <span class="o">+=</span> <span class="nx">chunk</span>
<span class="nx">process</span><span class="p">.</span><span class="nx">stdin</span><span class="p">.</span><span class="kc">on</span> <span class="s">&#39;end&#39;</span><span class="p">,</span> <span class="o">-&gt;</span>
<span class="nx">process</span><span class="p">.</span><span class="nx">stdout</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="s">&quot;EOF\n&quot;</span><span class="p">)</span> <span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">verbose</span>
- <span class="nx">createGist</span> <span class="p">[</span><span class="nv">name: </span><span class="nx">options</span><span class="p">.</span><span class="nx">name</span> <span class="o">or</span> <span class="s">&#39;stdin.txt&#39;</span><span class="p">,</span> <span class="nv">content: </span><span class="nx">data</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>Iterate over every file and grab the contents, ready to pass
+ <span class="nx">createGist</span> <span class="p">[</span><span class="nv">name: </span><span class="nx">options</span><span class="p">.</span><span class="nx">name</span> <span class="o">or</span> <span class="s">&#39;stdout.txt&#39;</span><span class="p">,</span> <span class="nv">content: </span><span class="nx">data</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>Iterate over every file and grab the contents, ready to pass
onto <code>createGist</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">fromFiles = </span><span class="o">-&gt;</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s">&#39;Over 10 files.&#39;</span> <span class="k">if</span> <span class="nx">files</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">10</span>
View
@@ -119,15 +119,18 @@ if options.fetch
return process.stdout.write gist.files[files[0]].content
ret = []
- buf = ''
for file in files
- buf += file + '\n'
- buf += new Array(file.length + 1).join '='
- buf += '\n\n' + gist.files[file].content
- ret.push buf
- buf = ''
-
- console.log ret.join
+ ret.push(
+ [ file
+ , '\n'
+ , new Array(file.length + 1).join('=')
+ , '\n\n'
+ , gist.files[file].content
+ ]
+ .join('')
+ )
+
+ console.log ret.join('\r\n')
files = options.argv.remain
@@ -235,7 +238,7 @@ fromStdin = ->
data += chunk
process.stdin.on 'end', ->
process.stdout.write("EOF\n") if options.verbose
- createGist [name: options.name or 'stdin.txt', content: data]
+ createGist [name: options.name or 'stdout.txt', content: data]
# Iterate over every file and grab the contents, ready to pass
# onto `createGist`.

0 comments on commit adf6468

Please sign in to comment.