|
|
|
@ -1130,6 +1130,155 @@
|
|
|
|
|
<span id="1088">1088</span>
|
|
|
|
|
<span id="1089">1089</span>
|
|
|
|
|
<span id="1090">1090</span>
|
|
|
|
|
<span id="1091">1091</span>
|
|
|
|
|
<span id="1092">1092</span>
|
|
|
|
|
<span id="1093">1093</span>
|
|
|
|
|
<span id="1094">1094</span>
|
|
|
|
|
<span id="1095">1095</span>
|
|
|
|
|
<span id="1096">1096</span>
|
|
|
|
|
<span id="1097">1097</span>
|
|
|
|
|
<span id="1098">1098</span>
|
|
|
|
|
<span id="1099">1099</span>
|
|
|
|
|
<span id="1100">1100</span>
|
|
|
|
|
<span id="1101">1101</span>
|
|
|
|
|
<span id="1102">1102</span>
|
|
|
|
|
<span id="1103">1103</span>
|
|
|
|
|
<span id="1104">1104</span>
|
|
|
|
|
<span id="1105">1105</span>
|
|
|
|
|
<span id="1106">1106</span>
|
|
|
|
|
<span id="1107">1107</span>
|
|
|
|
|
<span id="1108">1108</span>
|
|
|
|
|
<span id="1109">1109</span>
|
|
|
|
|
<span id="1110">1110</span>
|
|
|
|
|
<span id="1111">1111</span>
|
|
|
|
|
<span id="1112">1112</span>
|
|
|
|
|
<span id="1113">1113</span>
|
|
|
|
|
<span id="1114">1114</span>
|
|
|
|
|
<span id="1115">1115</span>
|
|
|
|
|
<span id="1116">1116</span>
|
|
|
|
|
<span id="1117">1117</span>
|
|
|
|
|
<span id="1118">1118</span>
|
|
|
|
|
<span id="1119">1119</span>
|
|
|
|
|
<span id="1120">1120</span>
|
|
|
|
|
<span id="1121">1121</span>
|
|
|
|
|
<span id="1122">1122</span>
|
|
|
|
|
<span id="1123">1123</span>
|
|
|
|
|
<span id="1124">1124</span>
|
|
|
|
|
<span id="1125">1125</span>
|
|
|
|
|
<span id="1126">1126</span>
|
|
|
|
|
<span id="1127">1127</span>
|
|
|
|
|
<span id="1128">1128</span>
|
|
|
|
|
<span id="1129">1129</span>
|
|
|
|
|
<span id="1130">1130</span>
|
|
|
|
|
<span id="1131">1131</span>
|
|
|
|
|
<span id="1132">1132</span>
|
|
|
|
|
<span id="1133">1133</span>
|
|
|
|
|
<span id="1134">1134</span>
|
|
|
|
|
<span id="1135">1135</span>
|
|
|
|
|
<span id="1136">1136</span>
|
|
|
|
|
<span id="1137">1137</span>
|
|
|
|
|
<span id="1138">1138</span>
|
|
|
|
|
<span id="1139">1139</span>
|
|
|
|
|
<span id="1140">1140</span>
|
|
|
|
|
<span id="1141">1141</span>
|
|
|
|
|
<span id="1142">1142</span>
|
|
|
|
|
<span id="1143">1143</span>
|
|
|
|
|
<span id="1144">1144</span>
|
|
|
|
|
<span id="1145">1145</span>
|
|
|
|
|
<span id="1146">1146</span>
|
|
|
|
|
<span id="1147">1147</span>
|
|
|
|
|
<span id="1148">1148</span>
|
|
|
|
|
<span id="1149">1149</span>
|
|
|
|
|
<span id="1150">1150</span>
|
|
|
|
|
<span id="1151">1151</span>
|
|
|
|
|
<span id="1152">1152</span>
|
|
|
|
|
<span id="1153">1153</span>
|
|
|
|
|
<span id="1154">1154</span>
|
|
|
|
|
<span id="1155">1155</span>
|
|
|
|
|
<span id="1156">1156</span>
|
|
|
|
|
<span id="1157">1157</span>
|
|
|
|
|
<span id="1158">1158</span>
|
|
|
|
|
<span id="1159">1159</span>
|
|
|
|
|
<span id="1160">1160</span>
|
|
|
|
|
<span id="1161">1161</span>
|
|
|
|
|
<span id="1162">1162</span>
|
|
|
|
|
<span id="1163">1163</span>
|
|
|
|
|
<span id="1164">1164</span>
|
|
|
|
|
<span id="1165">1165</span>
|
|
|
|
|
<span id="1166">1166</span>
|
|
|
|
|
<span id="1167">1167</span>
|
|
|
|
|
<span id="1168">1168</span>
|
|
|
|
|
<span id="1169">1169</span>
|
|
|
|
|
<span id="1170">1170</span>
|
|
|
|
|
<span id="1171">1171</span>
|
|
|
|
|
<span id="1172">1172</span>
|
|
|
|
|
<span id="1173">1173</span>
|
|
|
|
|
<span id="1174">1174</span>
|
|
|
|
|
<span id="1175">1175</span>
|
|
|
|
|
<span id="1176">1176</span>
|
|
|
|
|
<span id="1177">1177</span>
|
|
|
|
|
<span id="1178">1178</span>
|
|
|
|
|
<span id="1179">1179</span>
|
|
|
|
|
<span id="1180">1180</span>
|
|
|
|
|
<span id="1181">1181</span>
|
|
|
|
|
<span id="1182">1182</span>
|
|
|
|
|
<span id="1183">1183</span>
|
|
|
|
|
<span id="1184">1184</span>
|
|
|
|
|
<span id="1185">1185</span>
|
|
|
|
|
<span id="1186">1186</span>
|
|
|
|
|
<span id="1187">1187</span>
|
|
|
|
|
<span id="1188">1188</span>
|
|
|
|
|
<span id="1189">1189</span>
|
|
|
|
|
<span id="1190">1190</span>
|
|
|
|
|
<span id="1191">1191</span>
|
|
|
|
|
<span id="1192">1192</span>
|
|
|
|
|
<span id="1193">1193</span>
|
|
|
|
|
<span id="1194">1194</span>
|
|
|
|
|
<span id="1195">1195</span>
|
|
|
|
|
<span id="1196">1196</span>
|
|
|
|
|
<span id="1197">1197</span>
|
|
|
|
|
<span id="1198">1198</span>
|
|
|
|
|
<span id="1199">1199</span>
|
|
|
|
|
<span id="1200">1200</span>
|
|
|
|
|
<span id="1201">1201</span>
|
|
|
|
|
<span id="1202">1202</span>
|
|
|
|
|
<span id="1203">1203</span>
|
|
|
|
|
<span id="1204">1204</span>
|
|
|
|
|
<span id="1205">1205</span>
|
|
|
|
|
<span id="1206">1206</span>
|
|
|
|
|
<span id="1207">1207</span>
|
|
|
|
|
<span id="1208">1208</span>
|
|
|
|
|
<span id="1209">1209</span>
|
|
|
|
|
<span id="1210">1210</span>
|
|
|
|
|
<span id="1211">1211</span>
|
|
|
|
|
<span id="1212">1212</span>
|
|
|
|
|
<span id="1213">1213</span>
|
|
|
|
|
<span id="1214">1214</span>
|
|
|
|
|
<span id="1215">1215</span>
|
|
|
|
|
<span id="1216">1216</span>
|
|
|
|
|
<span id="1217">1217</span>
|
|
|
|
|
<span id="1218">1218</span>
|
|
|
|
|
<span id="1219">1219</span>
|
|
|
|
|
<span id="1220">1220</span>
|
|
|
|
|
<span id="1221">1221</span>
|
|
|
|
|
<span id="1222">1222</span>
|
|
|
|
|
<span id="1223">1223</span>
|
|
|
|
|
<span id="1224">1224</span>
|
|
|
|
|
<span id="1225">1225</span>
|
|
|
|
|
<span id="1226">1226</span>
|
|
|
|
|
<span id="1227">1227</span>
|
|
|
|
|
<span id="1228">1228</span>
|
|
|
|
|
<span id="1229">1229</span>
|
|
|
|
|
<span id="1230">1230</span>
|
|
|
|
|
<span id="1231">1231</span>
|
|
|
|
|
<span id="1232">1232</span>
|
|
|
|
|
<span id="1233">1233</span>
|
|
|
|
|
<span id="1234">1234</span>
|
|
|
|
|
<span id="1235">1235</span>
|
|
|
|
|
<span id="1236">1236</span>
|
|
|
|
|
<span id="1237">1237</span>
|
|
|
|
|
<span id="1238">1238</span>
|
|
|
|
|
<span id="1239">1239</span>
|
|
|
|
|
</pre><pre class='rust '>
|
|
|
|
|
<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>libc</span>;
|
|
|
|
|
|
|
|
|
@ -1188,6 +1337,7 @@
|
|
|
|
|
<span class='ident'>needs_short_version</span>: <span class='ident'>bool</span>,
|
|
|
|
|
<span class='ident'>needs_subcmd_help</span>: <span class='ident'>bool</span>,
|
|
|
|
|
<span class='ident'>required</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'ar</span> <span class='ident'>str</span><span class='op'>></span>,
|
|
|
|
|
<span class='ident'>matched_reqs</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'ar</span> <span class='ident'>str</span><span class='op'>></span>,
|
|
|
|
|
<span class='ident'>arg_list</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'ar</span> <span class='ident'>str</span><span class='op'>></span>,
|
|
|
|
|
<span class='ident'>short_list</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='ident'>char</span><span class='op'>></span>,
|
|
|
|
|
<span class='ident'>long_list</span>: <span class='ident'>HashSet</span><span class='op'><</span><span class='kw-2'>&</span><span class='lifetime'>'ar</span> <span class='ident'>str</span><span class='op'>></span>,
|
|
|
|
@ -1224,6 +1374,7 @@
|
|
|
|
|
<span class='ident'>needs_subcmd_help</span>: <span class='boolval'>true</span>,
|
|
|
|
|
<span class='ident'>needs_short_version</span>: <span class='boolval'>true</span>,
|
|
|
|
|
<span class='ident'>required</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
|
|
|
|
<span class='ident'>matched_reqs</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
|
|
|
|
<span class='ident'>arg_list</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
|
|
|
|
<span class='ident'>short_list</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
|
|
|
|
<span class='ident'>long_list</span>: <span class='ident'>HashSet</span>::<span class='ident'>new</span>(),
|
|
|
|
@ -1349,6 +1500,7 @@
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>a</span>.<span class='ident'>takes_value</span> {
|
|
|
|
|
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" has conflicting requirements, both index() and takes_value(true) were supplied"</span>, <span class='ident'>a</span>.<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='comment'>// Create the Positional Arguemnt Builder with each HashSet = None to only allocate those that require it</span>
|
|
|
|
|
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>pb</span> <span class='op'>=</span> <span class='ident'>PosBuilder</span> {
|
|
|
|
|
<span class='ident'>name</span>: <span class='ident'>a</span>.<span class='ident'>name</span>,
|
|
|
|
@ -1371,7 +1523,8 @@
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>r</span>) <span class='op'>=</span> <span class='ident'>a</span>.<span class='ident'>requires</span> {
|
|
|
|
|
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>rhs</span> <span class='op'>=</span> <span class='ident'>HashSet</span>::<span class='ident'>new</span>();
|
|
|
|
|
<span class='comment'>// without derefing n = &&str</span>
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>r</span> { <span class='ident'>rhs</span>.<span class='ident'>insert</span>(<span class='op'>*</span><span class='ident'>n</span>); }
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>r</span> {
|
|
|
|
|
<span class='ident'>rhs</span>.<span class='ident'>insert</span>(<span class='op'>*</span><span class='ident'>n</span>); }
|
|
|
|
|
<span class='ident'>pb</span>.<span class='ident'>requires</span> <span class='op'>=</span> <span class='prelude-val'>Some</span>(<span class='ident'>rhs</span>);
|
|
|
|
|
}
|
|
|
|
|
<span class='comment'>// Check if there is anything in the possible values and add those as well</span>
|
|
|
|
@ -1439,7 +1592,10 @@
|
|
|
|
|
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" must have either a short() and/or long() supplied since no index() or takes_value() were found"</span>, <span class='ident'>a</span>.<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>a</span>.<span class='ident'>required</span> {
|
|
|
|
|
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" cannot be required(true) because it has no index() or takes_value(true)"</span>, <span class='ident'>a</span>.<span class='ident'>name</span>)
|
|
|
|
|
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" cannot be required(true) because it has no index() or takes_value(true)"</span>, <span class='ident'>a</span>.<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>a</span>.<span class='ident'>possible_vals</span>.<span class='ident'>is_some</span>() {
|
|
|
|
|
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>"Argument \"{}\" cannot have a specific value set because it doesn't have takes_value(true) set"</span>, <span class='ident'>a</span>.<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
<span class='comment'>// No need to check for index() or takes_value() as that is handled above</span>
|
|
|
|
|
|
|
|
|
@ -1539,36 +1695,55 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>print_usage</span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>more_info</span>: <span class='ident'>bool</span>) {
|
|
|
|
|
<span class='kw'>let</span> <span class='ident'>tab</span> <span class='op'>=</span> <span class='string'>" "</span>;
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"USAGE:"</span>);
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>u</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>usage_str</span> {
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"\t{}"</span>,<span class='ident'>u</span>);
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}{}"</span>,<span class='ident'>tab</span>,<span class='ident'>u</span>);
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='kw'>let</span> <span class='ident'>flags</span> <span class='op'>=</span> <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>is_empty</span>();
|
|
|
|
|
<span class='kw'>let</span> <span class='ident'>pos</span> <span class='op'>=</span> <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>is_empty</span>();
|
|
|
|
|
<span class='kw'>let</span> <span class='ident'>opts</span> <span class='op'>=</span> <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>is_empty</span>();
|
|
|
|
|
<span class='kw'>let</span> <span class='ident'>subcmds</span> <span class='op'>=</span> <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>subcommands</span>.<span class='ident'>is_empty</span>();
|
|
|
|
|
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>num_req_pos</span> <span class='op'>=</span> <span class='number'>0</span>;
|
|
|
|
|
<span class='kw'>let</span> <span class='ident'>req_pos</span> <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>values</span>().<span class='ident'>filter_map</span>(<span class='op'>|</span><span class='kw-2'>ref</span> <span class='ident'>x</span><span class='op'>|</span> <span class='kw'>if</span> <span class='ident'>x</span>.<span class='ident'>required</span> <span class='op'>||</span> <span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>contains</span>(<span class='ident'>x</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>matched_pos_reqs</span> <span class='op'>=</span> <span class='ident'>HashSet</span>::<span class='ident'>new</span>();
|
|
|
|
|
<span class='comment'>// If it's required we also need to ensure all previous positionals are required too</span>
|
|
|
|
|
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>found</span> <span class='op'>=</span> <span class='boolval'>false</span>;
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>p</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>values</span>().<span class='ident'>rev</span>() {
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>found</span> {
|
|
|
|
|
<span class='ident'>matched_pos_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>p</span>.<span class='ident'>name</span>);
|
|
|
|
|
<span class='kw'>continue</span>;
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>contains</span>(<span class='ident'>p</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='ident'>matched_pos_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>p</span>.<span class='ident'>name</span>);
|
|
|
|
|
<span class='ident'>found</span> <span class='op'>=</span> <span class='boolval'>true</span>;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='kw'>let</span> <span class='ident'>req_pos</span> <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>values</span>().<span class='ident'>filter_map</span>(<span class='op'>|</span><span class='kw-2'>ref</span> <span class='ident'>x</span><span class='op'>|</span> <span class='kw'>if</span> <span class='ident'>x</span>.<span class='ident'>required</span> <span class='op'>||</span> <span class='ident'>matched_pos_reqs</span>.<span class='ident'>contains</span>(<span class='ident'>x</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='ident'>num_req_pos</span> <span class='op'>+=</span> <span class='number'>1</span>;
|
|
|
|
|
<span class='prelude-val'>Some</span>(<span class='ident'>x</span>.<span class='ident'>name</span>)
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>x</span>.<span class='ident'>multiple</span> {
|
|
|
|
|
<span class='prelude-val'>Some</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"<{}>..."</span>, <span class='ident'>x</span>.<span class='ident'>name</span>))
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='prelude-val'>Some</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"<{}>"</span>, <span class='ident'>x</span>.<span class='ident'>name</span>))
|
|
|
|
|
}
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='prelude-val'>None</span>
|
|
|
|
|
})
|
|
|
|
|
.<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='kw-2'>ref</span> <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"<{}> "</span>, <span class='ident'>name</span>)[..]);
|
|
|
|
|
.<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='kw-2'>ref</span> <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{} "</span>, <span class='ident'>name</span>)[..]);
|
|
|
|
|
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>num_req_opts</span> <span class='op'>=</span> <span class='number'>0</span>;
|
|
|
|
|
<span class='kw'>let</span> <span class='ident'>req_opts</span> <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>values</span>().<span class='ident'>filter_map</span>(<span class='op'>|</span><span class='ident'>x</span><span class='op'>|</span> <span class='kw'>if</span> <span class='ident'>x</span>.<span class='ident'>required</span> <span class='op'>||</span> <span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>contains</span>(<span class='ident'>x</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='kw'>let</span> <span class='ident'>req_opts</span> <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>values</span>().<span class='ident'>filter_map</span>(<span class='op'>|</span><span class='ident'>x</span><span class='op'>|</span> <span class='kw'>if</span> <span class='ident'>x</span>.<span class='ident'>required</span> <span class='op'>||</span> <span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>contains</span>(<span class='ident'>x</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='ident'>num_req_opts</span> <span class='op'>+=</span> <span class='number'>1</span>;
|
|
|
|
|
<span class='prelude-val'>Some</span>(<span class='ident'>x</span>)
|
|
|
|
|
}<span class='kw'>else</span> {
|
|
|
|
|
<span class='prelude-val'>None</span>
|
|
|
|
|
})
|
|
|
|
|
.<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='kw-2'>ref</span> <span class='ident'>o</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}{} "</span>,<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>s</span>) <span class='op'>=</span> <span class='ident'>o</span>.<span class='ident'>short</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{} "</span>, <span class='ident'>s</span>)
|
|
|
|
|
.<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='kw-2'>ref</span> <span class='ident'>o</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}{} "</span>,<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='ident'>o</span>.<span class='ident'>long</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}="</span>, <span class='ident'>l</span>)
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}="</span>,<span class='ident'>o</span>.<span class='ident'>long</span>.<span class='ident'>unwrap</span>())
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{} "</span>,<span class='ident'>o</span>.<span class='ident'>short</span>.<span class='ident'>unwrap</span>())
|
|
|
|
|
},<span class='ident'>o</span>.<span class='ident'>name</span>));
|
|
|
|
|
|
|
|
|
|
<span class='macro'>print</span><span class='macro'>!</span>(<span class='string'>"\t{} {} {} {} {}"</span>, <span class='self'>self</span>.<span class='ident'>bin_name</span>.<span class='ident'>clone</span>().<span class='ident'>unwrap_or</span>(<span class='self'>self</span>.<span class='ident'>name</span>.<span class='ident'>clone</span>()),
|
|
|
|
|
<span class='macro'>print</span><span class='macro'>!</span>(<span class='string'>"{}{} {} {} {} {}"</span>,<span class='ident'>tab</span>, <span class='self'>self</span>.<span class='ident'>bin_name</span>.<span class='ident'>clone</span>().<span class='ident'>unwrap_or</span>(<span class='self'>self</span>.<span class='ident'>name</span>.<span class='ident'>clone</span>()),
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>flags</span> {<span class='string'>"[FLAGS]"</span>} <span class='kw'>else</span> {<span class='string'>""</span>},
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>opts</span> {
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>num_req_opts</span> <span class='op'>!=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>len</span>() <span class='op'>&&</span> <span class='op'>!</span><span class='ident'>req_opts</span>.<span class='ident'>is_empty</span>() {
|
|
|
|
@ -1603,6 +1778,32 @@
|
|
|
|
|
<span class='kw'>let</span> <span class='ident'>opts</span> <span class='op'>=</span> <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>is_empty</span>();
|
|
|
|
|
<span class='kw'>let</span> <span class='ident'>subcmds</span> <span class='op'>=</span> <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>subcommands</span>.<span class='ident'>is_empty</span>();
|
|
|
|
|
|
|
|
|
|
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>longest_flag</span> <span class='op'>=</span> <span class='number'>0</span>;
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>fl</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>flags</span>
|
|
|
|
|
.<span class='ident'>values</span>()
|
|
|
|
|
.<span class='ident'>filter_map</span>(<span class='op'>|</span><span class='kw-2'>ref</span> <span class='ident'>f</span><span class='op'>|</span> <span class='ident'>f</span>.<span class='ident'>long</span>)
|
|
|
|
|
.<span class='ident'>map</span>(<span class='op'>|</span><span class='kw-2'>ref</span> <span class='ident'>l</span><span class='op'>|</span> <span class='ident'>l</span>.<span class='ident'>len</span>() <span class='op'>+</span> <span class='number'>2</span>) {
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>fl</span> <span class='op'>></span> <span class='ident'>longest_flag</span> { <span class='ident'>longest_flag</span> <span class='op'>=</span> <span class='ident'>fl</span>; }
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>longest_opt</span><span class='op'>=</span> <span class='number'>0</span>;
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>ol</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>opts</span>
|
|
|
|
|
.<span class='ident'>values</span>()
|
|
|
|
|
.<span class='ident'>filter_map</span>(<span class='op'>|</span><span class='kw-2'>ref</span> <span class='ident'>f</span><span class='op'>|</span> <span class='kw'>if</span> <span class='ident'>f</span>.<span class='ident'>long</span>.<span class='ident'>is_some</span>() {<span class='kw'>let</span> <span class='ident'>mult</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='ident'>f</span>.<span class='ident'>multiple</span> { <span class='number'>3</span> } <span class='kw'>else</span> { <span class='number'>0</span> }; <span class='prelude-val'>Some</span>(<span class='ident'>f</span>.<span class='ident'>long</span>.<span class='ident'>unwrap</span>().<span class='ident'>len</span>() <span class='op'>+</span> <span class='ident'>mult</span> <span class='op'>+</span> <span class='ident'>f</span>.<span class='ident'>name</span>.<span class='ident'>len</span>() <span class='op'>+</span> <span class='number'>3</span>)}<span class='kw'>else</span> {<span class='prelude-val'>None</span>}) {
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>ol</span> <span class='op'>></span> <span class='ident'>longest_opt</span> {<span class='ident'>longest_opt</span> <span class='op'>=</span> <span class='ident'>ol</span>;}
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>longest_pos</span> <span class='op'>=</span> <span class='number'>0</span>;
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>pl</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>
|
|
|
|
|
.<span class='ident'>values</span>()
|
|
|
|
|
.<span class='ident'>map</span>(<span class='op'>|</span><span class='kw-2'>ref</span> <span class='ident'>f</span><span class='op'>|</span> <span class='kw'>if</span> <span class='ident'>f</span>.<span class='ident'>multiple</span> { <span class='ident'>f</span>.<span class='ident'>name</span>.<span class='ident'>len</span>() <span class='op'>+</span> <span class='number'>3</span> } <span class='kw'>else</span> { <span class='ident'>f</span>.<span class='ident'>name</span>.<span class='ident'>len</span>() } ) {
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>pl</span> <span class='op'>></span> <span class='ident'>longest_pos</span> {<span class='ident'>longest_pos</span> <span class='op'>=</span> <span class='ident'>pl</span>;}
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>longest_sc</span> <span class='op'>=</span> <span class='number'>0</span>;
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>scl</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>subcommands</span>
|
|
|
|
|
.<span class='ident'>values</span>()
|
|
|
|
|
.<span class='ident'>map</span>(<span class='op'>|</span><span class='kw-2'>ref</span> <span class='ident'>f</span><span class='op'>|</span> <span class='ident'>f</span>.<span class='ident'>name</span>.<span class='ident'>len</span>() ) {
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>scl</span> <span class='op'>></span> <span class='ident'>longest_sc</span> {<span class='ident'>longest_sc</span> <span class='op'>=</span> <span class='ident'>scl</span>;}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>author</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>author</span> {
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}"</span>, <span class='ident'>author</span>);
|
|
|
|
|
}
|
|
|
|
@ -1614,34 +1815,59 @@
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>flags</span> <span class='op'>||</span> <span class='ident'>opts</span> <span class='op'>||</span> <span class='ident'>pos</span> <span class='op'>||</span> <span class='ident'>subcmds</span> {
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='kw'>let</span> <span class='ident'>tab</span> <span class='op'>=</span> <span class='string'>" "</span>;
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>flags</span> {
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"FLAGS:"</span>);
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>v</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>values</span>() {
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"\t{}{}\t{}"</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>s</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>short</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='string'>" "</span>.<span class='ident'>to_owned</span>()},
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>long</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>",--{}"</span>,<span class='ident'>l</span>)}<span class='kw'>else</span> {<span class='string'>" \t"</span>.<span class='ident'>to_owned</span>()},
|
|
|
|
|
<span class='ident'>v</span>.<span class='ident'>help</span>.<span class='ident'>unwrap_or</span>(<span class='string'>" "</span>) );
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}{}{}{}"</span>,<span class='ident'>tab</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>s</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>short</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='ident'>tab</span>.<span class='ident'>to_owned</span>()},
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>long</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{}--{}{}"</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>short</span>.<span class='ident'>is_some</span>() { <span class='string'>", "</span> } <span class='kw'>else</span> {<span class='string'>""</span>},
|
|
|
|
|
<span class='ident'>l</span>,
|
|
|
|
|
<span class='comment'>// +2 accounts for the ', ' +4 for tab = 6</span>
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>get_spaces</span>((<span class='ident'>longest_flag</span> <span class='op'>+</span> <span class='number'>4</span>) <span class='op'>-</span> (<span class='ident'>v</span>.<span class='ident'>long</span>.<span class='ident'>unwrap</span>().<span class='ident'>len</span>() <span class='op'>+</span> <span class='number'>2</span>)))
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='comment'>// 6 is tab (4) + -- (2)</span>
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>get_spaces</span>(<span class='ident'>longest_flag</span><span class='op'>+</span><span class='number'>6</span>).<span class='ident'>to_owned</span>()
|
|
|
|
|
},
|
|
|
|
|
<span class='ident'>v</span>.<span class='ident'>help</span>.<span class='ident'>unwrap_or</span>(<span class='ident'>tab</span>) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>opts</span> {
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"OPTIONS:"</span>);
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>v</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>values</span>() {
|
|
|
|
|
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>needs_tab</span> <span class='op'>=</span> <span class='boolval'>false</span>;
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"\t{}{}{}\t{}"</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>s</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>short</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{} "</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='string'>" "</span>.<span class='ident'>to_owned</span>()},
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>long</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>",--{}="</span>,<span class='ident'>l</span>)}<span class='kw'>else</span> {<span class='ident'>needs_tab</span> <span class='op'>=</span> <span class='boolval'>true</span>; <span class='string'>" "</span>.<span class='ident'>to_owned</span>()},
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{}"</span>, <span class='ident'>v</span>.<span class='ident'>name</span>),
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{}{}{}"</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>needs_tab</span> { <span class='string'>"\t"</span> } <span class='kw'>else</span> { <span class='string'>""</span> },
|
|
|
|
|
<span class='ident'>h</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>pv</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>possible_vals</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" [values:{}]"</span>, <span class='ident'>pv</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{}"</span>,<span class='ident'>name</span>)[..] ))
|
|
|
|
|
}<span class='kw'>else</span>{<span class='string'>""</span>.<span class='ident'>to_owned</span>()})
|
|
|
|
|
<span class='comment'>// if it supports multiple we add '...' i.e. 3 to the name length</span>
|
|
|
|
|
<span class='kw'>let</span> <span class='ident'>mult</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>multiple</span> { <span class='number'>3</span> } <span class='kw'>else</span> { <span class='number'>0</span> };
|
|
|
|
|
<span class='comment'>// let long_len = if v.long.is_some() { v.long.unwrap().len() + 3}else{0};</span>
|
|
|
|
|
<span class='comment'>// let mut needs_tab = false;</span>
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}{}{}{}{}{}"</span>,<span class='ident'>tab</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>s</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>short</span>{<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>,<span class='ident'>s</span>)}<span class='kw'>else</span>{<span class='ident'>tab</span>.<span class='ident'>to_owned</span>()},
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>long</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{}--{}="</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>short</span>.<span class='ident'>is_some</span>() {<span class='string'>", "</span>} <span class='kw'>else</span> {<span class='string'>""</span>},<span class='ident'>l</span>)
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='string'>" "</span>.<span class='ident'>to_owned</span>()
|
|
|
|
|
<span class='string'>" "</span>.<span class='ident'>to_owned</span>()
|
|
|
|
|
},
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{}{}"</span>, <span class='ident'>v</span>.<span class='ident'>name</span>, <span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>multiple</span>{<span class='string'>"..."</span>} <span class='kw'>else</span> {<span class='string'>""</span>}),
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>long</span>.<span class='ident'>is_some</span>() {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>get_spaces</span>((<span class='ident'>longest_opt</span> <span class='op'>+</span> <span class='number'>4</span>) <span class='op'>-</span> (<span class='ident'>v</span>.<span class='ident'>long</span>.<span class='ident'>unwrap</span>().<span class='ident'>len</span>() <span class='op'>+</span> <span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>len</span>() <span class='op'>+</span> <span class='number'>2</span> <span class='op'>+</span> <span class='ident'>mult</span>))
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='comment'>// 7 is '--=' (3) + tab (4)</span>
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>get_spaces</span>((<span class='ident'>longest_opt</span> <span class='op'>+</span> <span class='number'>6</span>) <span class='op'>-</span> (<span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>len</span>() <span class='op'>+</span> <span class='ident'>mult</span>))
|
|
|
|
|
},
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{}{}"</span>, <span class='ident'>h</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>pv</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>possible_vals</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" [values:{}]"</span>, <span class='ident'>pv</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" {}"</span>,<span class='ident'>name</span>)[..] ))
|
|
|
|
|
}<span class='kw'>else</span>{
|
|
|
|
|
<span class='string'>""</span>.<span class='ident'>to_owned</span>()
|
|
|
|
|
})
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='ident'>tab</span>.<span class='ident'>to_owned</span>()
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1649,30 +1875,66 @@
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"POSITIONAL ARGUMENTS:"</span>);
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>v</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>values</span>() {
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"\t{}\t\t{}"</span>, <span class='ident'>v</span>.<span class='ident'>name</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{}{}"</span>,
|
|
|
|
|
<span class='ident'>h</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>pv</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>possible_vals</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" [values:{}]"</span>, <span class='ident'>pv</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" {}"</span>,<span class='ident'>name</span>)[..] ))
|
|
|
|
|
}<span class='kw'>else</span>{<span class='string'>""</span>.<span class='ident'>to_owned</span>()})
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='string'>" "</span>.<span class='ident'>to_owned</span>()
|
|
|
|
|
} );
|
|
|
|
|
<span class='kw'>let</span> <span class='ident'>mult</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>multiple</span> { <span class='number'>3</span> } <span class='kw'>else</span> { <span class='number'>0</span> };
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}{}{}{}"</span>,<span class='ident'>tab</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>v</span>.<span class='ident'>multiple</span> {<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{}..."</span>,<span class='ident'>v</span>.<span class='ident'>name</span>)} <span class='kw'>else</span> {<span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>to_owned</span>()},
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>get_spaces</span>((<span class='ident'>longest_pos</span> <span class='op'>+</span> <span class='number'>4</span>) <span class='op'>-</span> (<span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>len</span>() <span class='op'>+</span> <span class='ident'>mult</span>)),
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>h</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>help</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"{}{}"</span>,
|
|
|
|
|
<span class='ident'>h</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>pv</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>possible_vals</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" [values:{}]"</span>, <span class='ident'>pv</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" {}"</span>,<span class='ident'>name</span>)[..] ))
|
|
|
|
|
}<span class='kw'>else</span>{<span class='string'>""</span>.<span class='ident'>to_owned</span>()})
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='ident'>tab</span>.<span class='ident'>to_owned</span>()
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>subcmds</span> {
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>""</span>);
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"SUBCOMMANDS:"</span>);
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>sc</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>subcommands</span>.<span class='ident'>values</span>() {
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"\t{}\t\t{}"</span>, <span class='ident'>sc</span>.<span class='ident'>name</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>a</span>) <span class='op'>=</span> <span class='ident'>sc</span>.<span class='ident'>about</span> {<span class='ident'>a</span>} <span class='kw'>else</span> {<span class='string'>" "</span>} );
|
|
|
|
|
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}{}{}{}"</span>,<span class='ident'>tab</span>,
|
|
|
|
|
<span class='ident'>sc</span>.<span class='ident'>name</span>,
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>get_spaces</span>((<span class='ident'>longest_sc</span> <span class='op'>+</span> <span class='number'>4</span>) <span class='op'>-</span> (<span class='ident'>sc</span>.<span class='ident'>name</span>.<span class='ident'>len</span>())),
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>a</span>) <span class='op'>=</span> <span class='ident'>sc</span>.<span class='ident'>about</span> {<span class='ident'>a</span>} <span class='kw'>else</span> {<span class='ident'>tab</span>} );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>exit</span>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='attribute'>#[<span class='ident'>inline</span>(<span class='ident'>always</span>)]</span>
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>get_spaces</span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>num</span>: <span class='ident'>usize</span>) <span class='op'>-></span> <span class='kw-2'>&</span><span class='lifetime'>'static</span> <span class='ident'>str</span> {
|
|
|
|
|
<span class='kw'>match</span> <span class='ident'>num</span> {
|
|
|
|
|
<span class='number'>0</span> <span class='op'>=></span> <span class='string'>""</span>,
|
|
|
|
|
<span class='number'>1</span> <span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>2</span> <span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>3</span> <span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>4</span> <span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>5</span> <span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>6</span> <span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>7</span> <span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>8</span> <span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>9</span> <span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>10</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>11</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>12</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>13</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>14</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>15</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>16</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>17</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>18</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>19</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>20</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>21</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>22</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>23</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>24</span><span class='op'>=></span> <span class='string'>" "</span>,
|
|
|
|
|
<span class='number'>25</span><span class='op'>|</span>_<span class='op'>=></span> <span class='string'>" "</span>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>print_version</span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>quit</span>: <span class='ident'>bool</span>) {
|
|
|
|
|
<span class='comment'>// Print the binary name if existing, but replace all spaces with hyphens in case we're</span>
|
|
|
|
|
<span class='comment'>// dealing with subcommands i.e. git mv is translated to git-mv</span>
|
|
|
|
@ -1692,7 +1954,7 @@
|
|
|
|
|
|
|
|
|
|
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>get_matches</span>(<span class='kw-2'>mut</span> <span class='self'>self</span>) <span class='op'>-></span> <span class='ident'>ArgMatches</span><span class='op'><</span><span class='lifetime'>'ar</span><span class='op'>></span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>verify_positionals</span>();
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>sc</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>subcommands</span>.<span class='ident'>values</span>() {
|
|
|
|
|
<span class='kw'>for</span> (_,<span class='ident'>sc</span>) <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>subcommands</span>.<span class='ident'>iter_mut</span>() {
|
|
|
|
|
<span class='ident'>sc</span>.<span class='ident'>verify_positionals</span>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1713,7 +1975,7 @@
|
|
|
|
|
<span class='ident'>matches</span>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>verify_positionals</span>(<span class='kw-2'>&</span><span class='self'>self</span>) {
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>verify_positionals</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>) {
|
|
|
|
|
<span class='comment'>// Because you must wait until all arguments have been supplied, this is the first chance</span>
|
|
|
|
|
<span class='comment'>// to make assertions on positional argument indexes</span>
|
|
|
|
|
<span class='comment'>// </span>
|
|
|
|
@ -1734,6 +1996,19 @@
|
|
|
|
|
<span class='macro'>panic</span><span class='macro'>!</span>(<span class='string'>"Found positional argument \"{}\" which accepts multiple values but it's not the last positional argument (i.e. others have a higher index)"</span>,
|
|
|
|
|
<span class='ident'>p</span>.<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='comment'>// If it's required we also need to ensure all previous positionals are required too</span>
|
|
|
|
|
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>found</span> <span class='op'>=</span> <span class='boolval'>false</span>;
|
|
|
|
|
<span class='kw'>for</span> (_, <span class='ident'>p</span>) <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>iter_mut</span>().<span class='ident'>rev</span>() {
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>found</span> {
|
|
|
|
|
<span class='ident'>p</span>.<span class='ident'>required</span> <span class='op'>=</span> <span class='boolval'>true</span>;
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>insert</span>(<span class='ident'>p</span>.<span class='ident'>name</span>);
|
|
|
|
|
<span class='kw'>continue</span>;
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>p</span>.<span class='ident'>required</span> {
|
|
|
|
|
<span class='ident'>found</span> <span class='op'>=</span> <span class='boolval'>true</span>;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>get_matches_from</span>(<span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>matches</span>: <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>ArgMatches</span><span class='op'><</span><span class='lifetime'>'ar</span><span class='op'>></span>, <span class='ident'>it</span>: <span class='kw-2'>&</span><span class='kw-2'>mut</span> <span class='ident'>IntoIter</span><span class='op'><</span><span class='ident'>String</span><span class='op'>></span>) {
|
|
|
|
@ -1759,12 +2034,13 @@
|
|
|
|
|
}<span class='kw'>else</span>{
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>, <span class='ident'>opt</span>.<span class='ident'>short</span>.<span class='ident'>unwrap</span>())
|
|
|
|
|
},
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"\n\t[valid values:{}]"</span>, <span class='ident'>p_vals</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" {}"</span>,<span class='ident'>name</span>)[..] )) ), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"\n [valid values:{}]"</span>, <span class='ident'>p_vals</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" {}"</span>,<span class='ident'>name</span>)[..] )) ), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='kw-2'>mut</span> <span class='ident'>o</span>) <span class='op'>=</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>get_mut</span>(<span class='ident'>opt</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='ident'>o</span>.<span class='ident'>values</span>.<span class='ident'>push</span>(<span class='ident'>arg</span>.<span class='ident'>clone</span>());
|
|
|
|
|
<span class='comment'>// if it's multiple the occurrences are increased when originall found</span>
|
|
|
|
|
<span class='ident'>o</span>.<span class='ident'>occurrences</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='ident'>opt</span>.<span class='ident'>multiple</span> { <span class='ident'>o</span>.<span class='ident'>occurrences</span> <span class='op'>+</span> <span class='number'>1</span> } <span class='kw'>else</span> { <span class='number'>1</span> };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1776,6 +2052,7 @@
|
|
|
|
|
<span class='ident'>needs_val_of</span> <span class='op'>=</span> <span class='prelude-val'>None</span>;
|
|
|
|
|
<span class='kw'>continue</span>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>arg_slice</span>.<span class='ident'>starts_with</span>(<span class='string'>"--"</span>) <span class='op'>&&</span> <span class='op'>!</span><span class='ident'>pos_only</span> {
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>arg_slice</span>.<span class='ident'>len</span>() <span class='op'>==</span> <span class='number'>2</span> {
|
|
|
|
|
<span class='ident'>pos_only</span> <span class='op'>=</span> <span class='boolval'>true</span>;
|
|
|
|
@ -1800,9 +2077,12 @@
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"Found positional argument {}, but {} doesn't accept any"</span>, <span class='ident'>arg</span>, <span class='self'>self</span>.<span class='ident'>name</span>),
|
|
|
|
|
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
}
|
|
|
|
|
<span class='comment'>// If we find that an argument requires a positiona, we need to update all the</span>
|
|
|
|
|
<span class='comment'>// previous positionals too. This will denote where to start</span>
|
|
|
|
|
<span class='comment'>// let mut req_pos_from_name = None;</span>
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>p</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>positionals_idx</span>.<span class='ident'>get</span>(<span class='kw-2'>&</span><span class='ident'>pos_counter</span>) {
|
|
|
|
|
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>contains</span>(<span class='ident'>p</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument \"{}\" is mutually exclusive with one or more other arguments"</span>, <span class='ident'>arg</span>),
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument \"{}\" cannot be used with one or more of the other specified arguments"</span>, <span class='ident'>arg</span>),
|
|
|
|
|
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1812,7 +2092,7 @@
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"\"{}\" isn't a valid value for {}{}"</span>,
|
|
|
|
|
<span class='ident'>arg_slice</span>,
|
|
|
|
|
<span class='ident'>p</span>.<span class='ident'>name</span>,
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"\n\t[valid values:{}]"</span>, <span class='ident'>p_vals</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" {}"</span>,<span class='ident'>name</span>)[..] )) ), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"\n [valid values:{}]"</span>, <span class='ident'>p_vals</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" {}"</span>,<span class='ident'>name</span>)[..] )) ), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1841,15 +2121,19 @@
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>bl</span>) <span class='op'>=</span> <span class='ident'>p</span>.<span class='ident'>blacklist</span> {
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>name</span> <span class='kw'>in</span> <span class='ident'>bl</span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>insert</span>(<span class='ident'>name</span>);
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>contains</span>(<span class='ident'>p</span>.<span class='ident'>name</span>) {
|
|
|
|
|
|
|
|
|
|
<span class='comment'>// No need to check for existance, returns None if not found</span>
|
|
|
|
|
<span class='comment'>// if self.required.contains(p.name) {</span>
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>p</span>.<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
<span class='comment'>// }</span>
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>reqs</span>) <span class='op'>=</span> <span class='ident'>p</span>.<span class='ident'>requires</span> {
|
|
|
|
|
<span class='comment'>// Add all required args which aren't already found in matches to the</span>
|
|
|
|
|
<span class='comment'>// final required list</span>
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) {<span class='kw'>continue</span>;}
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) {<span class='kw'>continue</span>;}
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) {<span class='kw'>continue</span>;}
|
|
|
|
@ -1870,12 +2154,14 @@
|
|
|
|
|
}
|
|
|
|
|
_ <span class='op'>=></span> {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>validate_blacklist</span>(<span class='kw-2'>&</span><span class='ident'>matches</span>);
|
|
|
|
|
|
|
|
|
|
<span class='kw'>if</span> <span class='op'>!</span><span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>is_empty</span>() {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='string'>"One or more required arguments were not supplied"</span>.<span class='ident'>to_owned</span>(),
|
|
|
|
|
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>validate_blacklist</span>(<span class='kw-2'>&</span><span class='ident'>matches</span>);
|
|
|
|
|
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>sc_name</span>) <span class='op'>=</span> <span class='ident'>subcmd_name</span> {
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='kw-2'>mut</span> <span class='ident'>sc</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>subcommands</span>.<span class='ident'>get_mut</span>(<span class='kw-2'>&</span><span class='ident'>sc_name</span>) {
|
|
|
|
@ -1950,7 +2236,7 @@
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>v</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>values</span>().<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>long</span>.<span class='ident'>is_some</span>()).<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>long</span>.<span class='ident'>unwrap</span>() <span class='op'>==</span> <span class='ident'>arg</span>).<span class='ident'>nth</span>(<span class='number'>0</span>) {
|
|
|
|
|
<span class='comment'>// Ensure this option isn't on the master mutually excludes list</span>
|
|
|
|
|
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument --{} is mutually exclusive with one or more other arguments"</span>, <span class='ident'>arg</span>),
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument --{} cannot be used with one or more of the other specified arguments"</span>, <span class='ident'>arg</span>),
|
|
|
|
|
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1968,7 +2254,7 @@
|
|
|
|
|
}<span class='kw'>else</span>{
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>, <span class='ident'>v</span>.<span class='ident'>short</span>.<span class='ident'>unwrap</span>())
|
|
|
|
|
},
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"\n\t[valid values:{}]"</span>, <span class='ident'>p_vals</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" {}"</span>,<span class='ident'>name</span>)[..] )) ), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"\n [valid values:{}]"</span>, <span class='ident'>p_vals</span>.<span class='ident'>iter</span>().<span class='ident'>fold</span>(<span class='ident'>String</span>::<span class='ident'>new</span>(), <span class='op'>|</span><span class='ident'>acc</span>, <span class='ident'>name</span><span class='op'>|</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='kw-2'>&</span><span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>" {}"</span>,<span class='ident'>name</span>)[..] )) ), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1981,7 +2267,6 @@
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>insert</span>(<span class='ident'>v</span>.<span class='ident'>name</span>, <span class='ident'>OptArg</span>{
|
|
|
|
|
<span class='ident'>name</span>: <span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>to_owned</span>(),
|
|
|
|
|
<span class='comment'>// If arg_val is None occurrences will get incremented upon receiving a value</span>
|
|
|
|
|
<span class='ident'>occurrences</span>: <span class='kw'>if</span> <span class='ident'>arg_val</span>.<span class='ident'>is_some</span>() { <span class='number'>1</span> } <span class='kw'>else</span> { <span class='number'>0</span> },
|
|
|
|
|
<span class='ident'>values</span>: <span class='kw'>if</span> <span class='ident'>arg_val</span>.<span class='ident'>is_some</span>() { <span class='macro'>vec</span><span class='macro'>!</span>[<span class='ident'>arg_val</span>.<span class='ident'>clone</span>().<span class='ident'>unwrap</span>()]} <span class='kw'>else</span> {<span class='macro'>vec</span><span class='macro'>!</span>[]}
|
|
|
|
|
});
|
|
|
|
@ -1990,15 +2275,18 @@
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>bl</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>blacklist</span> {
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>name</span> <span class='kw'>in</span> <span class='ident'>bl</span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>insert</span>(<span class='ident'>name</span>);
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='comment'>// No need to check for existance, returns None if not found</span>
|
|
|
|
|
<span class='comment'>// if self.required.contains(v.name) {</span>
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>v</span>.<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
<span class='comment'>// }</span>
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>reqs</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>requires</span> {
|
|
|
|
|
<span class='comment'>// Add all required args which aren't already found in matches to the</span>
|
|
|
|
|
<span class='comment'>// final required list</span>
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
|
|
|
@ -2015,7 +2303,7 @@
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>v</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>values</span>().<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>long</span>.<span class='ident'>is_some</span>()).<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>long</span>.<span class='ident'>unwrap</span>() <span class='op'>==</span> <span class='ident'>arg</span>).<span class='ident'>nth</span>(<span class='number'>0</span>) {
|
|
|
|
|
<span class='comment'>// Ensure this flag isn't on the mutually excludes list</span>
|
|
|
|
|
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument --{} is mutually exclusive with one or more other arguments"</span>, <span class='ident'>arg</span>),
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument --{} cannot be used with one or more of the other specified arguments"</span>, <span class='ident'>arg</span>),
|
|
|
|
|
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2039,20 +2327,23 @@
|
|
|
|
|
|
|
|
|
|
<span class='comment'>// If this flag was requierd, remove it</span>
|
|
|
|
|
<span class='comment'>// .. even though Flags shouldn't be required</span>
|
|
|
|
|
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='comment'>// No need to check for existance, returns None if not found</span>
|
|
|
|
|
<span class='comment'>// if self.required.contains(v.name) {</span>
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>v</span>.<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
<span class='comment'>// }</span>
|
|
|
|
|
|
|
|
|
|
<span class='comment'>// Add all of this flags "mutually excludes" list to the master list</span>
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>bl</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>blacklist</span> {
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>name</span> <span class='kw'>in</span> <span class='ident'>bl</span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>insert</span>(<span class='ident'>name</span>);
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='comment'>// Add all required args which aren't already found in matches to the master list</span>
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>reqs</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>requires</span> {
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
|
|
|
@ -2094,7 +2385,7 @@
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>v</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>values</span>().<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>short</span>.<span class='ident'>is_some</span>()).<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>short</span>.<span class='ident'>unwrap</span>() <span class='op'>==</span> <span class='ident'>arg_c</span>).<span class='ident'>nth</span>(<span class='number'>0</span>) {
|
|
|
|
|
<span class='comment'>// Ensure this option isn't on the master mutually excludes list</span>
|
|
|
|
|
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument --{} is mutually exclusive with one or more other arguments"</span>, <span class='ident'>arg</span>),
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument -{} cannot be used with one or more of the other specified arguments"</span>, <span class='ident'>arg</span>),
|
|
|
|
|
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2105,7 +2396,7 @@
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>insert</span>(<span class='ident'>v</span>.<span class='ident'>name</span>, <span class='ident'>OptArg</span>{
|
|
|
|
|
<span class='ident'>name</span>: <span class='ident'>v</span>.<span class='ident'>name</span>.<span class='ident'>to_owned</span>(),
|
|
|
|
|
<span class='comment'>// occurrences will get incremented upon receiving a value</span>
|
|
|
|
|
<span class='comment'>// occurrences will be incremented on getting a value</span>
|
|
|
|
|
<span class='ident'>occurrences</span>: <span class='number'>0</span>,
|
|
|
|
|
<span class='ident'>values</span>: <span class='macro'>vec</span><span class='macro'>!</span>[]
|
|
|
|
|
});
|
|
|
|
@ -2113,15 +2404,18 @@
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>bl</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>blacklist</span> {
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>name</span> <span class='kw'>in</span> <span class='ident'>bl</span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>insert</span>(<span class='ident'>name</span>);
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='comment'>// No need to check for existance, returns None if not found</span>
|
|
|
|
|
<span class='comment'>// if self.required.contains(v.name) {</span>
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>v</span>.<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
<span class='comment'>// }</span>
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>reqs</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>requires</span> {
|
|
|
|
|
<span class='comment'>// Add all required args which aren't already found in matches to the</span>
|
|
|
|
|
<span class='comment'>// final required list</span>
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
|
|
|
@ -2142,7 +2436,7 @@
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>v</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>values</span>().<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>short</span>.<span class='ident'>is_some</span>()).<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&</span><span class='ident'>v</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>short</span>.<span class='ident'>unwrap</span>() <span class='op'>==</span> <span class='ident'>arg</span>) {
|
|
|
|
|
<span class='comment'>// Ensure this flag isn't on the mutually excludes list</span>
|
|
|
|
|
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument -{} is mutually exclusive with one or more other arguments"</span>, <span class='ident'>arg</span>),
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument -{} cannot be used with one or more of the other specified arguments"</span>, <span class='ident'>arg</span>),
|
|
|
|
|
<span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2165,20 +2459,24 @@
|
|
|
|
|
|
|
|
|
|
<span class='comment'>// If this flag was requierd, remove it</span>
|
|
|
|
|
<span class='comment'>// .. even though Flags shouldn't be required</span>
|
|
|
|
|
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>contains</span>(<span class='ident'>v</span>.<span class='ident'>name</span>) {
|
|
|
|
|
|
|
|
|
|
<span class='comment'>// No need to check for existance, returns None if it didn't exist</span>
|
|
|
|
|
<span class='comment'>// if self.required.contains(v.name) {</span>
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>v</span>.<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
<span class='comment'>// }</span>
|
|
|
|
|
|
|
|
|
|
<span class='comment'>// Add all of this flags "mutually excludes" list to the master list</span>
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>bl</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>blacklist</span> {
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>name</span> <span class='kw'>in</span> <span class='ident'>bl</span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>insert</span>(<span class='ident'>name</span>);
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>required</span>.<span class='ident'>remove</span>(<span class='ident'>name</span>);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<span class='comment'>// Add all required args which aren't already found in matches to the master list</span>
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>reqs</span>) <span class='op'>=</span> <span class='ident'>v</span>.<span class='ident'>requires</span> {
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>n</span> <span class='kw'>in</span> <span class='ident'>reqs</span> {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>matched_reqs</span>.<span class='ident'>insert</span>(<span class='ident'>n</span>);
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>n</span>) { <span class='kw'>continue</span>; }
|
|
|
|
@ -2194,7 +2492,7 @@
|
|
|
|
|
<span class='kw'>fn</span> <span class='ident'>validate_blacklist</span>(<span class='kw-2'>&</span><span class='self'>self</span>, <span class='ident'>matches</span>: <span class='kw-2'>&</span><span class='ident'>ArgMatches</span><span class='op'><</span><span class='lifetime'>'ar</span><span class='op'>></span>) {
|
|
|
|
|
<span class='kw'>for</span> <span class='ident'>name</span> <span class='kw'>in</span> <span class='self'>self</span>.<span class='ident'>blacklist</span>.<span class='ident'>iter</span>() {
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>flags</span>.<span class='ident'>contains_key</span>(<span class='ident'>name</span>) {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument {} is mutually exclusive with one or more other arguments"</span>,
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument {} cannot be used with one or more of the other specified arguments"</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>s</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>short</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>, <span class='ident'>s</span>)
|
|
|
|
|
} <span class='kw'>else</span> <span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>flags</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>long</span> {
|
|
|
|
@ -2204,17 +2502,17 @@
|
|
|
|
|
}), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>opts</span>.<span class='ident'>contains_key</span>(<span class='ident'>name</span>) {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument {} is mutually exclusive with one or more other arguments"</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>s</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>short</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>, <span class='ident'>s</span>)
|
|
|
|
|
} <span class='kw'>else</span> <span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>long</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"--{}"</span>, <span class='ident'>l</span>)
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument {} cannot be used with one or more of the other specified arguments"</span>,
|
|
|
|
|
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>s</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>long</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"--{}"</span>, <span class='ident'>s</span>)
|
|
|
|
|
} <span class='kw'>else</span> <span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>opts</span>.<span class='ident'>get</span>(<span class='ident'>name</span>).<span class='ident'>unwrap</span>().<span class='ident'>short</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"-{}"</span>, <span class='ident'>l</span>)
|
|
|
|
|
} <span class='kw'>else</span> {
|
|
|
|
|
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"\"{}\""</span>, <span class='ident'>name</span>)
|
|
|
|
|
}), <span class='boolval'>true</span>, <span class='boolval'>true</span>);
|
|
|
|
|
}
|
|
|
|
|
<span class='kw'>if</span> <span class='ident'>matches</span>.<span class='ident'>positionals</span>.<span class='ident'>contains_key</span>(<span class='ident'>name</span>) {
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument \"{}\" is mutually exclusive with one or more other arguments"</span>,<span class='ident'>name</span>),
|
|
|
|
|
<span class='self'>self</span>.<span class='ident'>report_error</span>(<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>"The argument \"{}\" cannot be used with one or more of the other specified arguments"</span>,<span class='ident'>name</span>),
|
|
|
|
|
<span class='boolval'>false</span>, <span class='boolval'>true</span>);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|