Skip to content

Commit 25589ac

Browse files
committed
fixed typer issues
1 parent fa4f2a0 commit 25589ac

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

datafog/client.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def show_config():
110110

111111

112112
@app.command()
113-
def download_model(model_name: str = typer.Argument(..., help="Model to download")):
113+
def download_model(model_name: str = typer.Argument(None, help="Model to download")):
114114
"""
115115
Download a spaCy model.
116116
@@ -119,13 +119,17 @@ def download_model(model_name: str = typer.Argument(..., help="Model to download
119119
120120
Prints a confirmation message after downloading.
121121
"""
122+
if not model_name:
123+
typer.echo("No model name provided to download.")
124+
raise typer.Exit(code=1)
125+
122126
SpacyAnnotator.download_model(model_name)
123127
typer.echo(f"Model {model_name} downloaded.")
124128

125129

126130
@app.command()
127131
def show_spacy_model_directory(
128-
model_name: str = typer.Argument(..., help="Model to check")
132+
model_name: str = typer.Argument(None, help="Model to check")
129133
):
130134
"""
131135
Show the directory path for a spaCy model.
@@ -135,6 +139,10 @@ def show_spacy_model_directory(
135139
136140
Prints the directory path of the specified model.
137141
"""
142+
if not model_name:
143+
typer.echo("No model name provided to check.")
144+
raise typer.Exit(code=1)
145+
138146
annotator = SpacyAnnotator(model_name)
139147
typer.echo(annotator.show_model_path())
140148

@@ -162,7 +170,7 @@ def list_entities():
162170

163171

164172
@app.command()
165-
def redact_text(text: str = typer.Argument(..., help="Text to redact")):
173+
def redact_text(text: str = typer.Argument(None, help="Text to redact")):
166174
"""
167175
Redact PII in text.
168176
@@ -171,6 +179,10 @@ def redact_text(text: str = typer.Argument(..., help="Text to redact")):
171179
172180
Prints the redacted text.
173181
"""
182+
if not text:
183+
typer.echo("No text provided to redact.")
184+
raise typer.Exit(code=1)
185+
174186
annotator = SpacyAnnotator()
175187
anonymizer = Anonymizer(anonymizer_type=AnonymizerType.REDACT)
176188
annotations = annotator.annotate_text(text)
@@ -179,7 +191,7 @@ def redact_text(text: str = typer.Argument(..., help="Text to redact")):
179191

180192

181193
@app.command()
182-
def replace_text(text: str = typer.Argument(..., help="Text to replace PII")):
194+
def replace_text(text: str = typer.Argument(None, help="Text to replace PII")):
183195
"""
184196
Replace PII in text with anonymized values.
185197
@@ -188,6 +200,10 @@ def replace_text(text: str = typer.Argument(..., help="Text to replace PII")):
188200
189201
Prints the text with PII replaced.
190202
"""
203+
if not text:
204+
typer.echo("No text provided to replace PII.")
205+
raise typer.Exit(code=1)
206+
191207
annotator = SpacyAnnotator()
192208
anonymizer = Anonymizer(anonymizer_type=AnonymizerType.REPLACE)
193209
annotations = annotator.annotate_text(text)
@@ -197,7 +213,7 @@ def replace_text(text: str = typer.Argument(..., help="Text to replace PII")):
197213

198214
@app.command()
199215
def hash_text(
200-
text: str = typer.Argument(..., help="Text to hash PII"),
216+
text: str = typer.Argument(None, help="Text to hash PII"),
201217
hash_type: HashType = typer.Option(HashType.SHA256, help="Hash algorithm to use"),
202218
):
203219
"""
@@ -209,6 +225,10 @@ def hash_text(
209225
210226
Prints the text with PII hashed.
211227
"""
228+
if not text:
229+
typer.echo("No text provided to hash.")
230+
raise typer.Exit(code=1)
231+
212232
annotator = SpacyAnnotator()
213233
anonymizer = Anonymizer(anonymizer_type=AnonymizerType.HASH, hash_type=hash_type)
214234
annotations = annotator.annotate_text(text)

0 commit comments

Comments
 (0)