Skip to content

Grouped flags #2766

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

Merged
merged 19 commits into from
May 12, 2025
Merged

Grouped flags #2766

merged 19 commits into from
May 12, 2025

Conversation

sukantoraymond
Copy link
Collaborator

@sukantoraymond sukantoraymond commented Apr 24, 2025

Grouped flags for blockchain deploy cmd, which will be extended to other commands.

Grouping flags cuts down on the number of flags displayed to users and enables users to discover which functionality (ICM / POS config) a flag serves.

This PR currently only groups ICM flags and POS flags. We can group more flags together: network flags, control & auth flags (ledger, keys, control keys, etc), non sov flags, etc. This flags will only be grouped, but never hidden.

This is what it looks like now: (we cut it down from 74 flags to 48 flags!)

AVL-7H2W7V:avalanche-cli raymondsukanto$ ./bin/avalanche blockchain deploy 
Usage:
  avalanche blockchain deploy [blockchainName] [flags]

Flags:
      --aggregator-log-level string    log level to use with signature aggregator (default "Debug")
      --aggregator-log-to-stdout       use stdout for signature aggregator logs
      --auth-keys strings              control keys that will be used to authenticate chain creation
      --avalanchego-path string        use this avalanchego binary path
      --avalanchego-version string     use this version of avalanchego (ex: v1.17.12) (default "latest")
      --balance float                  set the AVAX balance of each bootstrap validator that will be used for continuous fee on P-Chain (default 0.1)
      --bootstrap-endpoints strings    take validator node info from the given endpoints
      --bootstrap-filepath string      JSON file path that provides details about bootstrap validators, leave Node-ID and BLS values empty if using --generate-node-id=true
      --change-owner-address string    address that will receive change if node is no longer L1 validator
      --control-keys strings           addresses that may make blockchain changes
      --convert-only                   avoid node track, restart and poa manager setup
  -e, --ewoq                           use ewoq key [local/devnet deploy only]
      --generate-node-id               whether to create new node id for bootstrap validators (Node-ID and BLS values in bootstrap JSON file will be overridden if --bootstrap-filepath flag is used)
  -h, --help                           help for deploy
      --http-port uints                http port for node(s) (default [])
  -k, --key string                     select the key to use [fuji/devnet deploy only]
  -g, --ledger                         use ledger instead of key (always true on mainnet, defaults to false on fuji/devnet)
      --ledger-addrs strings           use the given ledger addresses
      --mainnet-chain-id uint32        use different ChainID for mainnet deployment
      --num-bootstrap-validators int   (only if --generate-node-id is true) number of bootstrap validators to set up in sovereign L1 validator)
      --num-local-nodes int            number of nodes to be created on local machine
      --num-nodes uint32               number of nodes to be created on local network deploy (default 2)
      --output-tx-path string          file path of the blockchain creation tx
      --partial-sync                   set primary network partial sync for new validators (default true)
  -s, --same-control-key               use the fee-paying key as control key
      --staking-port uints             staking port for node(s) (default [])
  -u, --subnet-id string               do not create a subnet, deploy the blockchain into the given subnet id
      --subnet-only                    only create a subnet
      --threshold uint32               required number of control key signatures to make blockchain changes
      --use-local-machine              use local machine as a blockchain validator

Global Flags:
      --config string       config file (default is $HOME/.avalanche-cli/config.json)
      --log-level string    log level for the application (default "ERROR")
      --skip-update-check   skip check for new versions

Network Flags (Select One):
  --cluster string      operate on the given cluster
  --devnet      operate on a devnet network
  --endpoint string     use the given endpoint for network operations
  --fuji        operate on fuji (alias to `testnet`)
  --local       operate on a local network
  --mainnet     operate on mainnet
  --testnet     operate on testnet (alias to `fuji`)

ICM Flags:
  (hidden) Use --show-icm-flags to show these options

Proof Of Stake Flags:
  (hidden) Use --show-pos-flags to show these options
Error: requires 1 arg(s), got 0

To show hidden grouped flags:

AVL-7H2W7V:avalanche-cli raymondsukanto$ ./bin/avalanche blockchain deploy --show-icm-flags
Usage:
  avalanche blockchain deploy [blockchainName] [flags]

Flags:
      --aggregator-log-level string    log level to use with signature aggregator (default "Debug")
      --aggregator-log-to-stdout       use stdout for signature aggregator logs
      --auth-keys strings              control keys that will be used to authenticate chain creation
      --avalanchego-path string        use this avalanchego binary path
      --avalanchego-version string     use this version of avalanchego (ex: v1.17.12) (default "latest")
      --balance float                  set the AVAX balance of each bootstrap validator that will be used for continuous fee on P-Chain (default 0.1)
      --bootstrap-endpoints strings    take validator node info from the given endpoints
      --bootstrap-filepath string      JSON file path that provides details about bootstrap validators, leave Node-ID and BLS values empty if using --generate-node-id=true
      --change-owner-address string    address that will receive change if node is no longer L1 validator
      --control-keys strings           addresses that may make blockchain changes
      --convert-only                   avoid node track, restart and poa manager setup
  -e, --ewoq                           use ewoq key [local/devnet deploy only]
      --generate-node-id               whether to create new node id for bootstrap validators (Node-ID and BLS values in bootstrap JSON file will be overridden if --bootstrap-filepath flag is used)
  -h, --help                           help for deploy
      --http-port uints                http port for node(s) (default [])
  -k, --key string                     select the key to use [fuji/devnet deploy only]
  -g, --ledger                         use ledger instead of key (always true on mainnet, defaults to false on fuji/devnet)
      --ledger-addrs strings           use the given ledger addresses
      --mainnet-chain-id uint32        use different ChainID for mainnet deployment
      --num-bootstrap-validators int   (only if --generate-node-id is true) number of bootstrap validators to set up in sovereign L1 validator)
      --num-local-nodes int            number of nodes to be created on local machine
      --num-nodes uint32               number of nodes to be created on local network deploy (default 2)
      --output-tx-path string          file path of the blockchain creation tx
      --partial-sync                   set primary network partial sync for new validators (default true)
  -s, --same-control-key               use the fee-paying key as control key
      --staking-port uints             staking port for node(s) (default [])
  -u, --subnet-id string               do not create a subnet, deploy the blockchain into the given subnet id
      --subnet-only                    only create a subnet
      --threshold uint32               required number of control key signatures to make blockchain changes
      --use-local-machine              use local machine as a blockchain validator

Global Flags:
      --config string       config file (default is $HOME/.avalanche-cli/config.json)
      --log-level string    log level for the application (default "ERROR")
      --skip-update-check   skip check for new versions

Network Flags (Select One):
  --cluster string   operate on the given cluster
  --devnet           operate on a devnet network
  --endpoint string  use the given endpoint for network operations
  --fuji             operate on fuji (alias to `testnet`)
  --local            operate on a local network
  --mainnet          operate on mainnet
  --testnet          operate on testnet (alias to `fuji`)

ICM Flags:
  --cchain-funding-key string                          key to be used to fund relayer account on cchain
  --cchain-icm-key string                              key to be used to pay for ICM deploys on C-Chain
  --icm-key string                                     key to be used to pay for ICM deploys
  --icm-version string                                 ICM version to deploy
  --noicm                                              skip automatic ICM deploy
  --relay-cchain                                       relay C-Chain as source and destination
  --relayer-allow-private-ips                          allow relayer to connec to private ips
  --relayer-amount float64                             automatically fund relayer fee payments with the given amount
  --relayer-key string                                 key to be used by default both for rewards and to pay fees
  --relayer-log-level string                           log level to be used for relayer logs
  --relayer-path string                                relayer binary to use
  --relayer-version string                             relayer version to deploy
  --skip-icm-deploy                                    Skip automatic ICM deploy
  --skip-local-teleporter                              skip automatic ICM deploy on local networks [to be deprecated]
  --skip-relayer                                       skip relayer deploy
  --skip-teleporter-deploy                             skip automatic ICM deploy
  --teleporter-messenger-contract-address-path string  path to an ICM Messenger contract address file
  --teleporter-messenger-deployer-address-path string  path to an ICM Messenger deployer address file
  --teleporter-messenger-deployer-tx-path string       path to an ICM Messenger deployer tx file
  --teleporter-registry-bytecode-path string           path to an ICM Registry bytecode file
  --teleporter-version string                          ICM version to deploy

Proof Of Stake Flags:
  (hidden) Use --show-pos-flags to show these options
Error: requires 1 arg(s), got 0

@sukantoraymond
Copy link
Collaborator Author

sukantoraymond commented Apr 24, 2025

This is what it looked like previously: (74 flags!) compared to 48 grouped!

AVL-7H2W7V:avalanche-cli raymondsukanto$ ./bin/avalanche blockchain deploy 
Usage:
  avalanche blockchain deploy [blockchainName] [flags]

Flags:
      --aggregator-log-level string                         log level to use with signature aggregator (default "Debug")
      --aggregator-log-to-stdout                            use stdout for signature aggregator logs
      --auth-keys strings                                   control keys that will be used to authenticate chain creation
      --avalanchego-path string                             use this avalanchego binary path
      --avalanchego-version string                          use this version of avalanchego (ex: v1.17.12) (default "latest")
      --balance float                                       set the AVAX balance of each bootstrap validator that will be used for continuous fee on P-Chain (default 0.1)
      --bootstrap-endpoints strings                         take validator node info from the given endpoints
      --bootstrap-filepath string                           JSON file path that provides details about bootstrap validators, leave Node-ID and BLS values empty if using --generate-node-id=true
      --cchain-funding-key string                           key to be used to fund relayer account on cchain
      --cchain-icm-key string                               key to be used to pay for ICM deploys on C-Chain
      --change-owner-address string                         address that will receive change if node is no longer L1 validator
      --cluster string                                      operate on the given cluster
      --control-keys strings                                addresses that may make blockchain changes
      --convert-only                                        avoid node track, restart and poa manager setup
      --devnet                                              operate on a devnet network
      --endpoint string                                     use the given endpoint for network operations
  -e, --ewoq                                                use ewoq key [fuji/devnet deploy only]
  -f, --fuji testnet                                        operate on fuji (alias to testnet
      --generate-node-id                                    whether to create new node id for bootstrap validators (Node-ID and BLS values in bootstrap JSON file will be overridden if --bootstrap-filepath flag is used)
  -h, --help                                                help for deploy
      --http-port uints                                     http port for node(s) (default [])
      --icm-key string                                      key to be used to pay for ICM deploys (default "cli-teleporter-deployer")
      --icm-version string                                  ICM version to deploy (default "latest")
  -k, --key string                                          select the key to use [fuji/devnet deploy only]
  -g, --ledger                                              use ledger instead of key (always true on mainnet, defaults to false on fuji/devnet)
      --ledger-addrs strings                                use the given ledger addresses
  -l, --local                                               operate on a local network
  -m, --mainnet                                             operate on mainnet
      --mainnet-chain-id uint32                             use different ChainID for mainnet deployment
      --noicm                                               skip automatic ICM deploy
      --num-bootstrap-validators int                        (only if --generate-node-id is true) number of bootstrap validators to set up in sovereign L1 validator)
      --num-local-nodes int                                 number of nodes to be created on local machine
      --num-nodes uint32                                    number of nodes to be created on local network deploy (default 2)
      --output-tx-path string                               file path of the blockchain creation tx
      --partial-sync                                        set primary network partial sync for new validators (default true)
      --pos-maximum-stake-amount uint                       maximum stake amount (default 1000)
      --pos-maximum-stake-multiplier uint8                  maximum stake multiplier (default 1)
      --pos-minimum-delegation-fee uint16                   minimum delegation fee (default 1)
      --pos-minimum-stake-amount uint                       minimum stake amount (default 1)
      --pos-minimum-stake-duration uint                     minimum stake duration (in seconds) (default 100)
      --pos-weight-to-value-factor uint                     weight to value factor (default 1)
      --relay-cchain                                        relay C-Chain as source and destination (default true)
      --relayer-allow-private-ips                           allow relayer to connec to private ips (default true)
      --relayer-amount float                                automatically fund relayer fee payments with the given amount
      --relayer-key string                                  key to be used by default both for rewards and to pay fees
      --relayer-log-level string                            log level to be used for relayer logs (default "info")
      --relayer-path string                                 relayer binary to use
      --relayer-version string                              relayer version to deploy (default "latest")
  -s, --same-control-key                                    use the fee-paying key as control key
      --skip-icm-deploy                                     skip automatic ICM deploy
      --skip-local-teleporter                               skip automatic ICM deploy on local networks [to be deprecated]
      --skip-relayer                                        skip relayer deploy
      --skip-teleporter-deploy                              skip automatic ICM deploy
      --staking-port uints                                  staking port for node(s) (default [])
  -u, --subnet-id string                                    do not create a subnet, deploy the blockchain into the given subnet id
      --subnet-only                                         only create a subnet
      --teleporter-messenger-contract-address-path string   path to an ICM Messenger contract address file
      --teleporter-messenger-deployer-address-path string   path to an ICM Messenger deployer address file
      --teleporter-messenger-deployer-tx-path string        path to an ICM Messenger deployer tx file
      --teleporter-registry-bytecode-path string            path to an ICM Registry bytecode file
      --teleporter-version string                           ICM version to deploy (default "latest")
  -t, --testnet fuji                                        operate on testnet (alias to fuji)
      --threshold uint32                                    required number of control key signatures to make blockchain changes
      --use-local-machine                                   use local machine as a blockchain validator

Global Flags:
      --config string       config file (default is $HOME/.avalanche-cli/config.json)
      --log-level string    log level for the application (default "ERROR")
      --skip-update-check   skip check for new versions


Usage error: accepts 1 arg(s), received 0

@@ -126,6 +127,35 @@ func AddNetworkFlagsToCmd(cmd *cobra.Command, networkFlags *NetworkFlags, addEnd
}
}

func GetNetworkFlagsGroup(cmd *cobra.Command, networkFlags *NetworkFlags, addEndpoint bool, supportedNetworkOptions []NetworkOption) flags.GroupedFlags {
return flags.RegisterFlagGroup(cmd, "Network Flags (Select One)", "show-network-flags", true, func(set *pflag.FlagSet) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

network group is always visible

@@ -126,6 +128,35 @@ func AddNetworkFlagsToCmd(cmd *cobra.Command, networkFlags *NetworkFlags, addEnd
}
}

func GetNetworkFlagsGroup(cmd *cobra.Command, networkFlags *NetworkFlags, addEndpoint bool, supportedNetworkOptions []NetworkOption) flags.GroupedFlags {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should replace the existing AddNetworkFlagsToCmd command that is used by other commands right now


func flagExists(target string, args []string) bool {
for _, arg := range args {
if arg == target {
Copy link
Collaborator

Choose a reason for hiding this comment

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

how do we handle option casing (upper case\lower case) in CLI in general?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good question, we always put lowercase for flags in CLI. Not sure if cobra (the CLI SDK that we use) automatically does this for us.

Copy link
Collaborator

Choose a reason for hiding this comment

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

found this https://github.com/spf13/pflag/blob/master/flag.go#L224 so i assume if we don't do anything special, the pflag pkg will honor the casing we passed in

Copy link
Collaborator

@Tonix517 Tonix517 left a comment

Choose a reason for hiding this comment

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

LGTM - leaving to @felipemadero for the final stamp

@github-project-automation github-project-automation bot moved this from Backlog 🗄️ to In Review 👀 in avalanchego Apr 28, 2025
requiredArgCount := 1
if len(args) != requiredArgCount {
_ = cmd.Help() // show full help with flag grouping
return utils.ErrWrongArgCount(requiredArgCount, len(args))
Copy link
Collaborator

Choose a reason for hiding this comment

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

also probably this error

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same as above

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean move utils.ErrWrongArgCount into cobrautils.ErrWrongArgCount

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is done in #2803

}
return err
return nil
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

remaining functions will be changed as we refactor more of the codebase

err := cobra.ExactArgs(n)(cmd, args)
if err != nil {
err = NewUsageError(cmd, err)
if len(args) != n {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this change is required, because otherwise this is what it looks like

AVL-7H2W7V:avalanche-cli raymondsukanto$ ./bin/avalanche blockchain deploy
Usage:
  avalanche blockchain deploy [blockchainName] [flags]

Flags:
      --aggregator-log-level string    log level to use with signature aggregator (default "Debug")
      --aggregator-log-to-stdout       use stdout for signature aggregator logs
      --auth-keys strings              control keys that will be used to authenticate chain creation
      --avalanchego-path string        use this avalanchego binary path
      --avalanchego-version string     use this version of avalanchego (ex: v1.17.12) (default "latest")
      --balance float                  set the AVAX balance of each bootstrap validator that will be used for continuous fee on P-Chain (default 0.1)
      --bootstrap-endpoints strings    take validator node info from the given endpoints
      --bootstrap-filepath string      JSON file path that provides details about bootstrap validators, leave Node-ID and BLS values empty if using --generate-node-id=true
      --change-owner-address string    address that will receive change if node is no longer L1 validator
      --control-keys strings           addresses that may make blockchain changes
      --convert-only                   avoid node track, restart and poa manager setup
  -e, --ewoq                           use ewoq key [local/devnet deploy only]
      --generate-node-id               whether to create new node id for bootstrap validators (Node-ID and BLS values in bootstrap JSON file will be overridden if --bootstrap-filepath flag is used)
  -h, --help                           help for deploy
      --http-port uints                http port for node(s) (default [])
  -k, --key string                     select the key to use [fuji/devnet deploy only]
  -g, --ledger                         use ledger instead of key (always true on mainnet, defaults to false on fuji/devnet)
      --ledger-addrs strings           use the given ledger addresses
      --mainnet-chain-id uint32        use different ChainID for mainnet deployment
      --num-bootstrap-validators int   (only if --generate-node-id is true) number of bootstrap validators to set up in sovereign L1 validator)
      --num-local-nodes int            number of nodes to be created on local machine
      --num-nodes uint32               number of nodes to be created on local network deploy (default 2)
      --output-tx-path string          file path of the blockchain creation tx
      --partial-sync                   set primary network partial sync for new validators (default true)
  -s, --same-control-key               use the fee-paying key as control key
      --staking-port uints             staking port for node(s) (default [])
  -u, --subnet-id string               do not create a subnet, deploy the blockchain into the given subnet id
      --subnet-only                    only create a subnet
      --threshold uint32               required number of control key signatures to make blockchain changes
      --use-local-machine              use local machine as a blockchain validator

Global Flags:
      --config string       config file (default is $HOME/.avalanche-cli/config.json)
      --log-level string    log level for the application (default "ERROR")
      --skip-update-check   skip check for new versions

Network Flags (Select One):
  --cluster string   operate on the given cluster
  --devnet           operate on a devnet network
  --endpoint string  use the given endpoint for network operations
  --fuji             operate on fuji (alias to `testnet`)
  --local            operate on a local network
  --mainnet          operate on mainnet
  --testnet          operate on testnet (alias to `fuji`)

ICM Flags:
  (hidden) Use --show-icm-flags to show these options

Proof Of Stake Flags:
  (hidden) Use --show-pos-flags to show these options
Usage:
  avalanche blockchain deploy [blockchainName] [flags]

Flags:
      --aggregator-log-level string    log level to use with signature aggregator (default "Debug")
      --aggregator-log-to-stdout       use stdout for signature aggregator logs
      --auth-keys strings              control keys that will be used to authenticate chain creation
      --avalanchego-path string        use this avalanchego binary path
      --avalanchego-version string     use this version of avalanchego (ex: v1.17.12) (default "latest")
      --balance float                  set the AVAX balance of each bootstrap validator that will be used for continuous fee on P-Chain (default 0.1)
      --bootstrap-endpoints strings    take validator node info from the given endpoints
      --bootstrap-filepath string      JSON file path that provides details about bootstrap validators, leave Node-ID and BLS values empty if using --generate-node-id=true
      --change-owner-address string    address that will receive change if node is no longer L1 validator
      --control-keys strings           addresses that may make blockchain changes
      --convert-only                   avoid node track, restart and poa manager setup
  -e, --ewoq                           use ewoq key [local/devnet deploy only]
      --generate-node-id               whether to create new node id for bootstrap validators (Node-ID and BLS values in bootstrap JSON file will be overridden if --bootstrap-filepath flag is used)
  -h, --help                           help for deploy
      --http-port uints                http port for node(s) (default [])
  -k, --key string                     select the key to use [fuji/devnet deploy only]
  -g, --ledger                         use ledger instead of key (always true on mainnet, defaults to false on fuji/devnet)
      --ledger-addrs strings           use the given ledger addresses
      --mainnet-chain-id uint32        use different ChainID for mainnet deployment
      --num-bootstrap-validators int   (only if --generate-node-id is true) number of bootstrap validators to set up in sovereign L1 validator)
      --num-local-nodes int            number of nodes to be created on local machine
      --num-nodes uint32               number of nodes to be created on local network deploy (default 2)
      --output-tx-path string          file path of the blockchain creation tx
      --partial-sync                   set primary network partial sync for new validators (default true)
  -s, --same-control-key               use the fee-paying key as control key
      --staking-port uints             staking port for node(s) (default [])
  -u, --subnet-id string               do not create a subnet, deploy the blockchain into the given subnet id
      --subnet-only                    only create a subnet
      --threshold uint32               required number of control key signatures to make blockchain changes
      --use-local-machine              use local machine as a blockchain validator

Global Flags:
      --config string       config file (default is $HOME/.avalanche-cli/config.json)
      --log-level string    log level for the application (default "ERROR")
      --skip-update-check   skip check for new versions


Usage error: accepts 1 arg(s), received 0

Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add an empty line between the help and the error message?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

addressed

@sukantoraymond sukantoraymond merged commit c6219fc into main May 12, 2025
36 checks passed
@sukantoraymond sukantoraymond deleted the grouped-flags branch May 12, 2025 15:59
@github-project-automation github-project-automation bot moved this to Done 🎉 in avalanchego May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants