# ==============================================================================
"""COUNT : print the number of lines, words and chars in a set of text files"""
# ==============================================================================
__author__  = "Christophe Schlick modified by Philippe Blasi"
__version__ = "1.0"
__date__    = "2022-11-12"
__usage__   = """
User input : <filename> [filename ...]
App output : number of lines, words and chars for each provided file"""
# ==============================================================================
from ezCLI import *
# ------------------------------------------------------------------------------
def count(name:str) -> str:
  """return the number of lines, words and chars stored in file 'name'"""
  text = read_txt(name) # read whole content of file 'name'
  line, word, char = len(text.split('\n')), len(text.split()), len(text)
  return f"{name} : lines = {line}, words = {word}, chars = {char}"
# ------------------------------------------------------------------------------
def parser(command:str) -> str:
  """parse 'command' and return line/word/char counters for provided files"""
  tuple_name = parse(command); #inspect()
  if type(tuple_name) is str:
    res = count(tuple_name)
  else:
    tab_res=[count(name) for name in tuple_name]
    res = "\n".join(tab_res)

  return res 
# ==============================================================================
if __name__ == '__main__':
  userloop(parser, "Enter <filename> [filename ...]")
# ==============================================================================
