Home  >  Article  >  Backend Development  >  In golang, can I use the flag package to define a flag that optionally accepts a string argument?

In golang, can I use the flag package to define a flag that optionally accepts a string argument?

WBOY
WBOYforward
2024-02-06 11:45:041030browse

In golang, can I use the flag package to define a flag that optionally accepts a string argument?

Question content

What I want to do is be able to run these three scenarios:

cmd --test --branchrelease

cmd --test all --branch release

cmd --branch release

You can specify --test yourself without parameters (such as Boolean values), and you can also specify parameters.

I don't think this is possible because the next flag (--branch) is used as an argument to --test when no arguments are given, but I thought I'd ask in case I'm missing something . p>

Correct Answer


No, there is no such option.

The above is the detailed content of In golang, can I use the flag package to define a flag that optionally accepts a string argument?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete