parse_argv.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright © 2024 Noah Vogt <noah@noahvogt.com>
  2. # This program is free software: you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation, either version 3 of the License, or
  5. # (at your option) any later version.
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. # You should have received a copy of the GNU General Public License
  11. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. import argparse
  13. from dataclasses import dataclass
  14. from utils import log, error_msg, expand_dir
  15. def parse_slidegen_argv_as_tuple() -> tuple:
  16. parser = argparse.ArgumentParser(
  17. prog="slidegen", description="slidegen - a slide generator."
  18. )
  19. parser.add_argument(
  20. "songfile",
  21. type=str,
  22. help="the input text file (with header and body)",
  23. )
  24. parser.add_argument(
  25. "output",
  26. type=str,
  27. help="output directory where the generated slides are placed",
  28. )
  29. parser.add_argument(
  30. "structure",
  31. type=str,
  32. help="the chosen song structure",
  33. nargs="?",
  34. default="",
  35. )
  36. args = parser.parse_args()
  37. try:
  38. song_file_path = expand_dir(args.songfile)
  39. output_dir = expand_dir(args.output)
  40. except IndexError:
  41. error_msg("incorrect amount of arguments provided, exiting...")
  42. try:
  43. chosen_structure = args.structure
  44. if chosen_structure.strip() == "":
  45. chosen_structure = ""
  46. except IndexError:
  47. chosen_structure = ""
  48. log("parsing '{}'...".format(song_file_path))
  49. return song_file_path, output_dir, chosen_structure
  50. def parse_ssync_args_as_tuple() -> tuple:
  51. parser = argparse.ArgumentParser(
  52. prog="ssync",
  53. description="ssync - an interactive program syncing that lets "
  54. + "you choose songs to generate slides for using fzf.",
  55. )
  56. parser.add_argument(
  57. "-o", "--offline", help="skips syncing with remote", action="store_true"
  58. )
  59. parser.add_argument(
  60. "-s",
  61. "--sequential",
  62. help="disables async slide generation",
  63. action="store_true",
  64. )
  65. args = parser.parse_args()
  66. return args.offline, args.sequential
  67. @dataclass
  68. class SsyncFlags:
  69. offline_enabled: bool
  70. disable_async_enabled: bool