ExtractCommandValue extracts the value from a command result using the fast enum-based approach
(cmd interface{})
| 8480 | |
| 8481 | // ExtractCommandValue extracts the value from a command result using the fast enum-based approach |
| 8482 | func ExtractCommandValue(cmd interface{}) (interface{}, error) { |
| 8483 | // First try to get the command type using the interface |
| 8484 | if cmdTypeGetter, ok := cmd.(CmdTypeGetter); ok { |
| 8485 | cmdType := cmdTypeGetter.GetCmdType() |
| 8486 | |
| 8487 | // Use fast type-based extraction |
| 8488 | switch cmdType { |
| 8489 | case CmdTypeGeneric: |
| 8490 | if genericCmd, ok := cmd.(interface { |
| 8491 | Val() interface{} |
| 8492 | Err() error |
| 8493 | }); ok { |
| 8494 | return genericCmd.Val(), genericCmd.Err() |
| 8495 | } |
| 8496 | case CmdTypeString: |
| 8497 | if stringCmd, ok := cmd.(interface { |
| 8498 | Val() string |
| 8499 | Err() error |
| 8500 | }); ok { |
| 8501 | return stringCmd.Val(), stringCmd.Err() |
| 8502 | } |
| 8503 | case CmdTypeInt: |
| 8504 | if intCmd, ok := cmd.(interface { |
| 8505 | Val() int64 |
| 8506 | Err() error |
| 8507 | }); ok { |
| 8508 | return intCmd.Val(), intCmd.Err() |
| 8509 | } |
| 8510 | case CmdTypeUint: |
| 8511 | if uintCmd, ok := cmd.(interface { |
| 8512 | Val() uint64 |
| 8513 | Err() error |
| 8514 | }); ok { |
| 8515 | return uintCmd.Val(), uintCmd.Err() |
| 8516 | } |
| 8517 | case CmdTypeBool: |
| 8518 | if boolCmd, ok := cmd.(interface { |
| 8519 | Val() bool |
| 8520 | Err() error |
| 8521 | }); ok { |
| 8522 | return boolCmd.Val(), boolCmd.Err() |
| 8523 | } |
| 8524 | case CmdTypeFloat: |
| 8525 | if floatCmd, ok := cmd.(interface { |
| 8526 | Val() float64 |
| 8527 | Err() error |
| 8528 | }); ok { |
| 8529 | return floatCmd.Val(), floatCmd.Err() |
| 8530 | } |
| 8531 | case CmdTypeStatus: |
| 8532 | if statusCmd, ok := cmd.(interface { |
| 8533 | Val() string |
| 8534 | Err() error |
| 8535 | }); ok { |
| 8536 | return statusCmd.Val(), statusCmd.Err() |
| 8537 | } |
| 8538 | case CmdTypeDuration: |
| 8539 | if durationCmd, ok := cmd.(interface { |
no test coverage detected