Skip to content

Commit b8254ce

Browse files
committed
chore: add file check rules
1 parent c96d8ea commit b8254ce

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

Makefile

+21-5
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,34 @@ summarize_progress: $(VENV_FOR_SCRIPT)/bin/activate
8989

9090
.PHONY: google_translate
9191
google_translate: $(VENV_FOR_SCRIPT)/bin/activate
92-
if [ -z $(filter-out $@,$(MAKECMDGOALS)) ]; then \
92+
93+
@$(eval _target=$(filter-out $@, $(MAKECMDGOALS)))
94+
@if [ -z $(_target) ]; then \
9395
echo "Please provide a file argument."; \
9496
exit 1; \
9597
fi
9698

97-
@$(eval __target=$(filter-out $@,$(MAKECMDGOALS)))
98-
@$(eval __filepath=$(addprefix ../,$(__target)))
99-
@$(eval __temp_po_file=tmp.po)
99+
100+
@if [ "$(suffix $(_target))" != ".po" ]; then \
101+
echo "Incorrect file extension. Only '.po' files are allowed."; \
102+
exit 1; \
103+
else \
104+
_target=$(addsuffix ,po,$(_target)); \
105+
fi
106+
107+
@if [ ! -f "$(_target)" ]; then \
108+
echo "File '$(filter-out $@, $(_target))' does not exist."; \
109+
exit 1; \
110+
fi
111+
112+
@$(eval _tmp_po_file=tmp.po)
113+
@$(eval _file_path=$(addprefix ../, $(_target)))
100114

101115
cd .scripts && \
102116
. $(VENV_FOR_SCRIPT)/bin/activate; \
103-
python3 google_translate/main.py $(__filepath) > $(__temp_po_file) ; pomerge -t $(__filepath) -i $(__temp_po_file) -o $(__filepath); rm "$(__temp_po_file)"
117+
python3 google_translate/main.py $(_file_path) > $(_tmp_po_file) ; \
118+
pomerge -t $(_file_path) -i $(_tmp_po_file) -o $(_file_path) ; \
119+
# rm $(_tmp_po_file)
104120
exit 0
105121

106122

0 commit comments

Comments
 (0)