Class: Script
- Inherits:
-
Object
- Object
- Script
- Defined in:
- lib/script.rb
Instance Method Summary collapse
-
#initialize(configdir, argv = []) ⇒ Script
constructor
A new instance of Script.
- #parse(arguments) ⇒ Object
Constructor Details
#initialize(configdir, argv = []) ⇒ Script
Returns a new instance of Script.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/script.rb', line 7 def initialize (configdir, argv = []) @halt = false @argv=argv @configfile = nil begin @config_dir = Directory.new(configdir) getconfigfiles rescue RuntimeError puts "Error: " + $!.to_s end end |
Instance Method Details
#parse(arguments) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/script.rb', line 161 def parse (arguments) if not arguments.nil? then @configfile_arguments = Array.new @rsync_arguments = Array.new infarg = Array.new #Information Arguments (--help or --version) @verbose = false @status = false begin arguments.each do |argv| case argv when "--version", "-V" infarg.push argv when "--help", "-h", "-?" infarg.push argv when "--list", "-l" infarg.push argv when "--verbose", "-v" @verbose=true when /^--pass-rsync=/ @rsync_arguments.push(argv.gsub(/^--pass-rsync=/, "")) when "--status", "-s" @status=true else if not @configfile_names.include? argv then raise "Unknown argument '#{argv}'!\nUse '--help' to see possible options." end @configfile_arguments.push(argv) end end if infarg.size == 0 then backup else if @configfile_arguments.size != 0 or @verbose == true or @rsync_arguments.size != 0 then raise "You cannot backup and use '#{infarg[0]}' at the same time." end infarg.uniq.each do |arg| case arg when "--version", "-V" print_version when "--help", "-h", "-?" print_help when "--list", "-l" puts "Available configfiles:" puts @configfile_names end end end rescue RuntimeError puts $! end end end |