from subprocess import check_output
import os.path

cli_path = "../bin/atc"
doc_source_path = "source/cli.rst"
doc_preprocessed_path = "preprocessed/cli.rst"
if not os.path.isfile(cli_path):
	raise Exception("Could not find CLI executable at bin/atc!")
cli_output = check_output([cli_path, "--help"]).decode()
formatted_output = cli_output.strip().replace("\n", "\n   ")
atc_version_string = formatted_output.split("\n")[0]

with open(doc_source_path, "r") as f_in:
	with open(doc_preprocessed_path, "w") as f_out:
		f_out.write(f_in.read().replace("CLI_OUTPUT", formatted_output).replace("CLI_ATC_VERSION", atc_version_string))
