Coverage for puristaa/cli.py: 100.00%

14 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-04 22:03:31 +00:00

1#! /usr/bin/env python 

2# -*- coding: utf-8 -*- 

3"""Extract common prefix from sequence of strings and yield sequence of rest strings. 

4 

5Implementation uses min-max left matching, single character backtracking policy and a list. 

6""" 

7import os 

8import sys 

9import typing 

10 

11from puristaa.puristaa import prefix_compression 

12 

13 

14@typing.no_type_check 

15def main(argv=None): 

16 """Test driver for the prefix compression taking the texts from argv and the policy from PC_TOKEN env variable.""" 

17 texts = sys.argv[1:] if argv is None else argv 

18 if not isinstance(texts, (tuple, list)): 

19 texts = texts.split() 

20 token = os.getenv('PC_TOKEN', '') 

21 prefix, endings = prefix_compression(texts, lambda x: x == token if token else None) 

22 compressed = f"'{prefix}' + {endings}" 

23 print(f"Prefix compression{f' with inner structure separator {token}' if token else ''} yields {compressed}")