diff --git a/bin/console b/bin/console index d278be5..5941210 100755 --- a/bin/console +++ b/bin/console @@ -2,7 +2,7 @@ # frozen_string_literal: true require "bundler/setup" -require "tracer" +require "tracer/irb" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. diff --git a/lib/tracer/irb.rb b/lib/tracer/irb.rb index 8df62b4..fd50b81 100644 --- a/lib/tracer/irb.rb +++ b/lib/tracer/irb.rb @@ -1,3 +1,4 @@ +require_relative "../tracer" require "irb/cmd/nop" require "irb" @@ -46,6 +47,11 @@ class Trace < TraceCommand description "Trace the target object (or self) in the given expression. Usage: `trace [target,] `" def execute(*args) + if args.empty? + puts "Please provide the expression to trace. Usage: `trace [target,] `" + return + end + args = args.first.split(/,/, 2) case args.size @@ -56,8 +62,13 @@ def execute(*args) target = eval(args.first, irb_context.workspace.binding) expression = args.last else - raise ArgumentError, - "wrong number of arguments (given #{args.size}, expected 1..2)" + puts "Please provide the expression to trace. Usage: `trace [target,] `" + return + end + + unless expression + puts "Please provide the expression to trace. Usage: `trace [target,] `" + return end b = irb_context.workspace.binding @@ -69,7 +80,14 @@ class TraceCall < TraceCommand category "Tracing" description "Trace method calls in the given expression. Usage: `trace_call `" - def execute(expression) + def execute(*args) + expression = args.first + + unless expression + puts "Please provide the expression to trace. Usage: `trace_call `" + return + end + b = irb_context.workspace.binding Tracer.trace_call { eval(expression, b) } end @@ -79,7 +97,14 @@ class TraceException < TraceCommand category "Tracing" description "Trace exceptions in the given expression. Usage: `trace_exception `" - def execute(expression) + def execute(*args) + expression = args.first + + unless expression + puts "Please provide the expression to trace. Usage: `trace_exception `" + return + end + b = irb_context.workspace.binding Tracer.trace_exception { eval(expression, b) } end