def cli(execute, region, aws_access_key_id, aws_secret_access_key, s3_staging_dir, work_group, athenaclirc, profile, database): '''A Athena terminal client with auto-completion and syntax highlighting. \b Examples: - athenacli - athenacli my_database ''' if (athenaclirc == ATHENACLIRC) and (not os.path.exists( os.path.expanduser(athenaclirc))): err_msg = ''' Welcome to athenacli! It seems this is your first time to run athenacli, we generated a default config file for you %s Please change it accordingly, and run athenacli again. ''' % athenaclirc print(err_msg) write_default_config(DEFAULT_CONFIG_FILE, athenaclirc) sys.exit(1) if profile != 'default': os.environ['AWS_PROFILE'] = profile athenacli = AthenaCli(region=region, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, s3_staging_dir=s3_staging_dir, work_group=work_group, athenaclirc=athenaclirc, profile=profile, database=database) # --execute argument if execute: if execute == '-': if select.select([ sys.stdin, ], [], [], 0.0)[0]: query = sys.stdin.read() else: raise RuntimeError("No query to execute on stdin") elif os.path.exists(execute): with open(execute) as f: query = f.read() else: query = execute try: athenacli.formatter.format_name = 'csv' athenacli.run_query(query) exit(0) except Exception as e: click.secho(str(e), err=True, fg='red') exit(1) athenacli.run_cli()
def cli(execute, region, aws_access_key_id, aws_secret_access_key, s3_staging_dir, athenaclirc, database): '''A Athena terminal client with auto-completion and syntax highlighting. \b Examples: - athenacli - athenacli my_database ''' if (athenaclirc == ATHENACLIRC) and (not os.path.exists( os.path.expanduser(ATHENACLIRC))): err_msg = ''' Welcome to athenacli! It seems this is your first time to run athenacli, we generated a default config file for you %s Please change it accordingly, and run athenacli again. ''' % ATHENACLIRC print(err_msg) write_default_config(DEFAULT_CONFIG_FILE, ATHENACLIRC) sys.exit(1) athenacli = AthenaCli(region=region, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, s3_staging_dir=s3_staging_dir, athenaclirc=athenaclirc, database=database) # --execute argument if execute: if os.path.exists(execute): with open(execute) as f: query = f.read() else: query = execute try: athenacli.formatter.format_name = 'csv' athenacli.run_query(query) exit(0) except Exception as e: click.secho(str(e), err=True, fg='red') exit(1) athenacli.run_cli()