Skip to content

Commit 1e2bb70

Browse files
authored
Merge pull request #14 from erinshek/main
CLI
2 parents 11028db + c9f0a8f commit 1e2bb70

5 files changed

Lines changed: 67 additions & 1 deletion

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ from kaalin.string import upper, lower
3131
print(upper("Assalawma áleykum")) # ASSALAWMA ÁLEYKUM
3232
print(lower("Assalawma áleykum")) # assalawma áleykum
3333
```
34+
35+
### Command Line Interface (CLI)
36+
```bash
37+
$ cyr2lat input.txt [output.txt]
38+
$ lat2cyr input.txt [output.txt]
39+
```

kaalin/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from .number import NumberRangeError
22
from .converter import latin2cyrillic, cyrillic2latin
33
from . import string
4+
from . import cli

kaalin/cli/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .converter import lat2cyr, cyr2lat

kaalin/cli/converter.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from kaalin.converter.latin_cyrillic_converter import latin2cyrillic, cyrillic2latin
2+
import sys
3+
import os
4+
5+
def cyr2lat():
6+
if len(sys.argv) < 2 or len(sys.argv) > 3:
7+
print("Use:\n cyr2lat <input_file> [output_file]")
8+
sys.exit(1)
9+
10+
input_file = sys.argv[1]
11+
12+
if len(sys.argv) == 3:
13+
output_file = sys.argv[2]
14+
else:
15+
base, ext = os.path.splitext(input_file)
16+
output_file = f"{base}-lat{ext}"
17+
18+
try:
19+
with open(input_file, "r", encoding="utf-8") as f:
20+
text = f.read()
21+
converted = cyrillic2latin(text)
22+
with open(output_file, "w", encoding="utf-8") as f:
23+
f.write(converted)
24+
print(f"✅ Converted text written to: {output_file}")
25+
except Exception as e:
26+
print(f"❌ Error: {e}")
27+
sys.exit(1)
28+
29+
30+
def lat2cyr():
31+
if len(sys.argv) < 2 or len(sys.argv) > 3:
32+
print("Use:\n lat2cyr <input_file> [output_file]")
33+
sys.exit(1)
34+
35+
input_file = sys.argv[1]
36+
37+
if len(sys.argv) == 3:
38+
output_file = sys.argv[2]
39+
else:
40+
base, ext = os.path.splitext(input_file)
41+
output_file = f"{base}-cyr{ext}"
42+
43+
try:
44+
with open(input_file, "r", encoding="utf-8") as f:
45+
text = f.read()
46+
converted = latin2cyrillic(text)
47+
with open(output_file, "w", encoding="utf-8") as f:
48+
f.write(converted)
49+
print(f"✅ Converted text written to: {output_file}")
50+
except Exception as e:
51+
print(f"❌ Error: {e}")
52+
sys.exit(1)

setup.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
88
long_description = "\n" + fh.read()
99

10-
VERSION = '3.0.1'
10+
VERSION = '3.1.0'
1111
DESCRIPTION = 'Special opportunities for the Karakalpak language'
1212

1313
# Setting up
@@ -21,6 +21,12 @@
2121
long_description=long_description,
2222
packages=find_packages(),
2323
install_requires=[],
24+
entry_points={
25+
"console_scripts": [
26+
"cyr2lat=kaalin.cli.converter:cyr2lat",
27+
"lat2cyr=kaalin.cli.converter:lat2cyr",
28+
]
29+
},
2430
keywords=['karakalpak', 'language', 'python'],
2531
classifiers=[
2632
"Development Status :: 1 - Planning",

0 commit comments

Comments
 (0)