Selaa lähdekoodia

use a more typical commandline argument system

Noah Vogt 2 vuotta sitten
vanhempi
sitoutus
7800f39a23
4 muutettua tiedostoa jossa 50 lisäystä ja 7 poistoa
  1. 8 2
      README.md
  2. 1 0
      input/__init__.py
  3. 35 4
      input/parse_argv.py
  4. 6 1
      ssync.py

+ 8 - 2
README.md

@@ -34,6 +34,11 @@ The wrapper script doesn't have any additional arguments, as all the relevant va
 
     ./ssync.py
 
+Also for both programs there is a help page with `-h` or `--help`.
+
+    ./ssync.py -h
+    ./slidegen.py --help
+
 ### Source File Layout
 
 The file is divided into two what we will here call *parts* that are divided with at least one `\n` character and an arbitrary amount of lines that are either empty or only contain whitespace:
@@ -104,6 +109,8 @@ Note that directories constants support environment variables in the form `$var`
 OBS_SLIDES_DIR = "~/Documents/obs-${OBS_MAJOR_VERSION}/slides$month$weekday"
 ```
 
+Also note that if you enter unsensible configuration entries, that the program may crash as there is basically no config validation except for something like directories.
+
 Now for explanation of the individual entries.
 
 #### File Format and Naming
@@ -301,8 +308,7 @@ These are some issues and possible changes that will be addressed or at least co
     - handle possibly incorrect or insensible configurations safely
 - asynchronous slide generation
 - use caching, with checksum checks for changes in the source file and the `PROMPT_INPUT`
-- provide ssync with the song structure, display it to the user and prevent him from entering a prompt that would slidegen cause to terminate unsuccessfully
-- use a more typical commandline argument system
+- provide ssync with the song structure, display it to the user and prevent him from entering a prompt that would cause slidegen to terminate unsuccessfully
 - add more documentation, especially explaining the slide generation, but also dependencies and deployment
 - add tests
 

+ 1 - 0
input/__init__.py

@@ -18,5 +18,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 from .parse_prompt import parse_prompt_input
 from .parse_file import parse_metadata, parse_songtext
 from .parse_argv import parse_argv_as_tuple
+from .parse_argv import parse_ssync_args
 from .validate_ssync_config import validate_ssync_config
 from .slide_selection_iterator import slide_selection_iterator

+ 35 - 4
input/parse_argv.py

@@ -15,19 +15,42 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
-import sys
+import argparse
 
 from utils import log, error_msg, expand_dir
 
 
 def parse_argv_as_tuple() -> tuple:
+    parser = argparse.ArgumentParser(
+        prog="slidegen", description="slidegen - a slide generator."
+    )
+    parser.add_argument(
+        "songfile",
+        type=str,
+        help="the input text file (with header and body)",
+    )
+    parser.add_argument(
+        "output",
+        type=str,
+        help="output directory where the generated slides are placed",
+    )
+    parser.add_argument(
+        "structure",
+        type=str,
+        help="the chosen song structure",
+        nargs="?",
+        default="",
+    )
+
+    args = parser.parse_args()
+
     try:
-        song_file_path = sys.argv[1]
-        output_dir = expand_dir(sys.argv[2])
+        song_file_path = expand_dir(args.songfile)
+        output_dir = expand_dir(args.output)
     except IndexError:
         error_msg("incorrect amount of arguments provided, exiting...")
     try:
-        chosen_structure = sys.argv[3]
+        chosen_structure = args.structure
         if chosen_structure.strip() == "":
             chosen_structure = ""
     except IndexError:
@@ -35,3 +58,11 @@ def parse_argv_as_tuple() -> tuple:
 
     log("parsing {}...".format(song_file_path))
     return song_file_path, output_dir, chosen_structure
+
+def parse_ssync_args() -> None:
+    parser = argparse.ArgumentParser(
+        prog="ssync",
+        description="ssync - an interactive program syncing that lets "
+        + "you choose songs to generate slides for using fzf.",
+    )
+    parser.parse_args()

+ 6 - 1
ssync.py

@@ -20,12 +20,17 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 import colorama
 
 from utils import clear_obs_slides_dir
-from input import validate_ssync_config, slide_selection_iterator
+from input import (
+    validate_ssync_config,
+    slide_selection_iterator,
+    parse_ssync_args,
+)
 from sync import sync_slide_repo, save_new_checkfile, syncing_needed
 
 
 class Ssync:
     def __init__(self):
+        parse_ssync_args()
         validate_ssync_config()
 
     def execute(self):