@@ -9,7 +9,7 @@ from glob import glob
99from os import path
1010
1111from scriptshifter import DB_PATH
12- from scriptshifter .tables import init_db as _init_db
12+ from scriptshifter .tables import get_language , list_tables , init_db as _init_db
1313from scriptshifter .trans import transliterate as _transliterate
1414from test .integration import test_sample
1515
@@ -34,6 +34,63 @@ def init_db():
3434 click .echo (f"Initialized Scriptshifter DB in { DB_PATH } " )
3535
3636
37+ @cli .group (name = "tables" )
38+ def table_grp ():
39+ """ Commands to display table information. """
40+ pass
41+
42+
43+ @table_grp .command ()
44+ def list ():
45+ """ List all languages. """
46+ click .echo ("\n Language and script tables available:" )
47+ for tcode , tdata in list_tables ().items ():
48+ click .echo ()
49+ click .echo (click .style (tcode , fg = "green" ))
50+ for k , v in tdata .items ():
51+ if v is not None :
52+ click .echo (f"\t { k } : { v } " )
53+
54+
55+ @table_grp .command ()
56+ @click .argument ("lang" )
57+ @click .argument ("t_dir" , default = "s2r" )
58+ def show (lang , t_dir ):
59+ """
60+ Show character mappings for a language.
61+
62+ Only one direction (script to Roman or Roman to script) is diplayed. The
63+ mappings are in descending order of priority.
64+
65+ LANG is one of the language codes obtained by `sscli tables list`.
66+
67+ T_DIR is the direction to be displayed (`s2r` or `r2s`). Default is `s2r`.
68+ """
69+ try :
70+ lang_md = get_language (lang )
71+ except KeyError :
72+ click .echo (
73+ click .style ("ERROR: " , fg = "red" ) +
74+ f"{ lang } table does not exist." )
75+ exit (1 )
76+
77+ dir_k = "script_to_roman" if t_dir == "s2r" else "roman_to_script"
78+ if dir_k not in lang_md :
79+ click .echo (
80+ click .style ("ERROR: " , fg = "red" ) +
81+ f"{ lang } table has no `{ dir_k } ` section." )
82+ exit (1 )
83+
84+ out = lang_md [dir_k ].get ("map" )
85+
86+ click .echo (f"\n Mapping table for { lang } , direction: { t_dir } " )
87+ click .echo ("Tokens are listed in descending order of priority." )
88+ click .echo ("\n src\t dest" )
89+ click .echo ("-" * 12 )
90+ for src , dest in out :
91+ click .echo (f"{ src } \t { dest } " )
92+
93+
3794@cli .group (name = "test" )
3895def test_grp ():
3996 """ Test operations. """
0 commit comments