bin/babot in babot-0.5.0 vs bin/babot in babot-0.6.1

- old
+ new

@@ -17,50 +17,37 @@ class BabotRunner < Boson::Runner def initialize cmd "mkdir -p '#{root}'" end - desc "Add bot from [repository]" - def add(repository) - name = File.basename repository - + desc "Add bot [name] from [repository]" + def add(name, repository) if File.directory? repository cmd "ln -s '#{File.realpath repository}' '#{root.join(name)}'" else cmd "git clone '#{repository}' '#{root.join(name)}'" end cmd "mkdir -p '#{Pathname.new(root).join name, 'config'}'" File.open(root.join(name, "config", "credentials.yml").to_s, 'w') do |config| config.write DEFAULT_CONFIG.to_yaml end - configure name end desc "Update bot [name]" def update(name) cmd "cd '#{root.join(name)}' && git pull --rebase origin master && bundle install" end - desc "Update crontab" - def schedule - `ls #{root}`.split.each do |name| - cmd "whenever -i #{name} -f #{root.join(name, 'config', 'schedule.rb')}" - end + desc "Set run date of the bot [name] with [cron] syntax with [options]" + def schedule(name, cron, *options) + cmd "printf \"every '#{cron}' do\ncommand 'babot run #{name} \"#{options.join("\" \"")}\"'\nend\" > #{root.join name, 'config', 'schedule.rb'}" end desc "Run bot [name]" - def run(name) - options = YAML::load_file root.join(name, "config", 'credentials.yml') - - Twitter.configure do |config| - config.consumer_key = options['consumer_key'] - config.consumer_secret = options['consumer_secret'] - config.oauth_token = options['oauth_token'] - config.oauth_token_secret = options['oauth_token_secret'] - end - load root.join(name, 'babot.run').to_s + def run(name, *options) + cmd "cd '#{root.join name}' && bundle exec ruby 'babot.run' \"#{options.join("\" \"")}\"" end desc "Delete bot [name]" def delete(name) cmd "rm -rf '#{root.join name}' '#{root.join name, 'config', 'credentials.yml'}'" @@ -79,10 +66,10 @@ desc "Push to remote server [remote]" def push(remote) cmd "ssh '#{remote}' 'rm -rf ~/.babot'" cmd "scp -qr '#{root}' '#{remote}:~/.'" `ls -1 '#{root}'`.split.each do |name| - cmd "ssh '#{remote}' 'cd ~/.babot/#{name} && bundle install'" + cmd "ssh '#{remote}' 'cd ~/.babot/#{name} && bundle install && whenever -i #{name} -f ~/.babot/#{name}/config/schedule.rb'" end cmd "ssh '#{remote}' 'babot schedule'" end private