2

I'm trying to debug the following script in VS code:

import os
import argparse

def parseArgs():
    parser = argparse.ArgumentParser()

    parser.add_argument("-cn", "--cert_names", nargs="+", default=None, help='Provide one or several cert names to be created')
    parser.add_argument('-pw', '--password', action='store_true', help='Provide a password for private keys and certs')
    args = parser.parse_args()
    
    if not args.cert_names:
        print("Please provide one or more cert names")

def main():
    parseArgs()
    print(args.cert_names)

This is the launch.json file I'm using:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File and libraries",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode" : false,
            "args": ["-cn cert1 cert2 cert3 cert4"],
            "cwd": "${fileDirname}",
        }
    ]
}

After I run the debugger in VS code I get the following message: create_certs.py: error: unrecognized arguments: -cn cert1 cert2 cert3 cert4

What I want is to pass that list as an argument to the script, I've also tried with "args": ["--cert_names cert1 cert2 cert3 cert4"], and same result,

Does anyone know where I am going wrong?

1
  • I'm unfamiliar with vsc and launch.json, but maybe try 'args': ['-cn', 'cert1',...] instead? Commented Feb 10, 2021 at 20:47

1 Answer 1

1

Try putting the args separately, like:

"args": ["-cn", "cert1", "cert2", "cert3", "cert4"],

otherwise they all get passed as one massive argument.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.