Skip to content

Commit

Permalink
Add validation of required commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Malinskiy committed Apr 9, 2018
1 parent ada27ed commit cac687d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/spielbash/model/action/message_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def execute(session)
sleep(action_context.reading_delay_s)

session.send_key('C-h', message.length) if (action_context.delete)
sleep(action_context.typing_delay_s)
end
end
end
1 change: 0 additions & 1 deletion lib/spielbash/model/movie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def shoot
action.execute(session)
end

session.stop_recording
session.close_session
end

Expand Down
15 changes: 8 additions & 7 deletions lib/spielbash/model/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ def stop_recording
end

def close_session
send_key("exit")
send_key('C-m')

wait
send_key("exit C-m")
end

# This will wait for tmux session pid to not have any child processes
Expand All @@ -47,7 +44,7 @@ def wait

def send_key(key, count=1)
key = 'Space' if key == ' '
execute_tmux_with("send-keys -t #{name} -N #{count} #{key}")
execute_tmux_with("send-keys -t #{name} -N #{count} #{key}", true)
end

def start_recording
Expand All @@ -60,7 +57,7 @@ def start_recording
private

def exec_wait_check_cmd(pid)
if context.wait_check_cmd.nil?
if is_real_environment
execute_with('pgrep', "-P #{pid}", true)
else
cmd = context.wait_check_cmd.split
Expand All @@ -78,7 +75,7 @@ def execute_with(cmd, arguments, wait = false, leader = true, io_inherit = false
end

def execute_with_exactly(cmd, wait, io_inherit, leader, *arguments)
raise "Please install #{cmd}" if which(cmd).nil?
raise "Please install #{cmd}" if is_real_environment && which(cmd).nil?

process = ChildProcess.build(cmd, *arguments)
process.leader = leader
Expand All @@ -98,6 +95,10 @@ def execute_with_exactly(cmd, wait, io_inherit, leader, *arguments)
process
end

def is_real_environment
context.wait_check_cmd.nil?
end

def output(file)
file.rewind
out = file.read
Expand Down
2 changes: 1 addition & 1 deletion lib/spielbash/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Spielbash
VERSION = "0.1.1"
VERSION = "0.1.2"
end
23 changes: 21 additions & 2 deletions lib/spielbash/view/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,27 @@ module CLI
desc 'Be verbose'
switch [:v, :verbose]

# pre do |global_options, command, options, args|
# end
# Cross-platform way of finding an executable in the $PATH.
#
# which('ruby') #=> /usr/bin/ruby
def 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 true if File.executable?(exe) && !File.directory?(exe)
}
end
false
end

pre do |global_options, command, options, args|
help_now!('pgrep is not installed!') unless which('pgrep')
help_now!('docker is not installed!') unless which('docker')
help_now!('tmux is not installed!') unless which('tmux')
help_now!('resize is not installed!') unless which('resize')
help_now!('asciinema is not installed!') unless which('asciinema')
end

desc 'Create a recording'
command :record do |c|
Expand Down

0 comments on commit cac687d

Please sign in to comment.