Fix -pm <value> parsing and add comma-separated multi-fact -F #14
Reference in New Issue
Block a user
Delete Branch "benvin/positional-match-value"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Two related query-ergonomics fixes surfaced while using the tool interactively.
1.
-pm <value>failed withunknown command "k8s"pflag does not attach a space-separated value to a string flag (
-m) grouped with a bool flag (-p), sok8swas left as a stray positional. Only-pm=k8sor the un-grouped-p -m k8sworked.cobra.MaximumNArgs(1)) and fall back to it for the match value when-mis empty (matchValue()).-pm/-im/-ipm <value>and a bare-p <value>now all work;-mstill wins when both are given.2.
-F a,b(multiple facts) returned{}-jF ipaddress,enc_rolequeried a single fact literally namedipaddress,enc_role.-Fon commas (splitFactNames) and match any of them via anorover["=","name",<n>]clauses (nameFilter); a single name keeps the plain=form.Both paths have unit tests; verified live:
node-lookup -R -pm externaldns | node-lookup -jF ipaddress,enc_rolereturns both facts per host. AGENTS.md updated.`node-lookup -jF ipaddress,enc_role` returned `{}` because it queried a single fact literally named "ipaddress,enc_role". Requesting several facts per host is a natural need (e.g. pairing an address with its role). - Split -F on commas (splitFactNames) and match any of them via an "or" over ["=","name",<n>] clauses (nameFilter); a single name keeps the plain "=" form. - Key JSON output by each result's real fact name so all requested facts appear under the host (previously keyed by the raw -F string). - Update the -F flag help and add unit tests (split, single vs multi query shape, multi-fact JSON).Accept match value positionally so -pm <value> worksto Fix -pm <value> parsing and add comma-separated multi-fact -F`-A` emitted hosts with empty vars, so `-F ipaddress,enc_role -A` lost the facts it just queried. Ansible inventories are far more useful with the values inline. - Extract factsByHost() (the {host: {fact: value}} builder) and share it between -j and -A so the Ansible inventory attaches each host's queried fact(s) as host vars, keyed by real fact name. - Strengthen the Ansible test to assert host vars and add a multi-fact case.