5bbd1d38c9271ba6319a46f0827ff90ec8c25efd ceisenhart Thu Oct 22 19:25:39 2015 -0700 Adding a check to the argparse module that causes the program to spit help with no arguments. This replicates the C code style. Refs #16156 diff --git src/utils/newPythonProg/newPythonProg.c src/utils/newPythonProg/newPythonProg.c index cde87f0..319c951 100644 --- src/utils/newPythonProg/newPythonProg.c +++ src/utils/newPythonProg/newPythonProg.c @@ -57,31 +57,32 @@ void writeProgram(char *fileName, char *programName, char *usage) { FILE *programFile = mustOpen(fileName, "w"); // Write the python skeleton fprintf(programFile, "#!/usr/bin/env python2.7\n# %s\n\"\"\"%s\"\"\"\n", programName, usage); fprintf(programFile, "import os\nimport sys\nimport collections\nimport argparse\n" "\n" "# import the UCSC kent python library\n" "sys.path.append(os.path.join(os.path.dirname(__file__), 'pyLib'))\n" "import common\n\n"); fprintf(programFile, "def parseArgs(args):\n \"\"\"\n Parse the command line arguments.\n \"\"\"\n parser" "= argparse.ArgumentParser(description = __doc__)\n parser.add_argument (\"inpu" "tFile\",\n help = \" The input file. \",\n type = argparse.FileType(\"r\"))\n "); fprintf(programFile, "parser.add_argument (\"outputFile\",\n help = \" The output file. \",\n type =" - "argparse.FileType(\"w\"))\n options = parser.parse_args()\n return options\n\n"); + "argparse.FileType(\"w\"))\n if (len(sys.argv) == 1):\n parser.print_help()\n" + " exit(1)\n options = parser.parse_args()\n return options\n\n"); fprintf(programFile, "def main(args):\n \"\"\"\n Initialized options and calls other functions.\n \"\"\"\n " "options = parseArgs(args)\n\nif __name__ == \"" "__main__\" : \n sys.exit(main(sys.argv))"); } void newPythonProg(char *programName, char *usage) /* newPythonProg - Make a skeleton for a new python program. */ { char fileName[512]; char dirName[512]; //char fileOnly[128]; safef(dirName, sizeof(dirName), "%s", programName); makeDir(dirName);