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

add a flag loader to allow flags to be set also via env vars #524

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tclemos
Copy link
Contributor

@tclemos tclemos commented Feb 28, 2025

Description

closes #521

allows current commands that depend on --rpc-url and --private-key flags to be set via env vars ETH_RPC_URL and PRIVATE_KEY respectively.

Testing

call any command that depends on --rpc-url or --private-key replacing the flag by the respective env var, the execution must happen exactly the same.

example:

# example 1 - regular flag usage
cdk ger dump --rpc-url https://sepolia.infura.io/v3/f694519bed4a476bbe8905b8c2e00ace --rollup-manager-address bali

# example 2 - inline env var set
$ ETH_RPC_URL="https://sepolia.infura.io/v3/f694519bed4a476bbe8905b8c2e00ace" cdk ger dump --rollup-manager-address bali

# example 3 - export
$ export ETH_RPC_URL="https://sepolia.infura.io/v3/f694519bed4a476bbe8905b8c2e00ace"
$ cdk ger dump --rollup-manager-address bali

@tclemos tclemos self-assigned this Feb 28, 2025
Copy link
Member

@leovct leovct left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, left a few comments :)

Tested ETH_RPC_URL and it seemed to work well!

Comment on lines +43 to +44
rpcUrl, _ = flag_loader.GetRpcUrlFlagValue(cmd, false)
testPrivateHexKey, _ = flag_loader.GetPrivateKeyFlagValue(cmd, false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I know flag_loader.GetRpcUrlFlagValue(cmd, false) should not return any error but I would still check if the error returned is nil. Just in case the implementation changes in the future.

@@ -0,0 +1,41 @@
package flag_loader
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would avoid passing a boolean to the function, as this makes the code harder to debug and maintain.

I'd for something like:

func getOptionalFlagValue(cmd *cobra.Command, flagName, envVarName string) *string {}
func getRequiredFlagValue(cmd *cobra.Command, flagName, envVarName string) (*string, error) {
  // leverage getOptionalFlagValue
}

func GetRequiredRpcUrlFlagValue(cmd *cobra.Command) (*string, error) {}
func GetOptionalRpcUrlFlagValue(cmd *cobra.Command) *string {}

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

POLYCLI_RPC_URL env var
2 participants