#!/usr/bin/python3.6
"""
perftest_cluster - Perftest cluster mode CLI dispatcher.

Installed by `make install` to $(bindir)/perftest_cluster. Thin wrapper
around the cluster_mode Python package that lives under
$(libexecdir)/perftest/.

The /usr/libexec token below is substituted at build time by autotools
(see the do_subst rule in Makefile.am) so this script always points at
the real install path the user picked via `./configure --libexecdir=...`
or `--prefix=...`.

Usage:
    perftest_cluster run [orchestrator-args...]   forwards to cluster_mode.__main__

Dev-mode equivalent (running from the perftest source tree, no install):
    python3 -m cluster_mode [args...]
"""

import sys

# cluster_mode is installed under libexec, NOT on the system Python path,
# so we don't collide with distro Python packaging policies. autotools
# substitutes /usr/libexec at build time.
sys.path.insert(0, '/usr/libexec/perftest')


_USAGE = (
    "usage: perftest_cluster run [orchestrator-args...]\n"
    "  run     orchestrator CLI (forwards to cluster_mode.__main__)\n"
)


def main():
    if len(sys.argv) < 2:
        sys.stderr.write(_USAGE)
        sys.exit(2)

    if sys.argv[1] in ('-h', '--help'):
        sys.stdout.write(_USAGE)
        sys.exit(0)

    sub = sys.argv.pop(1)
    if sub == 'run':
        from cluster_mode.__main__ import main as orchestrator_main
        orchestrator_main()
    else:
        sys.stderr.write(f"perftest_cluster: unknown subcommand {sub!r}\n")
        sys.stderr.write(_USAGE)
        sys.exit(2)


if __name__ == '__main__':
    main()
