1
+ from enum import Enum
1
2
from pathlib import Path
3
+ from typing import Optional
2
4
3
5
import rich
4
6
import typer
8
10
9
11
app = typer .Typer ()
10
12
13
+ class ValidateOptions (str , Enum ):
14
+ POPOLO = "popolo"
15
+ TRANSCRIPT = "transcript"
11
16
12
17
@app .command ()
13
- def validate_popolo (file : Path ):
18
+ def blank ():
19
+ """
20
+ Holding command to make 'validate' not the default.
21
+ """
22
+ pass
23
+
24
+
25
+ @app .command ()
26
+ def validate (file : Optional [Path ] = None , url : Optional [str ] = None , type : ValidateOptions = ValidateOptions .POPOLO ):
27
+ # must be at least one of file or url, but not both
28
+ if not file and not url :
29
+ typer .echo ("Must provide either a file or a URL." )
30
+ raise typer .Exit (code = 1 )
31
+ if file and url :
32
+ typer .echo ("Must provide either a file or a URL, not both." )
33
+ raise typer .Exit (code = 1 )
34
+ if type == ValidateOptions .POPOLO :
35
+ if file :
36
+ validate_popolo_file (file )
37
+ if url :
38
+ validate_popolo_url_file (url )
39
+ elif type == ValidateOptions .TRANSCRIPT :
40
+ if not file :
41
+ typer .echo ("Must provide a file for a transcript." )
42
+ raise typer .Exit (code = 1 )
43
+ validate_transcript (file )
44
+
45
+
46
+ def validate_popolo_file (file : Path ):
14
47
"""
15
48
Validate a mysoc style Popolo file.
16
49
Returns Exit 1 if a validation error.
@@ -26,9 +59,7 @@ def validate_popolo(file: Path):
26
59
)
27
60
rich .print ("[green]Valid Popolo file[/green]" )
28
61
29
-
30
- @app .command ()
31
- def validate_popolo_url (url : str ):
62
+ def validate_popolo_url_file (url : str ):
32
63
"""
33
64
Validate a mysoc style Popolo file.
34
65
Returns Exit 1 if a validation error.
@@ -45,7 +76,6 @@ def validate_popolo_url(url: str):
45
76
rich .print ("[green]Valid Popolo file[/green]" )
46
77
47
78
48
- @app .command ()
49
79
def validate_transcript (file : Path ):
50
80
"""
51
81
Validate a mysoc style Popolo file.
0 commit comments