Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve error message of when a set of flags is required to use together #1358

Merged
merged 10 commits into from
Apr 30, 2024
Prev Previous commit
Next Next commit
added a test
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
  • Loading branch information
wangxiaoxuan273 committed Apr 24, 2024
commit faa3e35be39ece3b5b1ccb704dbbf458ce9c5b39
8 changes: 7 additions & 1 deletion cmd/oras/internal/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ func TestCheckMutuallyExclusiveFlags(t *testing.T) {

func TestCheckRequiredTogetherFlags(t *testing.T) {
fs := &pflag.FlagSet{}
var foo, bar, hello bool
var foo, bar, hello, world bool
fs.BoolVar(&foo, "foo", false, "foo test")
fs.BoolVar(&bar, "bar", false, "bar test")
fs.BoolVar(&hello, "hello", false, "hello test")
fs.BoolVar(&world, "world", false, "world test")
fs.Lookup("foo").Changed = true
fs.Lookup("bar").Changed = true
tests := []struct {
Expand All @@ -77,6 +78,11 @@ func TestCheckRequiredTogetherFlags(t *testing.T) {
[]string{"foo", "hello"},
true,
},
{
"none of --hello and --world is used, no error is returned",
[]string{"hello", "world"},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading