import subprocess
import sys
import os

# This would eventually be saved in a hidden config file (like ~/.grass_config)
CONFIG = {
    "bin": "/Applications/GRASS-8.4.app/Contents/Resources/bin/grass",
    "project": "/Users/arthpatel/Downloads/nc_spm_08_grass7/PERMANENT"
}

def run_grass(module, args):
    full_cmd = [CONFIG["bin"], CONFIG["project"], "--exec", module] + args
    print(f"--- [GRASS-CLI] Running {module} ---")
    subprocess.run(full_cmd)

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: g [module] [args]")
    else:
        # If the user types 'g list', we map it to 'g.list'
        subcommand = sys.argv[1]
        if subcommand == "list":
            run_grass("g.list", sys.argv[2:])
        elif subcommand == "slope":
            run_grass("r.slope.aspect", sys.argv[2:])
        else:
            # Fallback for any other GRASS module
            run_grass(subcommand, sys.argv[2:])
