-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split subcommands, add --group and --csv options
- Loading branch information
1 parent
e6b7dd3
commit 9c72e91
Showing
5 changed files
with
259 additions
and
190 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import argparse | ||
import sys | ||
|
||
from shaperglot.cli.check import check | ||
from shaperglot.cli.report import report | ||
from shaperglot.cli.describe import describe | ||
|
||
|
||
def main(args=None): | ||
if args is None: | ||
args = sys.argv[1:] | ||
parser = argparse.ArgumentParser( | ||
description="Check a font file's language coverage" | ||
) | ||
subparsers = parser.add_subparsers(help='sub-commands') | ||
|
||
parser_describe = subparsers.add_parser('describe', help=describe.__doc__) | ||
parser_describe.add_argument( | ||
'lang', metavar='LANG', help='an ISO639-3 language code' | ||
) | ||
parser_describe.set_defaults(func=describe) | ||
|
||
parser_check = subparsers.add_parser('check', help=check.__doc__) | ||
parser_check.add_argument('--verbose', '-v', action='count') | ||
parser_check.add_argument('font', metavar='FONT', help='the font file') | ||
parser_check.add_argument( | ||
'lang', metavar='LANG', help='one or more ISO639-3 language codes', nargs="+" | ||
) | ||
parser_check.set_defaults(func=check) | ||
|
||
parser_report = subparsers.add_parser('report', help=report.__doc__) | ||
parser_report.add_argument('font', metavar='FONT', help='the font file') | ||
parser_report.add_argument('--verbose', '-v', action='count') | ||
parser_report.add_argument('--csv', action='store_true', help="Output as CSV") | ||
parser_report.add_argument( | ||
'--group', action='store_true', help="Group by success/failure" | ||
) | ||
parser_report.add_argument( | ||
'--filter', type=str, help="Regular expression to filter languages" | ||
) | ||
parser_report.set_defaults(func=report) | ||
|
||
options = parser.parse_args(args) | ||
if not hasattr(options, "func"): | ||
parser.print_help() | ||
sys.exit(1) | ||
options.func(options) | ||
|
||
|
||
if __name__ == '__main__': # pragma: no cover | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from shaperglot.checker import Checker | ||
from shaperglot.languages import Languages | ||
|
||
|
||
def check(options): | ||
"""Check a particular language or languages are supported""" | ||
checker = Checker(options.font) | ||
langs = Languages() | ||
for lang in options.lang: | ||
if lang not in langs: | ||
print(f"Language '{options.lang}' not known") | ||
continue | ||
|
||
results = checker.check(langs[lang]) | ||
|
||
if results.is_unknown: | ||
print(f"Cannot determine whether font supports language '{lang}'") | ||
elif results.is_success: | ||
print(f"Font supports language '{lang}'") | ||
else: | ||
print(f"Font does not fully support language '{lang}'") | ||
|
||
if options.verbose and options.verbose > 1: | ||
for message in results: | ||
print(f" * {message}") | ||
elif options.verbose or not results.is_success: | ||
for message in results.fails: | ||
print(f" * {message}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
from textwrap import fill | ||
|
||
from shaperglot.languages import Languages | ||
|
||
def describe(options): | ||
"""Describe the checks shaperglot will perform to determine support for a given language""" | ||
langs = Languages() | ||
if options.lang not in langs: | ||
maybe = langs.disambiguate(options.lang) | ||
if len(maybe) == 1: | ||
lang = langs[maybe[0]] | ||
print(f"Assuming you meant {maybe[0]} ({lang['full_name']}).") | ||
elif len(maybe) > 1: | ||
print(f"Language '{options.lang}' not known", end="") | ||
print("; try one of: " + ", ".join(maybe)) | ||
return | ||
else: | ||
print(f"Language '{options.lang}' not known", end="") | ||
print("") | ||
return | ||
else: | ||
lang = langs[options.lang] | ||
print(f"To test for {lang['name']} support, shaperglot will:") | ||
for shaperglot_check in lang.get("shaperglot_checks", []): | ||
print( | ||
fill( | ||
"ensure " + shaperglot_check.describe(), | ||
initial_indent=" * ", | ||
subsequent_indent=" ", | ||
width=os.get_terminal_size()[0] - 2, | ||
) | ||
) | ||
|
Oops, something went wrong.