Created
June 5, 2017 16:10
Using ruby-progressbar for long command line tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'ruby-progressbar' | |
commands = [ | |
{ | |
description: 'changing into Centro Direct directory', | |
command: 'cd ~/dev/centro-media-manager/' | |
}, | |
{ | |
description: 'powdering down', | |
command: 'powder down' | |
}, | |
{ | |
description: 'bundle root app', | |
command: 'bundle install', | |
bundle: true | |
}, | |
{ | |
description: 'bundle all components', | |
command: './scripts/cmm_bundle all', | |
bundle: true | |
}, | |
{ | |
description: 'killing any idle postgres instances', | |
command: "[[ -n $(ps aux | grep postgres | grep idle) ]] && \ | |
kill $(ps aux | grep postgres | grep idle | awk '{print $2}')" | |
}, | |
# command: 'bundle exec rake db:drop db:create db:migrate' | |
{ | |
description: 'dev db drop', | |
command: 'dropdb -h localhost -p 5432 cmm_development' | |
}, | |
{ | |
description: 'dev db create', | |
command: 'createdb -h localhost -p 5432 cmm_development' | |
}, | |
{ | |
description: 'dev db load structure', | |
command: 'psql -h localhost -p 5432 cmm_development < db/structure.sql' | |
}, | |
{ | |
description: 'dev db migrate', | |
command: 'bundle exec rake db:migrate' | |
}, | |
{ | |
description: 'powdering up', | |
command: 'powder up' | |
}, | |
{ | |
description: 'dev db seed', | |
command: 'bundle exec rake db:seed' | |
}, | |
{ | |
description: 'dev db bootstrap', | |
command: 'bundle exec rake db:bootstrap' | |
}, | |
# command: 'RAILS_ENV=test bundle exec rake db:drop db:create db:migrate' | |
{ | |
description: 'test db drop', | |
command: 'dropdb -h localhost -p 5432 cmm_test' | |
}, | |
{ | |
description: 'test db create', | |
command: 'createdb -h localhost -p 5432 cmm_test' | |
}, | |
{ | |
description: 'test db load structure', | |
command: 'psql -h localhost -p 5432 cmm_test < db/structure.sql' | |
}, | |
{ | |
description: 'test db migrate', | |
command: 'RAILS_ENV=test bundle exec rake db:migrate' | |
}, | |
{ | |
description: 'test db seed', | |
command: 'RAILS_ENV=test bundle exec rake db:seed' | |
} | |
] | |
def bundle? | |
@bundle ||= ARGV.any? { |arg| arg.casecmp('bundle') } | |
end | |
# Filters out bundle commands if no bundle arg passed | |
commands = commands.select { |cmd| cmd[:bundle] ? bundle? : true } | |
progress = ProgressBar.create(total: commands.size, format: ' %c/%C %P%%|%B|%e') | |
commands.each do |command| | |
progress.total = command[:unknown] == true ? nil : commands.size | |
progress.log("#{command[:description]}...") if command[:description] | |
system("#{command[:command]} > cdr.log") if command[:command] | |
progress.increment | |
end | |
progress.finish | |
system('rm cdr.log') | |
system('powder status && git status') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment