COMPOSE ?= docker-compose
SERVICE ?= beets

.PHONY: build rebuild shell zsh bash beet config stats doctor pip-install freeze

build:
	$(COMPOSE) build $(SERVICE)

rebuild:
	$(COMPOSE) build --no-cache $(SERVICE)

shell: zsh

zsh:
	$(COMPOSE) run --rm $(SERVICE) zsh

bash:
	$(COMPOSE) run --rm $(SERVICE) bash

beet:
	$(COMPOSE) run --rm $(SERVICE) beet

config:
	$(COMPOSE) run --rm $(SERVICE) beet config

stats:
	$(COMPOSE) run --rm $(SERVICE) beet stats

pip-install:
	$(COMPOSE) run --rm $(SERVICE) bash -c 'pip install -r /music/beets/requirements.txt'

freeze:
	$(COMPOSE) run --rm $(SERVICE) bash -c 'pip freeze > /music/beets/requirements.txt'

doctor:
	$(COMPOSE) run --rm $(SERVICE) bash -c ' \
		set -e; \
		echo "== environment =="; \
		echo "HOME=$$HOME"; \
		echo "BEETSDIR=$$BEETSDIR"; \
		echo "PATH=$$PATH"; \
		echo; \
		echo "== beets =="; \
		command -v beet; \
		beet version; \
		echo; \
		echo "== config path =="; \
		beet config -p; \
		echo; \
		echo "== python =="; \
		command -v python; \
		python --version; \
		echo; \
		echo "== pip =="; \
		command -v pip; \
		pip --version; \
		echo; \
		echo "== tools =="; \
		for c in ffmpeg ffprobe flac metaflac mp3val lame opusenc opusdec fpcalc shntool cuebreakpoints cuetag sox magick jq rg fzf sqlite3; do \
			printf "%-18s" "$$c"; command -v "$$c" || true; \
		done; \
		echo; \
		echo "== paths =="; \
		ls -ld /music/beets /music/beets/config /music/beets/scripts /music/library /music/inbox /music/pruned; \
	'
