[codemod] Give proper error when run without arguments
[codemod] Give proper error when run without arguments

Summary:
When a codemod command is run with no arguments, it gives an error,
because it requires a list of filenames.

But rather than a proper error message, it was crashing with an
OCaml traceback:

  Unhandled exception: (Failure hd)
  Raised at file "stdlib.ml", line 29, characters 17-33
  Called from file "list.ml", line 30, characters 10-23
  Called from file "src/commands/commandUtils.ml", line 13, characters 4-32

There was already a conditional intended to provide a helpful error
message for the lack of filenames.  But earlier in the function, if
there's no --root, we were trying to take the first filename in order
to guess the root.  That caused the crash.

The fix is to move that check sooner.  (Nothing touches `filenames`
in between, so this doesn't have any other effect.)  Now the command
fails properly with:

  Error: filenames or --input-file are required

Also move a neighboring comment to the line it looks like it was
intended to apply to.

This fix would be good to backport to a v0.162.2, so that it can
apply to the replace-existentials codemod advertised in the v0.163.0
release notes.

Fixes: https://github.com/facebook/flow/issues/8782

Pull Request resolved: https://github.com/facebook/flow/pull/8783

Reviewed By: mroch

Differential Revision: D32239616

Pulled By: gkz

fbshipit-source-id: 35d39c1b38ccf7e1dbe4412130357d78b179bd76

mroch/flow,mroch/flow,facebook/flow,facebook/flow,facebook/flow,facebook/flow,facebook/flow,mroch/flow,mroch/flow,mroch/flow,mroch/flow,mroch/flow,facebook/flow,facebook/flow