sscli 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env python3
  2. __doc__ = """ Scriptshifter command line interface. """
  3. import click
  4. from glob import glob
  5. from os import path
  6. from scriptshifter import DB_PATH
  7. from scriptshifter.tables import init_db as _init_db
  8. from tests import test_sample
  9. @click.group()
  10. def cli():
  11. """ Scriptshifter CLI. """
  12. pass
  13. @cli.group(name="admin")
  14. def admin_grp():
  15. """ Admin operations. """
  16. pass
  17. @admin_grp.command()
  18. def init_db():
  19. """ Initialize SS database. """
  20. _init_db()
  21. click.echo(f"Initialized Scriptshifter DB in {DB_PATH}")
  22. @cli.group(name="test")
  23. def test_grp():
  24. """ Test operations. """
  25. pass
  26. @test_grp.command()
  27. def list_samples():
  28. """ List string sample sets that can be tested. """
  29. path_ptn = path.join(
  30. path.dirname(path.realpath(__file__)),
  31. "tests", "data", "script_samples", "*.csv")
  32. samples = [path.splitext(path.basename(fn))[0] for fn in glob(path_ptn)]
  33. click.echo("\n".join(samples))
  34. @test_grp.command()
  35. @click.argument("lang")
  36. def samples(lang):
  37. """
  38. Test sample strings for language LANG.
  39. LANG must match one of the names obtained with `test list-samples` command.
  40. """
  41. return test_sample(lang)
  42. @cli.group(name="trans")
  43. def trans_grp():
  44. """ Transliteration and transcription operations. """
  45. pass
  46. if __name__ == "__main__":
  47. cli()