MCPcopy
hub / github.com/ph4ntonn/Stowaway / expectParams

Method expectParams

admin/cli/interactive_win.go:1096–1168  ·  view source on GitHub ↗
(params []string, numbers interface{}, mode int, needToBeInt interface{})

Source from the content-addressed store, hash-verified

1094}
1095
1096func (console *Console) expectParams(params []string, numbers interface{}, mode int, needToBeInt interface{}) bool {
1097 switch nums := numbers.(type) {
1098 case int:
1099 if len(params) != nums {
1100 printer.Fail("\r\n[*] Format error!\r\n")
1101 if mode == MAIN {
1102 ShowMainHelp()
1103 } else {
1104 ShowNodeHelp()
1105 }
1106 console.ready <- true
1107 return true
1108 }
1109 case []int:
1110 var flag bool
1111 for _, num := range nums {
1112 if len(params) == num {
1113 flag = true
1114 }
1115 }
1116
1117 if !flag {
1118 printer.Fail("\r\n[*] Format error!\r\n")
1119 if mode == MAIN {
1120 ShowMainHelp()
1121 } else {
1122 ShowNodeHelp()
1123 }
1124 console.ready <- true
1125 return true
1126 }
1127 }
1128
1129 switch seqs := needToBeInt.(type) {
1130 case int:
1131 if needToBeInt != 0 {
1132 _, err := utils.Str2Int(params[seqs])
1133 if err != nil {
1134 printer.Fail("\r\n[*] Format error!\r\n")
1135 if mode == MAIN {
1136 ShowMainHelp()
1137 } else {
1138 ShowNodeHelp()
1139 }
1140 console.ready <- true
1141 return true
1142 }
1143 }
1144 case []int:
1145 var err error
1146 for _, seq := range seqs {
1147 if seq != 0 {
1148 _, err = utils.Str2Int(params[seq])
1149 if err != nil {
1150 break
1151 }
1152 }
1153 }

Callers 2

Calls 3

Str2IntFunction · 0.92
ShowMainHelpFunction · 0.85
ShowNodeHelpFunction · 0.85

Tested by

no test coverage detected