Class: Ftpeter::CLI
- Inherits:
-
Object
- Object
- Ftpeter::CLI
- Defined in:
- lib/ftpeter/cli.rb
Instance Method Summary collapse
-
#configure ⇒ Object
TODO: extract code into Connection-class.
- #confirm(confirmation = 'yes') ⇒ Object
- #get_changes_from(vcs) ⇒ Object
- #go ⇒ Object
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #okay? ⇒ Boolean
- #transport(changes) ⇒ Object
Constructor Details
#initialize(args) ⇒ CLI
Returns a new instance of CLI.
7 8 9 10 11 12 13 14 15 |
# File 'lib/ftpeter/cli.rb', line 7 def initialize(args) raise ArgumentError, 'Please specify a host to deploy to' unless args[0] @host = args[0] @dir = args[1] || '/' # the directory to change into @last = args[2] || 'origin/master' # get the last deployed version configure end |
Instance Method Details
#configure ⇒ Object
TODO: extract code into Connection-class
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ftpeter/cli.rb', line 18 def configure cleaned_host = if @host =~ %r~//~ require 'uri' URI(@host).host else @host end @credentials = begin `grep #{cleaned_host} ~/.netrc`.chomp .split("\n").first .match(/login (?<user>\S+) password (?<pass>\S+)/) rescue NoMethodError nil end @commands = begin Pathname.new('./.ftpeterrc').read.chomp rescue Errno::ENOENT nil end @connection = Ftpeter::Connection.new( @host, @credentials, @dir, @commands ) end |
#confirm(confirmation = 'yes') ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/ftpeter/cli.rb', line 62 def confirm(confirmation = 'yes') $stderr.print '[yes, No] > ' if $stdin.gets.chomp != confirmation raise "you did not enter '#{confirmation}', aborting" else true end end |
#get_changes_from(vcs) ⇒ Object
81 82 83 84 85 |
# File 'lib/ftpeter/cli.rb', line 81 def get_changes_from(vcs) raise ArgumentError, "There's only git-support for now" unless vcs == :git Ftpeter::Backend::Git.new(@last).changes end |
#go ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ftpeter/cli.rb', line 48 def go changes = get_changes_from(:git) upload = transport(changes).via(@connection, :lftp) $stdout.puts '=' * 80, upload.inform, '=' * 80, nil upload.persist if okay? upload.execute and upload.cleanup else $stdout.puts "#{upload.script} is left for your editing pleasure" end end |
#okay? ⇒ Boolean
72 73 74 75 76 77 78 79 |
# File 'lib/ftpeter/cli.rb', line 72 def okay? $stdout.puts 'is this script okay?' begin confirm('yes') rescue RuntimeError false end end |