-- mkopt -----------------------------------------------------------------------

mkopt :: OptDesc -> ExpQ
mkopt optdesc =
  let (shorts, longs) = partition ((1==) . length) $ optdesc ^. names
      display_type    = case dropWhile (`elem` "*?") $ optdesc ^. typename of
                          '[' : '<' : y -> '[' : (tail . dropWhile (/= '>')) y
                          '[' : ',' : x -> '[' : x
                          x             -> x
      display_dflt    = -- trim off any leading 'id '; replace "..." with ...;
                        -- remove anything Nothing
                        let disp = ("^\\\"(.+)\\\"$" `subst` "$1") $
                                     case dfltTxt optdesc of
                                       'i' : 'd' : ' ' : x -> x
                                       "GHC.Types.[]"      -> "[]"
                                       y                   -> y
                         in case disp of
                              "Data.Maybe.Nothing" -> ""
                              "Nothing"            -> ""
                              z                    -> z
   in -- mkOpt shorts longs
      --       (optSetVal optdesc)
      --       (optdesc ^. summary)
      --       (optdesc ^. descn)
      --       (display_type)
      --       (display_dflt)
      mAppEQ [ return $ VarE 'mkOpt
             , appE (varE 'concat) (lift shorts) -- short options
             , lift longs                        -- long  options
             , optSetVal optdesc                 -- handler (setval*)
             , stringEQ $ optdesc ^. summary     -- summary help
             , stringEQ $ optdesc ^. descn       -- long help
             , stringEQ   display_type           -- type name text (for help)
             , stringEQ   display_dflt           -- default value (for help)
             ]
mkopt :: OptDesc -> ExpQ
mkopt optdesc =
  let (shorts, longs) = partition ((1==) . length) $ optdesc ^. names
      display_type    = case dropWhile (`elem` "*?") $ optdesc ^. typename of
                          '[' : '<' : y -> '[' : (tail . dropWhile (/= '>')) y
                          '[' : ',' : x -> '[' : x
                          x             -> x
      display_dflt    = -- trim off any leading 'id '; replace "..." with ...;
                        -- remove anything Nothing
                        let disp = ("^\\\"(.+)\\\"$" `subst` "$1") $
                                     case dfltTxt optdesc of
                                       'i' : 'd' : ' ' : x -> x
                                       "GHC.Types.[]"      -> "[]"
                                       y                   -> y
                         in case disp of
                              "Data.Maybe.Nothing" -> ""
                              "Nothing"            -> ""
                              z                    -> z
   in -- mkOpt shorts longs
      --       (optSetVal optdesc)
      --       (optdesc ^. summary)
      --       (optdesc ^. descn)
      --       (display_type)
      --       (display_dflt)
      mAppEQ [ return $ VarE 'mkOpt
             , appE (varE 'concat) (lift shorts) -- short options
             , lift longs                        -- long  options
             , optSetVal optdesc                 -- handler (setval*)
             , stringEQ $ optdesc ^. summary     -- summary help
             , stringEQ $ optdesc ^. descn       -- long help
             , stringEQ   display_type           -- type name text (for help)
             , stringEQ   display_dflt           -- default value (for help)
             ]
mkopt optdesc =
  let (shorts, longs) = partition ((1==) . length) $ optdesc ^. names
      display_type    = case dropWhile (`elem` "*?") $ optdesc ^. typename of
                          '[' : '<' : y -> '[' : (tail . dropWhile (/= '>')) y
                          '[' : ',' : x -> '[' : x
                          x             -> x
      display_dflt    = -- trim off any leading 'id '; replace "..." with ...;
                        -- remove anything Nothing
                        let disp = ("^\\\"(.+)\\\"$" `subst` "$1") $
                                     case dfltTxt optdesc of
                                       'i' : 'd' : ' ' : x -> x
                                       "GHC.Types.[]"      -> "[]"
                                       y                   -> y
                         in case disp of
                              "Data.Maybe.Nothing" -> ""
                              "Nothing"            -> ""
                              z                    -> z
   in -- mkOpt shorts longs
      --       (optSetVal optdesc)
      --       (optdesc ^. summary)
      --       (optdesc ^. descn)
      --       (display_type)
      --       (display_dflt)
      mAppEQ [ return $ VarE 'mkOpt
             , appE (varE 'concat) (lift shorts) -- short options
             , lift longs                        -- long  options
             , optSetVal optdesc                 -- handler (setval*)
             , stringEQ $ optdesc ^. summary     -- summary help
             , stringEQ $ optdesc ^. descn       -- long help
             , stringEQ   display_type           -- type name text (for help)
             , stringEQ   display_dflt           -- default value (for help)
             ]