cobra icon indicating copy to clipboard operation
cobra copied to clipboard

Mark flag as required if another flag is present, but not inversely so

Open notthelewis opened this issue 2 months ago • 0 comments

Just want to start off by commending the project as a whole. Very nice library, have started using it for a tool I'm building and I'm already looking at replacing previous solutions I have in other projects.

As per the title, I'd like to know if there's a way to make flags RequiredTogether but only in one direction. For example, I'm reading in config something like this:

# Edit config for specific service
./tool edit -s "customerService" 

# Edit config for test on service
./tool edit -s "customerService" -t "shouldReturnTrue" 

And what I wanted to do was make it so that the -s flag can be used on it's own in isolation, but the -t flag cannot, as it depends on the -s flag.

My gut reaction was something like this:

EditCmd.MarkFlagsRequiredTogether("testName", "serviceName")

But of course, this works in both directions (i.e. service name also would require test name).

Is there any way around this?

notthelewis avatar Dec 13 '24 13:12 notthelewis