class Byebug::TraceCommand

def description

def description
  %{tr[acevar] VARNAME [stop|nostop]\tset trace variable on VARNAME}
end

def execute

def execute
  varname = @match[1]
  if global_variables.include?("$#{varname}".to_sym)
    if @match[2] && @match[2] !~ /(:?no)?stop/
      errmsg "expecting \"stop\" or \"nostop\"; got \"#{@match[2]}\"\n"
    else
      dbg_cmd = (@match[2] && @match[2] !~ /nostop/) ? 'byebug(1, false)' : ''
    end
    eval("trace_var(:\"\$#{varname}\") do |val|
            print \"traced global variable '#{varname}' has value '\#{val}'\"\n
            #{dbg_cmd}
          end")
    print "Tracing global variable \"#{varname}\".\n"
  else
    errmsg "'#{varname}' is not a global variable.\n"
  end
end

def names

def names
  %w(trace)
end

def regexp

def regexp
  /^\s* tr(?:acevar)? (?: \s+ (\S+))?  # (variable-name)?
                      (?: \s+ (\S+))?  # (stop | nostop)?
   \s*$/x
end