Skip to content

Commit

Permalink
check follow and num flags exclusivity
Browse files Browse the repository at this point in the history
  • Loading branch information
christophercampbell committed Jan 28, 2025
1 parent 84e2fe2 commit 44c2e67
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 8 additions & 0 deletions cli/cli/command_framework/lowlevel/flags/parsed_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ func (flags *ParsedFlags) GetBool(name string) (bool, error) {
}
return value, nil
}

func (flags *ParsedFlags) HasFlag(name string) bool {
_, err := flags.cmdFlagsSet.GetString(name)
if err != nil {

Check failure on line 63 in cli/cli/command_framework/lowlevel/flags/parsed_flags.go

View workflow job for this annotation

GitHub Actions / golang-lint (cli/cli)

S1008: should use 'return err != nil' instead of 'if err != nil { return true }; return false' (gosimple)
return true
}
return false
}
12 changes: 9 additions & 3 deletions cli/cli/commands/service/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ package logs

import (
"context"
"errors"
"fmt"
"os"
"os/signal"
"strconv"

"github.com/fatih/color"
"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/services"
"github.com/kurtosis-tech/kurtosis/api/golang/engine/kurtosis_engine_rpc_api_bindings"
Expand All @@ -24,9 +29,6 @@ import (
"github.com/kurtosis-tech/kurtosis/metrics-library/golang/lib/metrics_client"
"github.com/kurtosis-tech/stacktrace"
"github.com/sirupsen/logrus"
"os"
"os/signal"
"strconv"
)

const (
Expand Down Expand Up @@ -194,6 +196,10 @@ func run(
return stacktrace.Propagate(err, "An error occurred getting the should-follow-logs flag using key '%v'", shouldFollowLogsFlagKey)
}

if shouldFollowLogs && flags.HasFlag(returnNumLogsFlagKey) {
return stacktrace.Propagate(errors.ErrUnsupported, "`%v` flag cannot be used with `%v` flag", shouldFollowLogsFlagKey, returnNumLogsFlagKey)
}

shouldReturnAllLogs, err := flags.GetBool(returnAllLogsFlagKey)
if err != nil {
return stacktrace.Propagate(err, "An error occurred getting the 'all' flag using key '%v'", returnAllLogsFlagKey)
Expand Down

0 comments on commit 44c2e67

Please sign in to comment.