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

WBOY
Release: 2024-02-06 11:45:04
forward
995 people have browsed it

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!