parse_argv.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 utils import log, error_msg, expand_dir
  16. def parse_argv_as_tuple() -> tuple:
  17. parser = argparse.ArgumentParser(
  18. prog="slidegen", description="slidegen - a slide generator."
  19. )
  20. parser.add_argument(
  21. "songfile",
  22. type=str,
  23. help="the input text file (with header and body)",
  24. )
  25. parser.add_argument(
  26. "output",
  27. type=str,
  28. help="output directory where the generated slides are placed",
  29. )
  30. parser.add_argument(
  31. "structure",
  32. type=str,
  33. help="the chosen song structure",
  34. nargs="?",
  35. default="",
  36. )
  37. args = parser.parse_args()
  38. try:
  39. song_file_path = expand_dir(args.songfile)
  40. output_dir = expand_dir(args.output)
  41. except IndexError:
  42. error_msg("incorrect amount of arguments provided, exiting...")
  43. try:
  44. chosen_structure = args.structure
  45. if chosen_structure.strip() == "":
  46. chosen_structure = ""
  47. except IndexError:
  48. chosen_structure = ""
  49. log("parsing {}...".format(song_file_path))
  50. return song_file_path, output_dir, chosen_structure
  51. def parse_ssync_args_as_tuple() -> tuple:
  52. parser = argparse.ArgumentParser(
  53. prog="ssync",
  54. description="ssync - an interactive program syncing that lets "
  55. + "you choose songs to generate slides for using fzf.",
  56. )
  57. parser.add_argument(
  58. "-o", "--offline", help="skips syncing with remote", action="store_true"
  59. )
  60. parser.add_argument(
  61. "-s",
  62. "--sequential",
  63. help="disables async slide generation",
  64. action="store_true",
  65. )
  66. args = parser.parse_args()
  67. return args.offline, args.sequential