import argparse
import base64
import os
def encode_filepath(filepath):
"""Encodes a filepath using base64 for debugging purposes."""
try:
with open(filepath, 'rb') as f:
data = f.read()
encoded_data = base64.b64encode(data).decode('utf-8') # encode to string
return encoded_data
except FileNotFoundError:
return f"Error: File not found: {filepath}"
except Exception as e:
return f"Error: {e}"
def main():
"""CLI interface for encoding filepaths."""
parser = argparse.ArgumentParser(description="Encode filepaths using base64 for debugging.")
parser.add_argument("filepath", help="The filepath to encode.")
args = parser.parse_args()
encoded_string = encode_filepath(args.filepath)
print(encoded_string)
if __name__ == "__main__":
main()
Add your comment