Skip to content

Instantly share code, notes, and snippets.

@jhyland87
Created September 13, 2016 16:30
Show Gist options
  • Save jhyland87/bae842b9ad538eca2f71ad27405b659e to your computer and use it in GitHub Desktop.
Save jhyland87/bae842b9ad538eca2f71ad27405b659e to your computer and use it in GitHub Desktop.
import sys
help_items = [
{
'short' : '-h',
'long' : '--help',
'arg_val' : 'topic',
'required' : False,
'description' : 'Shows the general help menu, or help regarding a specific item or topic.',
'default' : 'general',
'values' : [ 'query', 'macros', 'general', 'explain', 'mode' ],
'examples' : [ '--help macro', '-h mode' ]
},
{
'short' : '-i',
'long' : '--in',
'arg_val' : 'file',
'required' : True,
'description' : 'Excel sheet to parse and use for the macro substitutions in the parsed query. Can be xls or xlsx.',
'default' : None,
'values' : None,
'examples' : [ '--in ./foo.xlsx', '-i ./bar.xls' ]
},
{
'short' : '-o',
'long' : '--out',
'arg_val' : 'file',
'required' : False,
'description' : 'Output file to save the SQL queries to. (.sql extension is appended if not in the value specified)',
'default' : '<STDOUT>',
'values' : None,
'examples' : [ '--out ./update-items-queries', '-o ./delete-expired-items.sql' ]
},
{
'short' : '-q',
'long' : '--query',
'arg_val' : 'query',
'required' : True,
'description' : 'Query "template" to use for the bulk query generation. Place macros in the query to customize it for each row (see "--help macros" for more info)',
'default' : None,
'values' : None,
'examples' : [ '--query "UPDATE accounts SET accounts.status = \'{col:D;d:0}\' WHERE account.id = \'{col:A}!\'"' ]
},
{
'short' : '-p',
'long' : '--passive',
'arg_val' : 'mode',
'required' : False,
'description' : 'Enable or disable passive mode for query generation. Enabling passive mode will withhold queries that have empty results for macros. Disabling it will terminate the query generation.',
'default' : 'true',
'values' : [ 'true', 'false' ],
'examples' : [ '--passive true', '-p false' ]
},
{
'short' : None,
'long' : '--macro-enclosure',
'arg_val' : 'enclosure',
'required' : False,
'description' : 'Enclosures for the macros in the query. The default value is "{}", which means the macros need to be enclosed like so: "{col:a}" (Note: This needs to have an even amount of characters in it)',
'default' : '{}',
'values' : None, #[ '' ],
'examples' : [ '--macro-enclosure "{{}}"' ]
}
]
print("\t{0:2}{1:37}{2:10}".format( '', 'ARGUMENT','DESCRIPTION'))
for hi in help_items:
#print("\t{0:5}{1:30} {2:10}".format( (hi['short']+',') if hi['short'] else '', hi['long'] + ((' <'+hi['arg_val']+'>') if hi['arg_val'] else ''), hi['description']))
print("\t{0:2}{1:5}{2:30} {3:10}".format( '*' if hi['required'] else '', (hi['short']+',') if hi['short'] else '', hi['long'] + ((' <'+hi['arg_val']+'>') if hi['arg_val'] else ''), hi['description']))
if hi['examples'] is not None and len(hi['examples']) > 0:
print("\t{0:39}{1:10}{2}".format( '','Examples:', '"'+ '", "'.join(hi['examples']) +'"'))
""" RESULT
ARGUMENT DESCRIPTION
-h, --help <topic> Shows the general help menu, or help regarding a specific item or topic.
Examples: "--help macro", "-h mode"
* -i, --in <file> Excel sheet to parse and use for the macro substitutions in the parsed query. Can be xls or xlsx.
Examples: "--in ./foo.xlsx", "-i ./bar.xls"
-o, --out <file> Output file to save the SQL queries to. (.sql extension is appended if not in the value specified)
Examples: "--out ./update-items-queries", "-o ./delete-expired-items.sql"
* -q, --query <query> Query "template" to use for the bulk query generation. Place macros in the query to customize it for each row (see "--help macros" for more info)
Examples: "--query "UPDATE accounts SET accounts.status = '{col:D;d:0}' WHERE account.id = '{col:A}!'""
-p, --passive <mode> Enable or disable passive mode for query generation. Enabling passive mode will withhold queries that have empty results for macros. Disabling it will terminate the query generation.
Examples: "--passive true", "-p false"
--macro-enclosure <enclosure> Enclosures for the macros in the query. The default value is "{}", which means the macros need to be enclosed like so: "{col:a}" (Note: This needs to have an even amount of characters in it)
Examples: "--macro-enclosure "{{}}""
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment