#!/usr/bin/env python
'''print all action_commands and analys_commands in cpptraj

The output is used for checking if specific command is valid in pytraj.pmap

Example
-------
python  find_action_and_analysis_commands.py > cpptraj_commands.py

# reformat cpptraj_commands.py to make it prettier
yapf -i cpptraj_commands.py

CPPTRAJHOME must be set
'''
# parse those lines in cpptraj/src/Command.cpp
#  { ACTION, "image", Action_Image::Alloc, Action_Image::Help, AddAction },
#  { ANALYSIS, "multicurve", Analysis_Multicurve::Alloc, Analysis_Multicurve::Help, AddAnalysis },

import os

cpptrajhome = os.environ.get('CPPTRAJHOME', '')

if not cpptrajhome:
    raise EnvironmentError('must set CPPTRAJHOME')

cpptraj_actlist = []
cpptraj_analist = []

with open(cpptrajhome + '/src/Command.cpp') as fh:
    lines = fh.readlines()
    cpptraj_actlist += [line.split('\n')[0].split()[1].replace('"', '').replace(',', '').replace('.h', '')
                        for line in lines if line.startswith('#include "Action_')]
    cpptraj_analist += [line.split('\n')[0].split()[1].replace('"', '').replace(',', '').replace('.h', '')
                        for line in lines if line.startswith('#include "Analysis_')]

print("# this file was auto-generated by scripts/find_action_and_analysis_commands.py")
print('action_commands = ', sorted(cpptraj_actlist))
print("")
print('analysis_commands = ', sorted(cpptraj_analist))
