Sha256: aa16ae0b6ef49be5dbb944d0341971bf1e34cffc421ff046caa8d5125b5764ea

Contents?: true

Size: 1.07 KB

Versions: 17

Compression:

Stored size: 1.07 KB

Contents

module Eco
  class Scripting
    module Lib
      def is_modifier?(value)
       value&.start_with?("-")
      end

      def get_arg(key, with_param: false, valid: true)
       return nil if !ARGV.include?(key)
       value = true
       if with_param
         next_i = ARGV.index(key) + 1
         value = ARGV[next_i]
         #puts "modifier argument: #{value}"
         value = nil if valid && is_modifier?(value)
       end
       return value
      end

      def get_file(key, required: false, should_exist: true)
        filename = get_arg(key, with_param: true)
        if !filename
            if required
              puts "you need to specify a file '#{key} file'"
              exit
            end
        elsif  !(File.exists?(filename) || File.exists?(File.expand_path(filename)))
          if should_exist && required
            puts "file doesn't exist #{filename}"
            exit
          end
        end

        filename = File.expand_path(filename) if filename && should_exist
        filename
      end
      
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
eco-helpers-0.7.1 lib/eco/scripting/arguments.rb
eco-helpers-0.6.17 lib/eco/scripting/arguments.rb
eco-helpers-0.6.16 lib/eco/scripting/arguments.rb
eco-helpers-0.6.15 lib/eco/scripting/arguments.rb
eco-helpers-0.6.13 lib/eco/scripting/arguments.rb
eco-helpers-0.6.12 lib/eco/scripting/arguments.rb
eco-helpers-0.6.11 lib/eco/scripting/arguments.rb
eco-helpers-0.6.9 lib/eco/scripting/arguments.rb
eco-helpers-0.6.8 lib/eco/scripting/arguments.rb
eco-helpers-0.6.7 lib/eco/scripting/arguments.rb
eco-helpers-0.6.6 lib/eco/scripting/arguments.rb
eco-helpers-0.6.5 lib/eco/scripting/arguments.rb
eco-helpers-0.6.4 lib/eco/scripting/arguments.rb
eco-helpers-0.6.3 lib/eco/scripting/arguments.rb
eco-helpers-0.6.2 lib/eco/scripting/arguments.rb
eco-helpers-0.6.1 lib/eco/scripting/arguments.rb
eco-helpers-0.6.0 lib/eco/scripting/arguments.rb