Skip to content

Main content

Option Duplicate Policy Resolver

Resolve explicit option duplicate occurrences under first/last/all/reject policy, retaining winning source indexes; not command-line token parsing.

Loading tool…

Description

Resolve explicit option duplicate occurrences under first/last/all/reject policy, retaining winning source indexes; not command-line token parsing.

An argv vector already consists of literal argument strings. Shell quoting and tokenization happen before this representation; joining argv elements with spaces does not reconstruct a safe command string. Option aliases, duplicates, arity and dependencies are application policies that these tools take explicitly.

Resolve explicit option duplicate occurrences under first/last/all/reject policy, retaining winning source indexes; not command-line token parsing.

When to use this tool

Use this tool to resolve explicit option duplicate occurrences under first/last/all/reject policy, retaining winning source indexes; not command-line token parsing.

How to use the tool and how it works

  1. Enter occurrencesJson, policy using the input definitions below. Serialize the JSON text fields in the decoded shape shown below.
  2. Run the operation. Resolve malformed-input errors before interpreting the result.
  3. Read result.records. Interpret signs, units, ordering and null values using the rules below.

Group exact option names in first-appearance order. first/last retain the corresponding original occurrence, all retains every occurrence, and reject errors on any repeated name. Return selected values with their source indexes.1

Input fieldMeaning and unitsAccepted input
occurrencesJsonJSON array of {name,value} string records, preserving duplicate occurrences.Text, at most 8,192 UTF-16 code units; the stated grammar and narrower limits also apply.
policyExact duplicate policy: first, last, all or reject.Text, at most 8,192 UTF-16 code units; the stated grammar and narrower limits also apply.

These decoded examples show the structure of the JSON text fields. Supply each as its corresponding serialized JSON string.

json
{
  "occurrencesJson": [
    {
      "name": "x",
      "value": "1"
    },
    {
      "name": "x",
      "value": "2"
    }
  ]
}
Output fieldInterpretation
resultObject containing the fields below.
result.recordsFirst-seen name groups with chosen values and original occurrence indexes.
json
{
  "input": {
    "occurrencesJson": "[{\"name\":\"x\",\"value\":\"1\"},{\"name\":\"x\",\"value\":\"2\"}]",
    "policy": "last"
  },
  "output": {
    "result": {
      "records": [
        {
          "name": "x",
          "values": [
            "2"
          ],
          "sourceIndexes": [
            1
          ]
        }
      ]
    }
  }
}

Limitations and assumptions

  • This resolves supplied records, without parsing command-line tokens or assuming a default duplicate policy.
  • Inputs are literal tokens or explicit records. The restricted long-name grammar is [A-Za-z0-9][A-Za-z0-9-]* where required. No universal option syntax, shell semantics or process execution is inferred.
  • Every declared top-level input is required and unknown fields are rejected. Ordinary strings are limited to 8,192 UTF-16 code units and lists to 128 entries, with tighter operation-specific bounds where stated. JSON text has bounded nesting and node counts.
  • Numeric outputs must be finite and within the absolute safe-integer magnitude; exact larger integers use decimal text. Source positions are zero-based UTF-16 offsets and span ends are exclusive unless a different convention is explicitly stated.

Alternative or Complementary methods

Use the application’s option schema to choose arity, aliases and conflict policy. Pass a literal argv vector to the intended process interface; shell command construction requires separate quoting rules.

References

  1. Tool behavior and example: Option Duplicate Policy Resolver — tool.io

Similar or alternative tools

  • Long Option Assignment Joiner

    Format one literal long-option argv token under a restricted ASCII option-name grammar; returns one argument, not shell quoting.

  • Long Option Assignment Splitter

    Split one strict ASCII --long-name[=value] argv token at the first equals; no shell parsing or implicit next-token consumption.