#!/usr/bin/env python

import sys

optionlist =  [ ]

for line in sys.stdin:
  line = line.strip()
  if line.startswith ('option:'):
    optionlist += [ [ line[8:], '', '' ] ]
  elif line.startswith ('default:'):
    optionlist[-1][1] = line
  else:
    if optionlist[-1][2]:
      optionlist[-1][2] += ' '
    optionlist[-1][2] += line

optionlist.sort()

string = '.. _config_file_options:\n'
string += '\n'
string += '##########################################\n'
string += 'List of MRtrix3 configuration file options\n'
string += '##########################################\n\n'

for entry in optionlist:
  string += '.. option:: ' + entry[0] + '\n\n'
  string += '    *' + entry[1] + '*\n\n'
  string += '     ' + entry[2] + '\n\n'

sys.stdout.write(string)
