HomeClusterLabs Projects

Refactor: tools: Clean up shadow NULL-checking in crm_shadow.c

Description

Refactor: tools: Clean up shadow NULL-checking in crm_shadow.c

There was some redundancy in NULL-checking shadow that made the code
harder to follow.

For query options, we already NULL-check shadow (from
getenv("CIB_shadow")) during argument processing.

For command options, an optarg is required, and that optarg is copied to
shadow, so we know shadow is non-NULL in that case too.

That only leave the case where no command flag is set. We can simply
treat that case as an error, using default flag '?' to call help and
return a usage error. We can also exit OK early if '?' or '$' is
passed explicitly -- there's no reason to process the rest of the
arguments if help or version is requested. This ensures that we don't
show the help output twice if no command flag is set.

These changes will make it easier to convert to GOption (and more
importantly easier to review that change).

Ref T98

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>

Details

Provenance
nrwahl2Authored on Nov 20 2022, 5:30 PM
Parents
rPd951274815c3: Merge pull request #2936 from rtczza/main
Branches
Unknown
Tags
Unknown
Tasks
Restricted Maniphest Task