diff --git a/cmd/frostfs-adm/internal/modules/morph/subnet.go b/cmd/frostfs-adm/internal/modules/morph/subnet.go index 95fa9e350b..16ee060e81 100644 --- a/cmd/frostfs-adm/internal/modules/morph/subnet.go +++ b/cmd/frostfs-adm/internal/modules/morph/subnet.go @@ -653,55 +653,14 @@ func addCommandInheritPreRun(par *cobra.Command, subs ...*cobra.Command) { } // registers flags and binds sub-commands for subnet commands. -// -// nolint: funlen func init() { - cmdSubnetCreate.Flags().StringP(flagSubnetWallet, "w", "", "Path to file with wallet") - _ = cmdSubnetCreate.MarkFlagRequired(flagSubnetWallet) - cmdSubnetCreate.Flags().StringP(flagSubnetAddress, "a", "", "Address in the wallet, optional") - - // get subnet flags - cmdSubnetGet.Flags().String(flagSubnetGetID, "", "ID of the subnet to read") - _ = cmdSubnetAdminAdd.MarkFlagRequired(flagSubnetGetID) - - // remove subnet flags - cmdSubnetRemove.Flags().String(flagSubnetRemoveID, "", "ID of the subnet to remove") - _ = cmdSubnetRemove.MarkFlagRequired(flagSubnetRemoveID) - cmdSubnetRemove.Flags().StringP(flagSubnetWallet, "w", "", "Path to file with wallet") - _ = cmdSubnetRemove.MarkFlagRequired(flagSubnetWallet) - cmdSubnetRemove.Flags().StringP(flagSubnetAddress, "a", "", "Address in the wallet, optional") - - // subnet administer flags - adminFlags := cmdSubnetAdmin.PersistentFlags() - adminFlags.String(flagSubnetAdminSubnet, "", "ID of the subnet to manage administrators") - _ = cmdSubnetAdmin.MarkFlagRequired(flagSubnetAdminSubnet) - adminFlags.String(flagSubnetAdminID, "", "Hex-encoded public key of the admin") - _ = cmdSubnetAdmin.MarkFlagRequired(flagSubnetAdminID) - adminFlags.StringP(flagSubnetWallet, "w", "", "Path to file with wallet") - _ = cmdSubnetAdmin.MarkFlagRequired(flagSubnetWallet) - adminFlags.StringP(flagSubnetAddress, "a", "", "Address in the wallet, optional") - - // add admin flags - cmdSubnetAdminAddFlags := cmdSubnetAdminAdd.Flags() - cmdSubnetAdminAddFlags.String(flagSubnetAdminAddGroup, "", fmt.Sprintf( - "Client group ID in text format (needed with --%s only)", flagSubnetAdminClient)) - cmdSubnetAdminAddFlags.Bool(flagSubnetAdminClient, false, "Add client admin instead of node one") - - // remove admin flags - cmdSubnetAdminRemoveFlags := cmdSubnetAdminRemove.Flags() - cmdSubnetAdminRemoveFlags.Bool(flagSubnetAdminClient, false, "Remove client admin instead of node one") - - // client managements flags - clientFlags := cmdSubnetClient.PersistentFlags() - clientFlags.String(flagSubnetClientSubnet, "", "ID of the subnet to be managed") - _ = cmdSubnetClient.MarkFlagRequired(flagSubnetClientSubnet) - clientFlags.String(flagSubnetClientGroup, "", "ID of the client group to work with") - _ = cmdSubnetClient.MarkFlagRequired(flagSubnetClientGroup) - clientFlags.String(flagSubnetClientID, "", "Client's user ID in FrostFS system in text format") - _ = cmdSubnetClient.MarkFlagRequired(flagSubnetClientID) - clientFlags.StringP(flagSubnetWallet, "w", "", "Path to file with wallet") - _ = cmdSubnetClient.MarkFlagRequired(flagSubnetWallet) - clientFlags.StringP(flagSubnetAddress, "a", "", "Address in the wallet, optional") + initCreateSubnetFlags() + initGetSubnetFlags() + initRemoveSubnetFlags() + initSubnetAdminFlags() + initSubnetAdminAddFlags() + initSubnetAdminRemoveFlags() + initClientManagementFlags() // add all admin managing commands to corresponding command section addCommandInheritPreRun(cmdSubnetAdmin, @@ -715,14 +674,7 @@ func init() { cmdSubnetClientRemove, ) - // subnet node flags - nodeFlags := cmdSubnetNode.PersistentFlags() - nodeFlags.StringP(flagSubnetWallet, "w", "", "Path to file with wallet") - _ = cmdSubnetNode.MarkFlagRequired(flagSubnetWallet) - nodeFlags.String(flagSubnetNode, "", "Hex-encoded public key of the node") - _ = cmdSubnetNode.MarkFlagRequired(flagSubnetNode) - nodeFlags.String(flagSubnetNodeSubnet, "", "ID of the subnet to manage nodes") - _ = cmdSubnetNode.MarkFlagRequired(flagSubnetNodeSubnet) + initSubnetNodeFlags() // add all node managing commands to corresponding command section addCommandInheritPreRun(cmdSubnetNode, @@ -730,10 +682,7 @@ func init() { cmdSubnetNodeRemove, ) - // subnet global flags - cmdSubnetFlags := cmdSubnet.PersistentFlags() - cmdSubnetFlags.StringP(endpointFlag, "r", "", "N3 RPC node endpoint") - _ = cmdSubnet.MarkFlagRequired(endpointFlag) + initSubnetGlobalFlags() // add all subnet commands to corresponding command section addCommandInheritPreRun(cmdSubnet, @@ -746,6 +695,77 @@ func init() { ) } +func initSubnetGlobalFlags() { + cmdSubnetFlags := cmdSubnet.PersistentFlags() + cmdSubnetFlags.StringP(endpointFlag, "r", "", "N3 RPC node endpoint") + _ = cmdSubnet.MarkFlagRequired(endpointFlag) +} + +func initSubnetNodeFlags() { + nodeFlags := cmdSubnetNode.PersistentFlags() + nodeFlags.StringP(flagSubnetWallet, "w", "", "Path to file with wallet") + _ = cmdSubnetNode.MarkFlagRequired(flagSubnetWallet) + nodeFlags.String(flagSubnetNode, "", "Hex-encoded public key of the node") + _ = cmdSubnetNode.MarkFlagRequired(flagSubnetNode) + nodeFlags.String(flagSubnetNodeSubnet, "", "ID of the subnet to manage nodes") + _ = cmdSubnetNode.MarkFlagRequired(flagSubnetNodeSubnet) +} + +func initClientManagementFlags() { + clientFlags := cmdSubnetClient.PersistentFlags() + clientFlags.String(flagSubnetClientSubnet, "", "ID of the subnet to be managed") + _ = cmdSubnetClient.MarkFlagRequired(flagSubnetClientSubnet) + clientFlags.String(flagSubnetClientGroup, "", "ID of the client group to work with") + _ = cmdSubnetClient.MarkFlagRequired(flagSubnetClientGroup) + clientFlags.String(flagSubnetClientID, "", "Client's user ID in FrostFS system in text format") + _ = cmdSubnetClient.MarkFlagRequired(flagSubnetClientID) + clientFlags.StringP(flagSubnetWallet, "w", "", "Path to file with wallet") + _ = cmdSubnetClient.MarkFlagRequired(flagSubnetWallet) + clientFlags.StringP(flagSubnetAddress, "a", "", "Address in the wallet, optional") +} + +func initSubnetAdminRemoveFlags() { + cmdSubnetAdminRemoveFlags := cmdSubnetAdminRemove.Flags() + cmdSubnetAdminRemoveFlags.Bool(flagSubnetAdminClient, false, "Remove client admin instead of node one") +} + +func initSubnetAdminAddFlags() { + cmdSubnetAdminAddFlags := cmdSubnetAdminAdd.Flags() + cmdSubnetAdminAddFlags.String(flagSubnetAdminAddGroup, "", fmt.Sprintf( + "Client group ID in text format (needed with --%s only)", flagSubnetAdminClient)) + cmdSubnetAdminAddFlags.Bool(flagSubnetAdminClient, false, "Add client admin instead of node one") +} + +func initSubnetAdminFlags() { + adminFlags := cmdSubnetAdmin.PersistentFlags() + adminFlags.String(flagSubnetAdminSubnet, "", "ID of the subnet to manage administrators") + _ = cmdSubnetAdmin.MarkFlagRequired(flagSubnetAdminSubnet) + adminFlags.String(flagSubnetAdminID, "", "Hex-encoded public key of the admin") + _ = cmdSubnetAdmin.MarkFlagRequired(flagSubnetAdminID) + adminFlags.StringP(flagSubnetWallet, "w", "", "Path to file with wallet") + _ = cmdSubnetAdmin.MarkFlagRequired(flagSubnetWallet) + adminFlags.StringP(flagSubnetAddress, "a", "", "Address in the wallet, optional") +} + +func initRemoveSubnetFlags() { + cmdSubnetRemove.Flags().String(flagSubnetRemoveID, "", "ID of the subnet to remove") + _ = cmdSubnetRemove.MarkFlagRequired(flagSubnetRemoveID) + cmdSubnetRemove.Flags().StringP(flagSubnetWallet, "w", "", "Path to file with wallet") + _ = cmdSubnetRemove.MarkFlagRequired(flagSubnetWallet) + cmdSubnetRemove.Flags().StringP(flagSubnetAddress, "a", "", "Address in the wallet, optional") +} + +func initGetSubnetFlags() { + cmdSubnetGet.Flags().String(flagSubnetGetID, "", "ID of the subnet to read") + _ = cmdSubnetAdminAdd.MarkFlagRequired(flagSubnetGetID) +} + +func initCreateSubnetFlags() { + cmdSubnetCreate.Flags().StringP(flagSubnetWallet, "w", "", "Path to file with wallet") + _ = cmdSubnetCreate.MarkFlagRequired(flagSubnetWallet) + cmdSubnetCreate.Flags().StringP(flagSubnetAddress, "a", "", "Address in the wallet, optional") +} + func testInvokeMethod(key keys.PrivateKey, method string, args ...any) ([]stackitem.Item, error) { c, err := getN3Client(viper.GetViper()) if err != nil {