Executes an arbitrary ruby script @param [Array] sub_argv Options passed to the execute_ruby_script command from the user input @return [Fixnum] Return status
(sub_argv)
| 1688 | # @return [Fixnum] Return status |
| 1689 | # |
| 1690 | def execute(sub_argv) |
| 1691 | |
| 1692 | $logger.info "ExecuteRubyScript, sub_argv = #{sub_argv}" |
| 1693 | |
| 1694 | require 'pathname' |
| 1695 | |
| 1696 | opts = OptionParser.new do |o| |
| 1697 | o.banner = 'Usage: openstudio execute_ruby_script file [arguments]' |
| 1698 | end |
| 1699 | |
| 1700 | if sub_argv.size == 1 |
| 1701 | if sub_argv[0] == '-h' || sub_argv[0] == '--help' |
| 1702 | safe_puts(opts.help) |
| 1703 | return 0 |
| 1704 | end |
| 1705 | end |
| 1706 | |
| 1707 | # Parse the options |
| 1708 | # DLM: don't do argument parsing as in other commands since we want to pass the remaining arguments to the ruby script |
| 1709 | return 0 if sub_argv == nil |
| 1710 | return 1 unless sub_argv |
| 1711 | $logger.debug("ExecuteRubyScript command: #{sub_argv.inspect}") |
| 1712 | file_path = sub_argv.shift.to_s |
| 1713 | file_path = File.absolute_path(File.join(Dir.pwd, file_path)) unless Pathname.new(file_path).absolute? |
| 1714 | $logger.debug "Path for the file to run: #{file_path}" |
| 1715 | |
| 1716 | ARGV.clear |
| 1717 | sub_argv.each do |arg| |
| 1718 | ARGV << arg |
| 1719 | end |
| 1720 | |
| 1721 | $logger.debug "ARGV: #{ARGV}" |
| 1722 | |
| 1723 | unless File.exist? file_path |
| 1724 | $logger.error "Unable to find the file #{file_path} on the filesystem" |
| 1725 | return 1 |
| 1726 | end |
| 1727 | |
| 1728 | require file_path |
| 1729 | |
| 1730 | 0 |
| 1731 | end |
| 1732 | end |
| 1733 | |
| 1734 | # Class to put the user into an irb shell |