python using argparse.ArgumentParser method
Omit the dest
parameter when using a positional argument. The name supplied for the positional argument will be the name of the argument:
import argparse
myparser = argparse.ArgumentParser(description='parser test')
myparser.add_argument("product_1", help="enter product1")
myparser.add_argument("product_2", help="enter product2")
args = myparser.parse_args()
firstProduct = args.product_1
secondProduct = args.product_2
print(firstProduct, secondProduct)
Running % test.py foo bar
prints
('foo', 'bar')
In addition to unutbu's answer, you may also use the metavar
attribute in order to make the destination variable and the variable name that appears in the help menus different, as shown in this link.
For example if you do:
myparser.add_argument("firstProduct", metavar="product_1", help="enter product1")
You will have the argument available for you in args.firstProduct
but have it listed as product_1
in the help.