GiulioSavini opened a new pull request, #13825:
URL: https://github.com/apache/trafficserver/pull/13825

   ## Summary
   
   `ts::ArgParser` lets a command or option declare an environment variable, 
but nothing ever
   read it except `src/tscore/unit_tests/test_ArgParser.cc`. The value was 
captured into
   `ArgumentData::env()` when the flag was typed with an explicit value, but 
could never fill a
   value that was left out, so every real declaration was decorative:
   
   - `traffic_ctl config get/set --cold` declares `TS_RECORD_YAML`, but `-c` 
with no file name
     always fell back to the compiled-in `records.yaml` path.
   - `traffic_ctl server debug enable --tags` declares `TS_DEBUG_TAGS`, but 
`--tags` with no
     value was a hard usage error (`1 argument(s) expected by tags`).
   
   This resolves the declared variable into the option's values during parsing, 
so a caller
   reading through `ArgumentData::value()`/`at()` needs no special handling. 
Precedence is:
   
   1. the value typed on the command line, if any
   2. the declared environment variable, if set
   3. the declared default value
   
   The variable is only consulted when the command or option is actually 
written on the command
   line; it never activates one that was never typed (this matches the "open 
question" the issue
   raised, deliberately keeping that out of scope).
   
   Covers all three cases that can have a missing value: a fixed-arity option 
(e.g.
   `--tags TAGS`), `AT_MOST_ONE_ARG_N` (e.g. `--cold [FILE]`), and 
`MORE_THAN_ONE_ARG_N`
   collecting none.
   
   ## Verification
   
   ```
   $ TS_RECORD_YAML=/tmp/records.yaml traffic_ctl config get 
proxy.config.diags.debug.enabled -c
   proxy.config.diags.debug.enabled: 1
   
   $ traffic_ctl config get proxy.config.diags.debug.enabled -c
   config get error: bad file: /etc/trafficserver/records.yaml   # unchanged 
when unset
   ```
   
   Added `src/tscore/unit_tests/test_ArgParser.cc` coverage for all three 
arities, the
   typed-value-wins-over-env and env-wins-over-default precedence, and that 
usage errors are
   unchanged when no variable is declared or it is declared but unset. Full 
`test_tscore` suite
   passes (`ctest --test-dir build-dev`), as does a manual `traffic_ctl` 
build/run of the repro
   above.
   
   Fixes #13588
   
   ## Test plan
   
   - [x] `cmake --build build-dev --target test_tscore` and run 
`./build-dev/src/tscore/test_tscore`
   - [x] `cmake --build build-dev --target format`
   - [x] Manual repro of both `TS_RECORD_YAML` and the unset fallback against a 
built `traffic_ctl`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to