Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
Allow provide custom path to servers config
Browse files Browse the repository at this point in the history
  • Loading branch information
miry committed Sep 9, 2020
1 parent 5c67aa1 commit b53023a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -163,6 +163,14 @@ lak_us:
- `server_name` is the text name that you can copy from the login page after you inpuit the credentials.
- `server_url` is the login url
# Config path
The default path servers config is `config/servers.yml`. It could be overide via option `--config` or `-c`:
```
$ bundle exec ruby runner.rb -c config.yml
```
### Actions
- `build_first` - Create a first building in the list. The order of buidlings get from `:buildings`
Expand Down
23 changes: 19 additions & 4 deletions runner.rb
Expand Up @@ -15,6 +15,21 @@
require_relative 'bot/lords_and_knights_v3'
require_relative 'bot/travian'

# Parse options
require 'optparse'

options = {
config: 'config/servers.yml'
}

OptionParser.new do |opts|
opts.banner = "Usage: runner.rb [options]"

opts.on("-cCONFIG", "--config=CONFIG", "Path to servers config. Default: config/servers.yml") do |c|
options[:config] = c
end
end.parse!

choose_driver = ARGV.first || :chrome_headless
choose_driver = choose_driver.to_sym

Expand Down Expand Up @@ -73,16 +88,16 @@
end
end

def servers
def servers(options)
if ENV.key?('SERVERS_JSON')
return JSON.parse(ENV['SERVERS_JSON'], symbolize_names: true)
elsif File.exists?('config/servers.yml')
return YAML.load(File.read('config/servers.yml'), symbolize_names: true)
elsif File.exists?(options[:config])
return YAML.load(File.read(options[:config]), symbolize_names: true)
end
[]
end

connections = servers
connections = servers(options)

if connections.size == 0
puts "\n\nWARNING No servers provided. Pls check that you have config/servers.yml or SERVERS_JSON environment variable."
Expand Down

0 comments on commit b53023a

Please sign in to comment.