class Frasco::CLI
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/frasco/cli.rb, line 34 def initialize(*args) super(*args) @simulator_dir = File.expand_path("~/Library/Application Support/iPhone Simulator"); end
Private Class Methods
exit_on_failure?()
click to toggle source
# File lib/frasco/cli.rb, line 316 def self.exit_on_failure? true end
Public Instance Methods
archive(name, archive_path)
click to toggle source
# File lib/frasco/cli.rb, line 205 def archive(name, archive_path) snapshot = _get_snapshot(name) raise FrascoError.snapshot_notfound_error(snapshot) \ unless snapshot.exists? raise FrascoError.new("speficied archive file is already exists: #{archive_path}\nOverwrite with -f/--overwrite option.") \ if File.exists?(archive_path) && !options["overwrite"] archive_path = File.absolute_path(archive_path) system("cd '#{snapshot.path}' && tar czf '#{archive_path}' .") end
cleanup()
click to toggle source
# File lib/frasco/cli.rb, line 145 def cleanup _before_bang_command snapshot = _get_snapshot(@@STASH_NAME) raise FrascoError.new("not stashed") \ unless snapshot.exists? # nothing if not eixsts simulator dir FileUtils.remove_dir(@simulator_dir) \ if File.exists?(@simulator_dir) FileUtils.move(snapshot.path, @simulator_dir) end
list()
click to toggle source
# File lib/frasco/cli.rb, line 57 def list pattern = "#{_find_snapshots_dir}/*" Dir.glob(pattern).sort.map do |path| snapshot = _get_snapshot(Snapshot.unescape_name(File.basename(path))) puts "#{snapshot.name}\t(#{snapshot.find_versions.join(', ')})" end end
remove(name)
click to toggle source
# File lib/frasco/cli.rb, line 185 def remove(name) snapshot = _get_snapshot(name) raise FrascoError.snapshot_notfound_error(snapshot) \ unless snapshot.exists? FileUtils.remove_dir(snapshot.path) end
rename(org_name, new_name)
click to toggle source
# File lib/frasco/cli.rb, line 166 def rename(org_name, new_name) org_snapshot = _get_snapshot(org_name) raise FrascoError.snapshot_notfound_error(org_snapshot) \ unless File.exists?(org_snapshot.path) new_snapshot = _get_snapshot(new_name) raise FrascoError.snapshot_exists_error(new_snapshot) \ if File.exists?(new_snapshot.path) FileUtils.move(org_snapshot.path, new_snapshot.path) end
save(name)
click to toggle source
# File lib/frasco/cli.rb, line 76 def save(name) _before_bang_command raise FrascoError.simulator_notfound_error \ unless File.exists?(@simulator_dir) snapshot = _get_snapshot(name) raise FrascoError.snapshot_exists_error(snapshot) \ if snapshot.exists? _mkdir_parents(snapshot.path) FileUtils.copy_entry(@simulator_dir, snapshot.path) end
setup()
click to toggle source
# File lib/frasco/cli.rb, line 44 def setup raise FrascoError.new("already initialized") \ if File.exists?(_default_frasco_dir) FileUtils.mkdir(_default_frasco_dir) end
simulator(*args)
click to toggle source
# File lib/frasco/cli.rb, line 246 def simulator(*args) Frasco::SimulatorCLI.start(args) end
stash()
click to toggle source
# File lib/frasco/cli.rb, line 100 def stash _before_bang_command stash = _get_snapshot(@@STASH_NAME) raise FrascoError.simulator_notfound_error \ unless File.exists?(@simulator_dir) raise FrascoError.new("already stashed") \ if File.exists?(stash.path) _mkdir_parents(stash.path) FileUtils.move(@simulator_dir, stash.path) end
up(name)
click to toggle source
# File lib/frasco/cli.rb, line 124 def up(name) _before_bang_command snapshot = _get_snapshot(name) raise FrascoError.snapshot_notfound_error(snapshot) \ unless snapshot.exists? stash FileUtils.copy_entry(snapshot.path, @simulator_dir) end
up_archive(archive_path)
click to toggle source
# File lib/frasco/cli.rb, line 228 def up_archive(archive_path) _before_bang_command raise FrascoError.new("no such file: #{archive_path}") \ unless File.exists?(archive_path) stash system("mkdir '#{@simulator_dir}' && tar xzf '#{archive_path}' -C '#{@simulator_dir}'") end
version()
click to toggle source
# File lib/frasco/cli.rb, line 255 def version @shell.say("frasco version #{Frasco::VERSION} (c) 2013 neethouse.org") end
Private Instance Methods
_before_bang_command()
click to toggle source
Raise error if simulator is already running. Quit simulator if specified –quit option, and continue.
# File lib/frasco/cli.rb, line 265 def _before_bang_command simulator = Simulator.new if simulator.is_running? if options[:quit] simulator.quit else raise FrascoError.new("Simulator is running. Quit with -f/--quit option.") end end end
_default_frasco_dir()
click to toggle source
# File lib/frasco/cli.rb, line 307 def _default_frasco_dir "#{Dir::home}/.frasco" end
_find_frasco_dir()
click to toggle source
Returns $FRASCO_DIR or $HOME/.frasco Raise an error when .frasco dir is not exists.
# File lib/frasco/cli.rb, line 296 def _find_frasco_dir dir = ENV["FRASCO_DIR"] || _default_frasco_dir raise FrascoError.new("frasco is not setup\nPlease execute 'frasco setup' command.") \ unless File.exists?(dir) dir end
_find_snapshots_dir()
click to toggle source
# File lib/frasco/cli.rb, line 312 def _find_snapshots_dir _find_snapshots_dir = "#{_find_frasco_dir}/snapshots" end
_get_snapshot(name)
click to toggle source
# File lib/frasco/cli.rb, line 280 def _get_snapshot(name) Snapshot.new(_find_snapshots_dir, name) end
_mkdir_parents(path)
click to toggle source
Create parent directories of specified path.
# File lib/frasco/cli.rb, line 287 def _mkdir_parents(path) basedir = File.dirname(path) FileUtils.mkdir_p(basedir) unless File.exists?(basedir) end