#!/usr/bin/env ruby require 'markdown_helper' # Each command foo has a corresponding Ruby executable _foo. def command_keywords dir_path = File.dirname(__FILE__) dirs = Dir.entries(dir_path) command_file_names = dirs.select{ |x| x.start_with?('_')} command_file_names.collect {|x| x.sub(/^_/, '')} end def usage puts <<-EOT Usage: markdown_helper command [options] [args] where * Command is one of #{command_keywords.inspect}. EOT exit end command_keyword = ARGV[0] unless command_keywords.include?(command_keyword) usage end bindir = File.dirname(__FILE__) bin_file_path = File.absolute_path(File.join( bindir, '_' + command_keyword, )) command = "ruby #{bin_file_path} #{ARGV.join(' ')}" system(command)