问题
i create an script with the following args:
def arguments():
''' gets arguments '''
parser = argparse.ArgumentParser(
description="This scripts start the setup for the project, this setup is defined by the Core \
Module of each Setup, so first it download the scripts from that module and \
proceed to run them from a temporal directory installing the desired \
components and applying the configuration."
)
parser.add_argument(
"--project_name",
help="The name for the project",
type=str,
required=True)
parser.add_argument(
"--project_dir",
help="The dir where to create the project",
type=str,
required=True)
parser.add_argument(
"--core_npm_package",
type=str,
help="The NPM core package",
required=True)
parser.add_argument(
"--npm_packages",
nargs='+',
type=str,
help="The NPM package for install if no source code is required",
required=True)
''' the modules data array in JSON format, it follows the structure defined in
src/app/modules/setup.module/vos/module.vo.ts '''
parser.add_argument(
"--modules_data",
type=str,
help="The data of each module in JSON format",
required=True)
return parser.parse_args()
Then when i try to run the script using python3 with the following arguments:
python3 run_setup.py --project_name TEST_PROJECT --project_dir /home/diego/Desktop/ --npm_packages @creard_nativescript_ng/auth.module --core_npm_package @creard_nativescript_ng/core.module --modules_data 'some long json or any data'
I got the output:
usage: run_setup.py [-h] [--project_name PROJECT_NAME]
[--project_dir PROJECT_DIR]
run_setup.py: error: unrecognized arguments: --npm_packages @creard_nativescript_ng/auth.module --core_npm_package @creard_nativescript_ng/core.module --modules_data [{"moduleName":"auth.module","package":"@creard_nativescript_ng/auth.module","options":{"loginConfig":{"title":"title modified"}}}]
But if i remove any argument (also --modules_data that i think is the culprit) always points that i miss some argument, no matter which argument, but all together don't work.
来源:https://stackoverflow.com/questions/48715099/python-argparse-seems-not-to-support-too-long-arguments