spf13 / pflag

Drop-in replacement for Go's flag package, implementing POSIX/GNU-style --flags.
BSD 3-Clause "New" or "Revised" License
2.43k stars 348 forks source link

Whether nargs is supported #391

Open Anthony-Dong opened 11 months ago

Anthony-Dong commented 11 months ago
import argparse

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Test Cli')
    parser.add_argument('--file', '-f', dest='files', nargs='+', type=str, required=False)
    args = parser.parse_args()
    print(args)

In python, nagrs is convenient for dealing with array types, but with pflag we need to define flag repeatedly

➜  python git:(master) ✗ python main.py -f main.py init.py 
Namespace(files=['main.py', 'init.py'])