# snouty docs — shared behavior
#
# Search and inspect cached Antithesis documentation from the command line.
#
# As a developer, I want to search and read Antithesis documentation from the
# command line so that I can quickly find relevant docs without leaving my
# terminal.
#
# Not tested here (kept in Rust — require HTTP header inspection or
# stateful mock server):
#   - Unless --offline is passed, the command checks for an updated
#     documentation database before running the requested subcommand.
#   - Documentation update requests send a User-Agent header in the form
#     snouty/<version> (<os>; <arch>; rust<rust-version>).
#   - Cached documentation is stored at docs.db under Snouty's cache
#     directory ($XDG_CACHE_HOME/snouty), along with an ETag file used to
#     avoid re-downloading an unchanged database.
#   - If a docs update fails and a cached database already exists, the
#     command prints a warning to stderr and continues with the cached
#     database. If no database exists yet, the command fails.

# When --offline is passed and no database exists, the command tells the user
#    to remove --offline.
env HOME=$WORK/empty-home
! snouty docs --offline search docker
stderr 'Documentation database not found.*'
stderr 'remove --offline to download it.*'

# The command is exposed as `snouty docs` with search, show, tree, and sqlite
#    subcommands. setup-docs-db seeds the cache (via XDG_CACHE_HOME) with the
#    fixture database.
setup-docs-db
snouty docs --offline search docker
stdout 'docker.*'

snouty docs --offline show getting_started
stdout '# Setup guide.*'

snouty docs --offline tree
stdout 'guides.*'

# The database lives at <cache dir>/docs.db; `sqlite` prints that path.
snouty docs --offline sqlite
stdout 'docs\.db'
