anza-xyz / agave

Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
https://www.anza.xyz/
Apache License 2.0
446 stars 217 forks source link

Add --silent flag to Solana CLI for turning off stdout for error/info contexts when running commands #2472

Open sebscholl opened 3 months ago

sebscholl commented 3 months ago

Problem

When writing test suites for programs that wrap the Solana CLI, test runner logs get populated with unnecessary print statements (in the context of running tests) that makes the logs cluttered and difficult to read.

In a test runner (regardless of language or framework) the CLI error ends up printing to the same process as the test runner. For example, a test that's covering a failure scenario shows

image

......Error: Bad parameter: SIGNATURE
.error: Invalid value for '--signer <PUBKEY>': No such file or directory (os error 2)
.Error: Invalid signature
.

Finished in 0.39404 seconds (files took 3.66 seconds to load)
9 examples, 0 failures

Proposed Solution

It would be nice for the CLI to support error or log suppression (the opposite of the currently supported --verbose flag). When set, commands wouldn't print any contextual information or errors to the console and only return the data that they are being run to collect - or a blank value.

Example solution:

# Current
$ solana balance -k invalid_keypair
=> Error: Dynamic program error: No default signer found, run "solana-keygen new -o not_a_keypair" to create a new one
$ solana balance -k valid_keypair
=> 10 SOL

# Solution
$ solana balance -k invalid_keypair --silent
=> 
$ solana balance -k valid_keypair --silent
=> 10 SOL
diman-io commented 1 month ago

solana balance -k invalid_keypair 2>/dev/null