gsctool: consolidate processing of optional parameters
gsctool: consolidate processing of optional parameters

Standard libc getopt_long() and getopt() functions do not allow the
optional parameters to follow the command line option without the equal
sign ('='), but gsctool utility users expect this form to be
available, so additional processing is done for command line arguments
accepting optional parameters.

This additional processing code is duplicated for each such argument.
On top of that, some arguments which described as requiring the
parameter (not optional) still include code which looks for the
command line option.

Information about expected parameter type is included in the long
options descriptor table, so it is not readily available if the user
specified the short version of the argument in the command line.

To consolidate processing of the optional parameters in one place, in
case the user specified the short version of the command line
argument, the long_opts table is looked up to find the appropriate
long version, then the parameter type is checked, and if the parameter
is supposed to be optional, the next command line token is examined to
determine if this is the optional parameter.

BRANCH=none
BUG=none
TEST=tried the following commands:
      - tried the following commands:
  ./extra/usb_updater/gsctool -b # reports missing file name error

  # All the following succeed processing command line parameters:
  ./extra/usb_updater/gsctool -m
  ./extra/usb_updater/gsctool -m enable
  ./extra/usb_updater/gsctool --tpm_mode enable
  ./extra/usb_updater/gsctool --tpm_mode=enable

  # All the following fail processing command line parameters
  # reporting 'Invalid tpm mode arg: xxx.':

  ./extra/usb_updater/gsctool -m xxx
  ./extra/usb_updater/gsctool --tpm_mode xxx
  ./extra/usb_updater/gsctool --tpm_mode=xxx

Change-Id: I68e9cc312aa8a5a2cccbd78df66a24ac71f78c36
Signed-off-by: Vadim Bendebury <5515d6d2d0829cbe0dd0dcf2094aaded06d58514@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1621185
Legacy-Commit-Queue: Commit Bot <5c2bf027dc5cc7ef186314391646e49f6866dc00@chromium.org>
Reviewed-by: Andrey Pronin <53bbebe6910b11f7aa2d1daaa466658eb4cba5f2@chromium.org>

coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec,coreboot/chrome-ec