From 5f7d58f9ecf787a029ce0be316211aab3c6c2365 Mon Sep 17 00:00:00 2001 From: Serguei Okladnikov Date: Fri, 1 Apr 2016 18:10:42 +0000 Subject: [PATCH 1/2] allow multiple files for command line tool useful for prepare for printing multiple documents: github-markup repo/docs/* instead of echo repo/docs/* | xargs github-markup --- bin/github-markup | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/bin/github-markup b/bin/github-markup index 76e5e369..17ac1cab 100755 --- a/bin/github-markup +++ b/bin/github-markup @@ -3,8 +3,26 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib" require 'github/markup' -if ARGV[0] && File.exists?(file = ARGV[0]) - puts GitHub::Markup.render(file) -else - puts "usage: #$0 FILE" +if ARGV.size < 1 + print "usage: #$0 FILE [ FILES ... ]\n" + exit end + +sources = [] + +ARGV.each { |s| + begin + file = File.open( s, "r" ) + sources.push [ s, file ] + rescue Exception => e + print "error: #{e.message}\n" + ensure + end +} + +sources.each { |s| + name,file = s + print GitHub::Markup.render( name, file.read ) + file.close +} + From 75578714e1242aa3660dd052cb430923a4078d65 Mon Sep 17 00:00:00 2001 From: Serguei Okladnikov Date: Thu, 16 Mar 2017 13:11:18 +0400 Subject: [PATCH 2/2] return error code to shell --- bin/github-markup | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/github-markup b/bin/github-markup index 17ac1cab..0d442bb2 100755 --- a/bin/github-markup +++ b/bin/github-markup @@ -5,7 +5,7 @@ require 'github/markup' if ARGV.size < 1 print "usage: #$0 FILE [ FILES ... ]\n" - exit + exit 1 end sources = [] @@ -15,13 +15,13 @@ ARGV.each { |s| file = File.open( s, "r" ) sources.push [ s, file ] rescue Exception => e - print "error: #{e.message}\n" + $stderr.print "error: #{e.message}\n" + exit 1 ensure end } -sources.each { |s| - name,file = s +sources.each { |name, file| print GitHub::Markup.render( name, file.read ) file.close }