#!/usr/bin/env python3.8
import sys
from math import inf
from subprocess import run

import click


@click.command()
@click.option("-s", "--shell", required=False)
@click.option("-m", "--max-attempts", type=int, required=False)
@click.argument("args", nargs=-1)
def main(shell, max_attempts, args):
    if shell and args:
        exit("--shell and args are exclusive.")
    it = 0
    while it < (max_attempts or inf):
        it += 1
        if shell:
            proc = run(shell, shell=True)
        else:
            proc = run(args)
        if proc.returncode != 0:
            sys.exit(proc.returncode)


if __name__ == "__main__":
    main()
