Class: Cyclops
- Inherits:
-
Object
- Object
- Cyclops
- Defined in:
- lib/cyclops/option_parser_extension.rb,
lib/cyclops.rb,
lib/cyclops/version.rb
Overview
–
#
cyclops – A command-line option parser #
#
Copyright © 2014 Jens Wille #
#
Authors: #
Jens Wille <jens.wille@gmail.com> #
#
cyclops is free software; you can redistribute it and/or modify it under # the terms of the GNU Affero General Public License as published by the Free # Software Foundation; either version 3 of the License, or (at your option) # any later version. #
#
cyclops is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for # more details. #
#
You should have received a copy of the GNU Affero General Public License # along with cyclops. If not, see <www.gnu.org/licenses/>. #
#
++
Defined Under Namespace
Modules: OptionParserExtension, Version
Constant Summary collapse
- VERSION =
Version.to_s
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#prog ⇒ Object
Returns the value of attribute prog.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Class Method Summary collapse
Instance Method Summary collapse
- #execute(arguments = ARGV, *inouterr) ⇒ Object
-
#initialize(defaults = nil, *args) ⇒ Cyclops
constructor
A new instance of Cyclops.
- #progname ⇒ Object
- #reset(stdin = STDIN, stdout = STDOUT, stderr = STDERR) ⇒ Object
- #run(arguments) ⇒ Object
- #usage ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(defaults = nil, *args) ⇒ Cyclops
Returns a new instance of Cyclops.
71 72 73 74 75 76 77 78 |
# File 'lib/cyclops.rb', line 71 def initialize(defaults = nil, *args) @defaults, @prog = defaults || self.class.defaults, $0 init(*args) # prevent backtrace on ^C trap(:INT) { exit 130 } end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
66 67 68 |
# File 'lib/cyclops.rb', line 66 def config @config end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
66 67 68 |
# File 'lib/cyclops.rb', line 66 def defaults @defaults end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
66 67 68 |
# File 'lib/cyclops.rb', line 66 def end |
#prog ⇒ Object
Returns the value of attribute prog.
69 70 71 |
# File 'lib/cyclops.rb', line 69 def prog @prog end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
67 68 69 |
# File 'lib/cyclops.rb', line 67 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
67 68 69 |
# File 'lib/cyclops.rb', line 67 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
67 68 69 |
# File 'lib/cyclops.rb', line 67 def stdout @stdout end |
Class Method Details
.defaults ⇒ Object
44 45 46 |
# File 'lib/cyclops.rb', line 44 def defaults {} end |
.execute(*args) ⇒ Object
48 49 50 |
# File 'lib/cyclops.rb', line 48 def execute(*args) new.execute(*args) end |
.usage(prog) ⇒ Object
36 37 38 |
# File 'lib/cyclops.rb', line 36 def usage(prog) "Usage: #{prog} [-h|--help] [options]" end |
.version ⇒ Object
40 41 42 |
# File 'lib/cyclops.rb', line 40 def version parent_const_get(:VERSION) end |
Instance Method Details
#execute(arguments = ARGV, *inouterr) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/cyclops.rb', line 92 def execute(arguments = ARGV, *inouterr) reset(*inouterr) (arguments) run(arguments) rescue => err raise if $VERBOSE abort err.is_a?(OptionParser::ParseError) ? "#{err}\n#{usage}" : "#{err.backtrace.first}: #{err} (#{err.class})" ensure .each_value { |value| value.close if value.is_a?(Zlib::GzipWriter) } end |
#progname ⇒ Object
80 81 82 |
# File 'lib/cyclops.rb', line 80 def progname File.basename(prog) end |
#reset(stdin = STDIN, stdout = STDOUT, stderr = STDERR) ⇒ Object
108 109 110 111 |
# File 'lib/cyclops.rb', line 108 def reset(stdin = STDIN, stdout = STDOUT, stderr = STDERR) @stdin, @stdout, @stderr = stdin, stdout, stderr , @config = {}, {} end |
#run(arguments) ⇒ Object
104 105 106 |
# File 'lib/cyclops.rb', line 104 def run(arguments) raise NotImplementedError, 'must be implemented by subclass' end |
#usage ⇒ Object
84 85 86 |
# File 'lib/cyclops.rb', line 84 def usage self.class.usage(prog) end |
#version ⇒ Object
88 89 90 |
# File 'lib/cyclops.rb', line 88 def version self.class.version end |