class CLI
Command line interface functionality
Constants
- BACKTRACE_RE
- FILENAME_AND_METHOD_RE
Public Class Methods
new(argv)
click to toggle source
# File lib/modulation/modules/cli.rb, line 7 def initialize(argv) @argv = argv process end
Public Instance Methods
cleanup_backtrace(error)
click to toggle source
# File lib/modulation/modules/cli.rb, line 49 def cleanup_backtrace(error) backtrace = error.backtrace.reject { |l| l =~ BACKTRACE_RE } error.set_backtrace(backtrace) end
collect_deps(path, array)
click to toggle source
# File lib/modulation/modules/cli.rb, line 54 def collect_deps(path, array) if File.directory?(path) Dir["#{path}/**/*.rb"].each { |fn| collect_deps(fn, array) } else array << File.expand_path(path) mod = import(File.expand_path(path)) if mod.respond_to?(:__traverse_dependencies) mod.__traverse_dependencies { |m| array << m.__module_info[:location] } end end end
deps()
click to toggle source
# File lib/modulation/modules/cli.rb, line 66 def deps paths = [] @argv.each { |arg| collect_deps(arg, paths) } puts(*paths) end
filename_and_method_from_arg(arg)
click to toggle source
# File lib/modulation/modules/cli.rb, line 38 def filename_and_method_from_arg(arg) if arg =~ FILENAME_AND_METHOD_RE match = Regexp.last_match [match[1], match[2].to_sym] else [arg, :main] end end
pack()
click to toggle source
# File lib/modulation/modules/cli.rb, line 72 def pack STDOUT << import('@modulation/packer').pack(@argv, hide_filenames: true) end
process()
click to toggle source
# File lib/modulation/modules/cli.rb, line 13 def process cmd = ARGV.shift if respond_to? cmd.to_sym send cmd else ARGV.unshift cmd run end end
run()
click to toggle source
# File lib/modulation/modules/cli.rb, line 23 def run @argv.each { |arg| run_file arg } rescue StandardError => e cleanup_backtrace(e) raise e end
run_file(arg)
click to toggle source
# File lib/modulation/modules/cli.rb, line 30 def run_file(arg) fn, method = filename_and_method_from_arg(arg) mod = import(File.expand_path(fn)) mod.send(method) if method end
version()
click to toggle source
# File lib/modulation/modules/cli.rb, line 76 def version puts "Modulation version #{Modulation::VERSION}" end