class ElasticDot::Command::Base
Protected Class Methods
ask()
click to toggle source
# File lib/elasticdot/command/base.rb, line 35 def self.ask $stdin.gets.to_s.strip end
create_git_remote(remote, url)
click to toggle source
# File lib/elasticdot/command/base.rb, line 64 def self.create_git_remote(remote, url) return if git('remote').split("\n").include?(remote) return unless File.exists?(".git") git "remote add #{remote} #{url}" puts "Git remote #{remote} added" end
echo_off()
click to toggle source
# File lib/elasticdot/command/base.rb, line 18 def self.echo_off with_tty do system "stty -echo" end end
echo_on()
click to toggle source
# File lib/elasticdot/command/base.rb, line 24 def self.echo_on with_tty do system "stty echo" end end
extract_app_from_git_config(remote = 'origin')
click to toggle source
# File lib/elasticdot/command/base.rb, line 94 def self.extract_app_from_git_config(remote = 'origin') url = git "config remote.#{remote}.url" return nil if url.empty? if url =~ /^git@git\.elasticdot\.com:([\w\d\-\.]+)\.git$/ $1 else nil end end
extract_app_in_dir()
click to toggle source
# File lib/elasticdot/command/base.rb, line 84 def self.extract_app_in_dir if app = extract_app_from_git_config return app elsif app = extract_app_from_git_config('elasticdot') return app else nil end end
find_app!(opts)
click to toggle source
# File lib/elasticdot/command/base.rb, line 39 def self.find_app!(opts) if opts[:app] @app = opts[:app] elsif app = extract_app_in_dir @app = app end return true if @app puts 'No app specified.' puts 'Specify which app to use with --app APP.' exit 1 end
git(args)
click to toggle source
# File lib/elasticdot/command/base.rb, line 58 def self.git(args) return "" unless has_git? flattened_args = [args].flatten.compact.join(" ") %x{ git #{flattened_args} 2>&1 }.strip end
has_git?()
click to toggle source
# File lib/elasticdot/command/base.rb, line 53 def self.has_git? %x{ git --version } $?.success? end
spinner(desc, &block)
click to toggle source
# File lib/elasticdot/command/base.rb, line 105 def self.spinner(desc, &block) chars = %w{ | / - \\ } t = Thread.new { block.call } while t.alive? print "#{desc} [#{chars[0]}]" sleep 0.1 print "\r" chars.push chars.shift end t.join puts "#{desc} [ok]" end
which(cmd)
click to toggle source
# File lib/elasticdot/command/base.rb, line 73 def self.which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each { |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable? exe } end return nil end
with_tty() { || ... }
click to toggle source
# File lib/elasticdot/command/base.rb, line 30 def self.with_tty(&block) return unless $stdin.isatty yield end