parse_argv.py 2.5 KB

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