geode.thor
# Throws exit code 1 on errors
Throws exit code 1 on errors
Throws exit code 1 on errors
def start
    raise Error, 'ERROR: Only one of -d, -a and --load-only can be given' if options.count { |_k, v| v } > 1
    if options[:dev]
      ENV['CRYSTALS_TO_LOAD'] = Dir['app/dev/*.rb'].join(',')
    elsif options[:all]
      ENV['CRYSTALS_TO_LOAD'] = (Dir['app/main/*.rb'] + Dir['app/dev/*.rb']).join(',')
    elsif options[:load_only]
      all_crystal_paths = Dir['app/main/*.rb'] + Dir['app/dev/*.rb']
      ENV['CRYSTALS_TO_LOAD'] = options[:load_only].map do |crystal_name|
        if (paths = all_crystal_paths.select { |p| File.basename(p, '.*').camelize == crystal_name }).empty?
          raise Error, "ERROR: Crystal #{crystal_name} not found"
        elsif paths.size > 1
          raise Error, "ERROR: Multiple crystals with name #{crystal_name} found"
        else paths[0]
        end
      end.join(',')
    else
      ENV['CRYSTALS_TO_LOAD'] = Dir['app/main/*.rb'].join(',')
    end
    load File.expand_path('app/bot.rb')
  end
def start raise Error , 'ERROR: Only one of -d, -a and --load-only can be given' if options . count { | _k , v | v } > 1 if options [ :dev ] ENV [ 'CRYSTALS_TO_LOAD' ] = Dir [ 'app/dev/*.rb' ] . join ( ',' ) elsif options [ :all ] ENV [ 'CRYSTALS_TO_LOAD' ] = ( Dir [ 'app/main/*.rb' ] + Dir [ 'app/dev/*.rb' ] ) . join ( ',' ) elsif options [ :load_only ] all_crystal_paths = Dir [ 'app/main/*.rb' ] + Dir [ 'app/dev/*.rb' ] ENV [ 'CRYSTALS_TO_LOAD' ] = options [ :load_only ] . map do | crystal_name | if ( paths = all_crystal_paths . select { | p | File . basename ( p , '.*' ) . camelize == crystal_name } ) . empty? raise Error , "ERROR: Crystal #{crystal_name} not found" elsif paths . size > 1 raise Error , "ERROR: Multiple crystals with name #{crystal_name} found" else paths [ 0 ] end end . join ( ',' ) else ENV [ 'CRYSTALS_TO_LOAD' ] = Dir [ 'app/main/*.rb' ] . join ( ',' ) end load File . expand_path ( 'app/bot.rb' ) end
Throws exit code 1 on errors
Throws exit code 1 on errors
# Validates that only one option is given # Selects the crystals to load, throwing an error if a crystal given in load_only is not found # Loads the bot script