Skip to content
Snippets Groups Projects
Commit a796aafe authored by Elie Khairallah's avatar Elie Khairallah Committed by Olivier Couet
Browse files

[man,help] Add script to generate man, .h page. Use for `root`. (#2339)

* [man,help] Add script to generate man, .h page. Use for `root`.

* Script improvements

* fix path bug

* bug fix
parent 7a0a8214
No related branches found
No related tags found
No related merge requests found
import sys
import importlib
import os
def getLongest():
longestSize = 0
for arg in listArgs:
if (len(arg.option_strings)==0):
size = len(arg.dest)
else:
size = len(", ".join(arg.option_strings))
longestSize = max(longestSize, size)
return longestSize
def write_header(parser, fileName):
longestSize = getLongest()
file= open(fileName, "w+")
splitPath = sys.argv[2].split("/")
file.write("#ifndef ROOT_{}\n".format(splitPath[len(splitPath)-1].partition(".")[0]))
file.write("#define ROOT_{}\n".format(splitPath[len(splitPath)-1].partition(".")[0]))
file.write("constexpr static const char kCommandLineOptionsHelp[] = R\"RAW(\n")
file.write(parser.format_usage() + "\n")
file.write("OPTIONS:\n")
for arg in listArgs:
options = ""
help = arg.help
if (len(arg.option_strings)==0):
listOptions = [arg.dest]
else:
listOptions = arg.option_strings
options = ", ".join(listOptions)
spaces = " " * (12 + longestSize - len(options))
help = help.replace("\n", "\n {}".format(" "*(len(options)) + spaces))
file.write(" {}{}{}\n".format(options, spaces, help))
file.write(")RAW\";\n")
file.write("#endif\n")
file.close()
def write_man(parser, fileName):
file= open(fileName, "w+")
file.write(".TH {} 1 \n".format(parser.prog))
file.write(".SH SYNOPSIS\n")
file.write(parser.format_usage() + "\n")
file.write(".SH DESCRIPTION\n")
file.write(parser.description + "\n")
file.write(".SH OPTIONS\n")
for arg in listArgs:
options = ""
help = arg.help
if (len(arg.option_strings)==0):
listOptions = [arg.dest]
else:
listOptions = arg.option_strings
options = "\ ".join(listOptions)
file.write(".IP {}\n".format(options))
file.write(help.replace("\n","\n.IP\n")+ "\n")
file.close()
if __name__ == "__main__":
path = os.path.expanduser(sys.argv[1])
splitPath = path.split("/")
sys.path.insert(0, "/".join(splitPath[:len(splitPath)-1]))
i = importlib.import_module(splitPath[len(splitPath)-1].partition(".")[0])
parser = i.get_argparse()
listArgs = parser._actions
if (sys.argv[2].partition(".")[2] == "h"):
write_header(parser, sys.argv[2])
elif (sys.argv[2].partition(".")[2] == "1"):
write_man(parser, sys.argv[2])
\ No newline at end of file
import argparse
import sys
def get_argparse():
parser = argparse.ArgumentParser(add_help=False, prog='root',
description = """ROOTs Object-Oriented Technologies.\n
root is an interactive interpreter of C++ code. It uses the ROOT framework. For more information on ROOT, please refer to\n
An extensive Users Guide is available from that site (see below).
""")
parser.add_argument('-b', help='Run in batch mode without graphics')
parser.add_argument('-x', help='Exit on exceptions')
parser.add_argument('-e', help='Execute the command passed between single quotes')
parser.add_argument('-n', help='Do not execute logon and logoff macros as specified in .rootrc')
parser.add_argument('-t', help='Enable thread-safety and implicit multi-threading (IMT)')
parser.add_argument('-q', help='Exit after processing command line macro files')
parser.add_argument('-l', help='Do not show splash screen')
parser.add_argument('-config', help='print ./configure options')
parser.add_argument('-memstat', help='run with memory usage monitoring')
parser.add_argument('-h','-?', '--help', help='Show summary of options')
parser.add_argument('--notebook', help='Execute ROOT notebook')
parser.add_argument('--web', help='Display graphics in a web browser')
parser.add_argument('dir', help='if dir is a valid directory cd to it before executing')
return parser
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment