def parseCommandLineArgs():
"""
As implied by the name, this will parse the command line arguments so we can use them. Important note,
after this function is called, no need to use the "extension" attribute since this one is concatenated
with the "output". This results in cleaner code since those two are always(? most of the time at least)
used together.
:return: A parsed object as provided by argparse.parse_args()
"""
parser = argparse.ArgumentParser(prog="Assembler.py",
description="Capua Assembler Version {}".format(__version__,),
epilog="This tool is provided as part of Spartacus learning environment under {} "
"licence. Feel free to distribute, modify, "
"contribute and learn!".format(__license__,))
parser.add_argument("-i", "--input",
required=True,
nargs=1,
type=str,
help="Define the input file to be used by the assembler.")
parser.add_argument("-o", "--output",
required=False,
nargs=1,
type=str,
default=UNDEFINED,
help="Define the output file where the assembled data will be written. If not specified, this "
"will default to the input file name, minus the extension, plus the --extension "
"provided value.")
parser.add_argument("-e", "--extension",
required=False,
nargs=1,
type=str,
default=DEFAULT_OUTPUT_EXTENSION,
help="Default output extension for the output file. This is useful if changing extension value "
"while keeping default output file name. Default value for this is {} please note that "
"the '.' has to be provided by the user!".format(DEFAULT_OUTPUT_EXTENSION,))
args = parser.parse_args()
args.input = args.input[0] # This originally come out as a list
args.output = args.output[0] if type(args.output) is not str else args.input.split(".")[0] # Using input as default
args.extension = args.extension[0] if type(args.extension) is not str else args.extension
args.output = args.output + args.extension if args.output.split(".")[-1] != "o" else args.output # Just so we don't have to keep typing this...
return args
Assembler.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录