ContriHUB / E-CP

A CLI tool with a variety of features to help in practicing competitive programming problems
0 stars 14 forks source link

Fixes Issue #7 #23

Closed Dadaji18 closed 2 years ago

Dadaji18 commented 2 years ago

Added a function as utility in /src/Config/Config.py that only reads text files, throws error otherwise

  def is_text_file(self, file_name):
      try:
          with open(file_name, 'tr') as check_file:
              check_file.read()
              return True
      except:
          return False

Used this function as a check for text files and updated set_temp function in /src/Cli/config.py for the same

@click.command()
@click.argument('path', type=str)
def set_temp(path):
    try:
        config = Config()
        if config.is_text_file(path):
            config.set_template(path)
            click.echo(click.style('Template path set', fg='green'))
        else:
            click.echo(click.style('Template must be a text file', fg='red'))
    except Exception as e:
        click.echo(e)