Skip to content

Commit faaa3dc

Browse files
committed
feat: add silent flag to enable piping claim data
1 parent fa16153 commit faaa3dc

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

pkg/rewards/claim.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"io"
89
"math/big"
910
"net/http"
1011
"sort"
@@ -74,6 +75,7 @@ func getClaimFlags() []cli.Flag {
7475
&ClaimTimestampFlag,
7576
&ProofStoreBaseURLFlag,
7677
&flags.VerboseFlag,
78+
&SilentFlag,
7779
}
7880

7981
allFlags := append(baseFlags, flags.GetSignerFlags()...)
@@ -85,6 +87,10 @@ func Claim(cCtx *cli.Context, p utils.Prompter) error {
8587
ctx := cCtx.Context
8688
logger := common.GetLogger(cCtx)
8789

90+
if cCtx.Bool(SilentFlag.Name) {
91+
logger = logging.NewTextSLogger(io.Discard, nil)
92+
}
93+
8894
config, err := readAndValidateClaimConfig(cCtx, logger)
8995
if err != nil {
9096
return eigenSdkUtils.WrapError("failed to read and validate claim config", err)
@@ -229,7 +235,7 @@ func Claim(cCtx *cli.Context, p utils.Prompter) error {
229235
solidityClaim := claimgen.FormatProofForSolidity(accounts.Root(), claim)
230236
jsonData, err := json.MarshalIndent(solidityClaim, "", " ")
231237
if err != nil {
232-
fmt.Println("Error marshaling JSON:", err)
238+
logger.Error("Error marshaling JSON:", err)
233239
return err
234240
}
235241
if !common.IsEmptyString(config.Output) {
@@ -240,24 +246,24 @@ func Claim(cCtx *cli.Context, p utils.Prompter) error {
240246
logger.Infof("Claim written to file: %s", config.Output)
241247
} else {
242248
fmt.Println(string(jsonData))
243-
fmt.Println()
244-
fmt.Println("To write to a file, use the --output flag")
249+
logger.Info("To write to a file, use the --output flag")
245250
}
246251
} else {
247252
if !common.IsEmptyString(config.Output) {
248-
fmt.Println("output file not supported for pretty output type")
249-
fmt.Println()
253+
logger.Info("output file not supported for pretty output type")
250254
}
251255
solidityClaim := claimgen.FormatProofForSolidity(accounts.Root(), claim)
252-
fmt.Println("------- Claim generated -------")
256+
logger.Info("------- Claim generated -------")
253257
common.PrettyPrintStruct(*solidityClaim)
254-
fmt.Println("-------------------------------")
255-
fmt.Println("To write to a file, use the --output flag")
258+
logger.Info("-------------------------------")
259+
logger.Info("To write to a file, use the --output flag")
260+
}
261+
if !cCtx.Bool(SilentFlag.Name) {
262+
txFeeDetails := common.GetTxFeeDetails(unsignedTx)
263+
logger.Info("\n")
264+
txFeeDetails.Print()
256265
}
257-
txFeeDetails := common.GetTxFeeDetails(unsignedTx)
258-
fmt.Println()
259-
txFeeDetails.Print()
260-
fmt.Println("To broadcast the claim, use the --broadcast flag")
266+
logger.Info("To broadcast the claim, use the --broadcast flag")
261267
}
262268

263269
return nil

pkg/rewards/flags.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,11 @@ var (
9191
Value: "all",
9292
EnvVars: []string{"REWARDS_CLAIM_TYPE"},
9393
}
94+
95+
SilentFlag = cli.BoolFlag{
96+
Name: "silent",
97+
Aliases: []string{"s"},
98+
Usage: "Suppress output except for claim",
99+
EnvVars: []string{"SILENT"},
100+
}
94101
)

0 commit comments

Comments
 (0)