__main__.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. import argparse
  10. import shtab
  11. from materialize.cli.scratch import (
  12. create,
  13. destroy,
  14. forward,
  15. login,
  16. mine,
  17. push,
  18. sftp,
  19. ssh,
  20. )
  21. def main() -> None:
  22. parser = argparse.ArgumentParser("scratch")
  23. subparsers = parser.add_subparsers(
  24. dest="subcommand", required=True, description="", help="subparsers"
  25. )
  26. for name, configure, run, description in [
  27. ("login", login.configure_parser, login.run, "Log in to AWS SSO"),
  28. (
  29. "create",
  30. create.configure_parser,
  31. create.run,
  32. "Create a new scratch instance",
  33. ),
  34. ("mine", mine.configure_parser, mine.run, "Show active scratch instance"),
  35. ("ssh", ssh.configure_parser, ssh.run, "Connect to scratch instance via ssh"),
  36. (
  37. "sftp",
  38. sftp.configure_parser,
  39. sftp.run,
  40. "Connect to scratch instance via sftp",
  41. ),
  42. (
  43. "destroy",
  44. destroy.configure_parser,
  45. destroy.run,
  46. "Destroy a scratch instance",
  47. ),
  48. (
  49. "push",
  50. push.configure_parser,
  51. push.run,
  52. "Push current HEAD (or a specific git commit) to scratch instance",
  53. ),
  54. (
  55. "completion",
  56. lambda p: shtab.add_argument_to(p, "shell", parent=parser),
  57. lambda: None,
  58. "Generate shell completion script",
  59. ),
  60. (
  61. "forward",
  62. forward.configure_parser,
  63. forward.run,
  64. "Forward local ports remotely",
  65. ),
  66. ]:
  67. s = subparsers.add_parser(name, description=description, help=description)
  68. configure(s)
  69. s.set_defaults(run=run)
  70. args = parser.parse_args()
  71. args.run(args)
  72. if __name__ == "__main__":
  73. main()