Improve errors from the option parser in daml2js (#6362)

fixes #6353
fixes #6352

This fixes the program name to refer to `daml codegen js` and changes
the behavior to show help if the parser fails. Putting things together
running `daml codegen js` without arguments now looks as follows:

```
Missing: DAR-FILES -o DIR

Usage: daml codegen js DAR-FILES -o DIR [-s SCOPE]
  Generate TypeScript bindings from a DAR

Available options:
  DAR-FILES                DAR files to generate TypeScript bindings for
  -o DIR                   Output directory for the generated packages
  -s SCOPE                 The NPM scope name for the generated packages;
                           defaults to daml.js
  -h,--help                Show this help text
```

changelog_begin
changelog_end
This commit is contained in:
Moritz Kiefer 2020-06-16 12:28:24 +02:00 committed by GitHub
parent d93b7b2513
commit 03d3115a00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,6 +30,7 @@ import Data.Maybe
import Data.Bifoldable
import Options.Applicative
import System.Directory
import System.Environment
import System.FilePath hiding ((<.>))
import System.Process
import System.Exit
@ -119,8 +120,8 @@ mergePackageMap ps = foldM merge Map.empty ps
-- Write packages for all the DALFs in all the DARs.
main :: IO ()
main = do
opts@Options{..} <- execParser optionsParserInfo
main = withProgName "daml codegen js" $ do
opts@Options{..} <- customExecParser (prefs showHelpOnError) optionsParserInfo
sdkVersionOrErr <- DATypes.parseVersion . T.pack . fromMaybe "0.0.0" <$> getSdkVersionMaybe
sdkVersion <- case sdkVersionOrErr of
Left _ -> fail "Invalid SDK version"