def main():
	"""Command-line tool.
	See bibsearch.py -h for help.
	"""

	import sys
	import add2bib

	output = sys.stdout
	
	from optparse import OptionParser
	
	usage = """
	%prog [options]
	example: %prog -f h -bo BIB_DATABASE 0-324-23583-6 9780596529321
	"""


	parser = OptionParser(usage=usage, version ="%prog " + __version__)
	parser.add_option("-f", "--format", action="store",
	                  dest="format", default='b',
					  help="set format(s) of output\nb: BibTeX\nh: HTML\nt: text", metavar="FORMAT")
	parser.add_option("-o", "--outfile", action="store", type="string", dest="outfile",
					  help="Write formatted references to FILE", metavar="FILE")
	parser.add_option("-n", "--nuke", action="store_true", dest="overwrite", default=False,
					  help="CAUTION! silently overwrite outfile, default=%default")
	parser.add_option("-b", "--backup", action="store_true", dest="backup", default=False,
					  help="backup FILE to FILE.bak, default=%default")
	parser.add_option("-v", "--verbose", action="store_true",
	                  dest="verbose", default=False,
					  help="Print INFO messages to stdout, default=%default")
	parser.add_option("-V", "--very_verbose", action="store_true",
	                  dest="very_verbose", default=False,
					  help="Print DEBUG messages to stdout, default=%default")

	#parse options
	(options, args) = parser.parse_args()
	# set license, also checking imports
	set_license_key()

	# open output file for writing (default: stdout)
	if options.outfile:
		if options.backup and os.path.exists(options.outfile):
			shutil.copyfile(options.outfile,options.outfile+".bak")
		if options.overwrite or not os.path.exists(options.outfile):
			output = open(options.outfile,'w')
		else:
			isbn2bib_logger.info("Appending to %s.\n(Use -n option to nuke (overwrite) the old output file.)"
			                     %options.outfile)
			output = open(options.outfile,'a')
	print args
	for isbn in args:
		isbn = isbn.replace('-','')
		entry = make_entry(isbn)
		output.write( str(entry) )
		
	if 'h' in options.format:
		output.write( add2bib.html_format(entry) )
	if 't' in options.format:
		output.write( add2bib.text_format(entry) )
dataset/ETHPy150Open dschwilk/bibstuff/bibstuff/isbn2bib.py/main/original