defmodule Mix.Tasks.Ttycast.Find do
@moduledoc """
Find text in visual recording snapshots.
mix ttycast.find /tmp/demo.ttycast error
"""
use Mix.Task
@shortdoc "Search visual .ttycast snapshots"
@impl true
def run(argv) do
{opts, args, invalid} = OptionParser.parse(argv, strict: [every_ms: :integer])
if invalid != [] or length(args) != 2 do
Mix.raise("usage: mix ttycast.find PATH TEXT [--every-ms MS]")
end
[path, text] = args
path
|> TTYCast.find(text, every_ms: Keyword.get(opts, :every_ms, 250))
|> Enum.each(fn match ->
Mix.shell().info("#{match.time_ms}ms #{match.match}")
end)
end
end