Skip to content

Commit

Permalink
Merge pull request #468 from bruin-data/update-flag-validation
Browse files Browse the repository at this point in the history
Update flag validation
  • Loading branch information
terzioglub authored Feb 25, 2025
2 parents 767d096 + 5f9a8e5 commit bbbdacd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions cmd/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func validateFlags(connection, query, asset, environment string) error {
hasEnvironment := environment != ""

switch {
case hasConnection || hasQuery:
case hasConnection:
if !(hasConnection && hasQuery) {
return errors.New("direct query mode requires both --connection and --query flags")
}
Expand All @@ -114,14 +114,15 @@ func validateFlags(connection, query, asset, environment string) error {
return nil

case hasAsset:
if hasConnection || hasQuery {
if hasConnection {
return errors.New("asset mode (--asset) cannot be combined with direct query mode (--connection and --query)")
}
return nil
default:
return errors.New("must use either:\n" +
"1. Direct query mode (--connection and --query), or\n" +
"2. Asset mode (--asset with optional --environment)")
"2. Asset mode (--asset with optional --environment), or\n" +
"3. Auto-detect mode (--asset to detect the connection and --query to run arbitrary queries)")
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestValidateFlags(t *testing.T) {
name: "missing connection in direct mode",
query: "SELECT * FROM table",
expectError: true,
errorMsg: "direct query mode requires both --connection and --query flags",
errorMsg: "must use either:\n1. Direct query mode (--connection and --query), or\n2. Asset mode (--asset with optional --environment), or\n3. Auto-detect mode (--asset to detect the connection and --query to run arbitrary queries)",
},
{
name: "mixing direct query and asset modes",
Expand All @@ -85,7 +85,7 @@ func TestValidateFlags(t *testing.T) {
{
name: "no flags provided",
expectError: true,
errorMsg: "must use either:\n1. Direct query mode (--connection and --query), or\n2. Asset mode (--asset with optional --environment)",
errorMsg: "must use either:\n1. Direct query mode (--connection and --query), or\n2. Asset mode (--asset with optional --environment), or\n3. Auto-detect mode (--asset to detect the connection and --query to run arbitrary queries)",
},
}

Expand Down

0 comments on commit bbbdacd

Please sign in to comment.