@@ -41,12 +41,12 @@ type alias CliOptions =
4141 , outputDirectory : String
4242 , outputModuleName : Maybe String
4343 , effectTypes : List OpenApi . Config . EffectType
44- , generateTodos : Bool
44+ , server : OpenApi . Config . Server
4545 , autoConvertSwagger : OpenApi . Config . AutoConvertSwagger
4646 , swaggerConversionUrl : Maybe String
4747 , swaggerConversionCommand : Maybe String
4848 , swaggerConversionCommandArgs : List String
49- , server : OpenApi . Config . Server
49+ , generateTodos : Bool
5050 , overrides : List OpenApi . Config . Path
5151 , writeMergedTo : Maybe String
5252 , noElmFormat : Bool
@@ -65,126 +65,138 @@ program =
6565 |> Cli . OptionsParser . with
6666 ( Cli . Option . optionalKeywordArg " output-dir"
6767 |> Cli . Option . withDefault " generated"
68+ |> Cli . Option . withDescription " The directory to output to. Defaults to `generated/`."
6869 )
6970 |> Cli . OptionsParser . with
70- ( Cli . Option . optionalKeywordArg " module-name" )
71+ ( Cli . Option . optionalKeywordArg " module-name"
72+ |> Cli . Option . withDescription " The Elm module name. Defaults to `OAS info.title`."
73+ )
7174 |> Cli . OptionsParser . with
7275 ( Cli . Option . optionalKeywordArg " effect-types"
7376 |> Cli . Option . validateMap effectTypesValidation
77+ |> Cli . Option . withDescription
78+ ( [ " A list of which kind of APIs to generate."
79+ , " Each item should be of the form `package.type`."
80+ , " If `package` is omitted it defaults to `elm/http`."
81+ , " If `type` is omitted it defaults to `cmd,task`."
82+ , " If not specified, defaults to `cmd,task` (for elm/http)."
83+ , " The options for package are:"
84+ , " - elm/http"
85+ , " - dillonkearns/elm-pages"
86+ , " - lamdera/program-test"
87+ , " The options for type are:"
88+ , " - cmd: Cmd for elm/http,"
89+ , " Effect.Command for lamdera/program-test"
90+ , " - cmdrisky: as above, but using Http.riskyRequest"
91+ , " - cmdrecord: the input to Http.request"
92+ , " - task: Task for elm/http"
93+ , " Effect.Task for lamdera/program-test"
94+ , " BackendTask for dillonkearns/elm-pages"
95+ , " - taskrisky: as above, but using Http.riskyTask"
96+ , " cannot be used for dillonkearns/elm-pages"
97+ , " - taskrecord: the input to Http.task"
98+ ]
99+ |> formatOptionDescription
100+ )
74101 )
75102 |> Cli . OptionsParser . with
76- ( Cli . Option . flag " generateTodos" )
103+ ( Cli . Option . optionalKeywordArg " server"
104+ |> Cli . Option . validateMap serverValidation
105+ |> Cli . Option . withDescription
106+ ( [ " The base URL for the OpenAPI server."
107+ , " If not specified this will be extracted from the OAS"
108+ , " or default to root of the web application."
109+ , " "
110+ , " You can pass in an object to define multiple servers, like"
111+ , """ {"dev": "http://localhost", "prod": "https://example.com"}."""
112+ , " "
113+ , " This will add a `server` parameter to functions and define"
114+ , " a `Servers` module with your servers. You can pass in an"
115+ , " empty object if you have fully dynamic servers."
116+ ]
117+ |> formatOptionDescription
118+ )
119+ )
77120 |> Cli . OptionsParser . with
78121 ( Cli . Option . optionalKeywordArg " auto-convert-swagger"
79122 |> Cli . Option . validateMap autoConvertValidation
123+ |> Cli . Option . withDescription
124+ ( [ " \" ask\" If a Swagger doc is encountered, ask the user before converting"
125+ , " it to an Open API file. This is the default."
126+ , " \" never\" If a Swagger doc is encountered, error out."
127+ , " \" always\" If a Swagger doc is encountered, automatically convert it"
128+ , " to an Open API file."
129+ ]
130+ |> formatOptionDescription
131+ )
80132 )
81133 |> Cli . OptionsParser . with
82- ( Cli . Option . optionalKeywordArg " swagger-conversion-url" )
134+ ( Cli . Option . optionalKeywordArg " swagger-conversion-url"
135+ |> Cli . Option . withDescription
136+ ( [ " The URL to use to convert a Swagger doc to an Open API"
137+ , " file. Defaults to `https://converter.swagger.io/api/convert`."
138+ ]
139+ |> formatOptionDescription
140+ )
141+ )
83142 |> Cli . OptionsParser . with
84- ( Cli . Option . optionalKeywordArg " swagger-conversion-command" )
143+ ( Cli . Option . optionalKeywordArg " swagger-conversion-command"
144+ |> Cli . Option . withDescription
145+ ( [ " Instead of making an HTTP request to convert"
146+ , " from Swagger to Open API, use this command."
147+ ]
148+ |> formatOptionDescription
149+ )
150+ )
85151 |> Cli . OptionsParser . with
86- ( Cli . Option . keywordArgList " swagger-conversion-command-args" )
152+ ( Cli . Option . keywordArgList " swagger-conversion-command-args"
153+ |> Cli . Option . withDescription
154+ ( [ " Additional arguments to pass to the Swagger conversion command,"
155+ , " before the contents of the Swagger file are passed in."
156+ ]
157+ |> formatOptionDescription
158+ )
159+ )
87160 |> Cli . OptionsParser . with
88- ( Cli . Option . optionalKeywordArg " server"
89- |> Cli . Option . validateMap serverValidation
161+ ( Cli . Option . flag " generateTodos"
162+ |> Cli . Option . withDescription
163+ ( [ " Whether to generate TODOs for unimplemented endpoints,"
164+ , " or fail when something unexpected is encountered."
165+ , " Defaults to `no`. To generate `Debug.todo \"\" `"
166+ , " instead of failing use one of: `yes`, `y`, `true`."
167+ ]
168+ |> formatOptionDescription
169+ )
90170 )
91171 |> Cli . OptionsParser . with
92172 ( Cli . Option . keywordArgList " overrides"
93173 |> Cli . Option . map ( List . map OpenApi . Config . pathFromString)
174+ |> Cli . Option . withDescription " Load an additional file to override parts of the original Open API file."
94175 )
95176 |> Cli . OptionsParser . with
96- ( Cli . Option . optionalKeywordArg " write-merged-to" )
177+ ( Cli . Option . optionalKeywordArg " write-merged-to"
178+ |> Cli . Option . withDescription " Write the merged Open API spec to the given file."
179+ )
97180 |> Cli . OptionsParser . with
98- ( Cli . Option . flag " no-elm-format" )
99- |> Cli . OptionsParser . withDoc
100- ( [ " "
101- , """ version: 0.7.0"""
102- , """ options:"""
103- , formatOption " output-dir" [ " The directory to output to. Defaults to `generated/`." ]
104- , formatOption " module-name" [ " The Elm module name. Defaults to `OAS info.title`." ]
105- , formatOption " effect-types"
106- [ " A list of which kind of APIs to generate."
107- , " Each item should be of the form `package.type`."
108- , " If `package` is omitted it defaults to `elm/http`."
109- , " If `type` is omitted it defaults to `cmd,task`."
110- , " If not specified, defaults to `cmd,task` (for elm/http)."
111- , " The options for package are:"
112- , " - elm/http"
113- , " - dillonkearns/elm-pages"
114- , " - lamdera/program-test"
115- , " The options for type are:"
116- , " - cmd: Cmd for elm/http,"
117- , " Effect.Command for lamdera/program-test"
118- , " - cmdrisky: as above, but using Http.riskyRequest"
119- , " - cmdrecord: the input to Http.request"
120- , " - task: Task for elm/http"
121- , " Effect.Task for lamdera/program-test"
122- , " BackendTask for dillonkearns/elm-pages"
123- , " - taskrisky: as above, but using Http.riskyTask"
124- , " cannot be used for dillonkearns/elm-pages"
125- , " - taskrecord: the input to Http.task"
126- ]
127- , formatOption " server"
128- [ " The base URL for the OpenAPI server."
129- , " If not specified this will be extracted from the OAS"
130- , " or default to root of the web application."
131- , " "
132- , " You can pass in an object to define multiple servers, like"
133- , """ {"dev": "http://localhost", "prod": "https://example.com"}."""
134- , " "
135- , " This will add a `server` parameter to functions and define"
136- , " a `Servers` module with your servers. You can pass in an"
137- , " empty object if you have fully dynamic servers."
138- ]
139- , formatOption " auto-convert-swagger=ask"
140- [ " If a Swagger doc is encountered, ask the user before converting"
141- , " it to an Open API file. This is the default."
142- ]
143- , formatOption " auto-convert-swagger=never" [ " If a Swagger doc is encountered, error out." ]
144- , formatOption " auto-convert-swagger[=always]"
145- [ " If a Swagger doc is encountered, automatically convert it"
146- , " to an Open API file."
147- ]
148- , formatOption " swagger-conversion-url"
149- [ " The URL to use to convert a Swagger doc to an Open API"
150- , " file. Defaults to `https://converter.swagger.io/api/convert`."
151- ]
152- , formatOption " swagger-conversion-command"
153- [ " Instead of making an HTTP request to convert"
154- , " from Swagger to Open API, use this command."
155- ]
156- , formatOption " swagger-conversion-command-args"
157- [ " Additional arguments to pass to the Swagger conversion command,"
158- , " before the contents of the Swagger file are passed in."
159- ]
160- , formatOption " generateTodos"
161- [ " Whether to generate TODOs for unimplemented endpoints,"
162- , " or fail when something unexpected is encountered."
163- , " Defaults to `no`. To generate `Debug.todo \"\" `"
164- , " instead of failing use one of: `yes`, `y`, `true`."
165- ]
166- , formatOption " overrides" [ " Load an additional file to override parts of the original Open API file." ]
167- , formatOption " write-merged-to" [ " Write the merged Open API spec to the given file." ]
168- , formatOption " no-elm-format" [ " Don't run elm-format on the outputs." ]
169- ]
170- |> String . join " \n\n "
181+ ( Cli . Option . flag " no-elm-format"
182+ |> Cli . Option . withDescription " Don't run elm-format on the outputs."
171183 )
172184 )
173185
174186
175- formatOption : String -> List String -> String
176- formatOption key descriptionLines =
187+ formatOptionDescription : List String -> String
188+ formatOptionDescription descriptionLines =
177189 descriptionLines
178190 |> List . indexedMap
179191 ( \ i line ->
180192 if i == 0 then
181- " " ++ String . padRight 35 ' ' ( " -- " ++ key ) ++ line
193+ line
182194
183195 else if String . isEmpty line then
184196 " "
185197
186198 else
187- " " ++ String . padRight 35 ' ' " " ++ line
199+ String . padRight 72 ' ' " " ++ line
188200 )
189201 |> String . join " \n "
190202
0 commit comments