Created
August 28, 2014 16:40
-
-
Save Phrogz/f867101f7c3de9c42837 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USAGE = <<ENDUSAGE | |
Usage: | |
docubot [-h] [-v] [create [-s shell] [-f]] directory [-w writer] [-o output_file] [-n] [-l log_file] | |
ENDUSAGE | |
HELP = <<ENDHELP | |
-h, --help Show this help. | |
-v, --version Show the version number (#{DocuBot::VERSION}). | |
create Create a starter directory filled with example files; | |
also copies the template for easy modification, if desired. | |
-s, --shell The shell to copy from. | |
Available shells: #{DocuBot::SHELLS.join(', ')} | |
-f, --force Force create over an existing directory, | |
deleting any existing files. | |
-w, --writer The output type to create [Defaults to 'chm'] | |
Available writers: #{DocuBot::Writer::INSTALLED_WRITERS.join(', ')} | |
-o, --output The file or folder (depending on the writer) to create. | |
[Default value depends on the writer chosen.] | |
-n, --nopreview Disable automatic preview of .chm. | |
-l, --logfile Specify the filename to log to. | |
ENDHELP | |
ARGS = { :shell=>'default', :writer=>'chm' } | |
UNFLAGGED_ARGS = [ :directory ] | |
next_arg = UNFLAGGED_ARGS.first | |
ARGV.each{ |arg| | |
case arg | |
when '-h','--help' then ARGS[:help] = true | |
when 'create' then ARGS[:create] = true | |
when '-f','--force' then ARGS[:force] = true | |
when '-n','--nopreview' then ARGS[:nopreview] = true | |
when '-v','--version' then ARGS[:version] = true | |
when '-s','--shell' then next_arg = :shell | |
when '-w','--writer' then next_arg = :writer | |
when '-o','--output' then next_arg = :output | |
when '-l','--logfile' then next_arg = :logfile | |
else | |
if next_arg | |
ARGS[next_arg] = arg | |
UNFLAGGED_ARGS.delete( next_arg ) | |
end | |
next_arg = UNFLAGGED_ARGS.first | |
end | |
} | |
if ARGS[:version] | |
puts "DocuBot v#{DocuBot::VERSION}" | |
end | |
if ARGS[:help] or !ARGS[:directory] | |
puts USAGE unless ARGS[:version] | |
puts HELP if ARGS[:help] | |
exit | |
end | |
if ARGS[:logfile] | |
$stdout.reopen( ARGS[:logfile], "w" ) | |
$stdout.sync = true | |
$stderr.reopen( $stdout ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment