Skip to content

Commit 1e1e793

Browse files
authored
Merge pull request #272 from wolfadex/simplify-help-generation
Simplify help generation
2 parents 32b72d5 + d287b0a commit 1e1e793

1 file changed

Lines changed: 90 additions & 68 deletions

File tree

cli/src/Cli.elm

Lines changed: 90 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -96,75 +96,97 @@ program =
9696
(Cli.Option.optionalKeywordArg "write-merged-to")
9797
|> Cli.OptionsParser.with
9898
(Cli.Option.flag "no-elm-format")
99-
|> Cli.OptionsParser.withDoc """
100-
version: 0.7.0
101-
102-
options:
103-
104-
--output-dir The directory to output to. Defaults to `generated/`.
105-
106-
--module-name The Elm module name. Defaults to `OAS info.title`.
107-
108-
--effect-types A list of which kind of APIs to generate.
109-
Each item should be of the form `package.type`.
110-
If `package` is omitted it defaults to `elm/http`.
111-
If `type` is omitted it defaults to `cmd,task`.
112-
If not specified, defaults to `cmd,task` (for elm/http).
113-
The options for package are:
114-
- elm/http
115-
- dillonkearns/elm-pages
116-
- lamdera/program-test
117-
The options for type are:
118-
- cmd: Cmd for elm/http,
119-
Effect.Command for lamdera/program-test
120-
- cmdrisky: as above, but using Http.riskyRequest
121-
- cmdrecord: the input to Http.request
122-
- task: Task for elm/http
123-
Effect.Task for lamdera/program-test
124-
BackendTask for dillonkearns/elm-pages
125-
- taskrisky: as above, but using Http.riskyTask
126-
cannot be used for dillonkearns/elm-pages
127-
- taskrecord: the input to Http.task
128-
129-
--server The base URL for the OpenAPI server.
130-
If not specified this will be extracted from the OAS
131-
or default to root of the web application.
132-
133-
You can pass in an object to define multiple servers, like
134-
{"dev": "http://localhost", "prod": "https://example.com"}.
135-
136-
This will add a `server` parameter to functions and define
137-
a `Servers` module with your servers. You can pass in an
138-
empty object if you have fully dynamic servers.
139-
140-
--auto-convert-swagger=ask If a Swagger doc is encountered, ask the user before converting
141-
it to an Open API file. This is the default.
142-
143-
--auto-convert-swagger=never If a Swagger doc is encountered, error out.
144-
145-
--auto-convert-swagger[=always] If a Swagger doc is encountered, automatically convert it
146-
to an Open API file.
147-
148-
--swagger-conversion-url The URL to use to convert a Swagger doc to an Open API
149-
file. Defaults to `https://converter.swagger.io/api/convert`.
150-
151-
--swagger-conversion-command Instead of making an HTTP request to convert
152-
from Swagger to Open API, use this command.
153-
154-
--swagger-conversion-command-args Additional arguments to pass to the Swagger conversion command,
155-
before the contents of the Swagger file are passed in.
156-
157-
--generateTodos Whether to generate TODOs for unimplemented endpoints,
158-
or fail when something unexpected is encountered.
159-
Defaults to `no`. To generate `Debug.todo ""`
160-
instead of failing use one of: `yes`, `y`, `true`.
161-
162-
--overrides Load an additional file to override parts of the original Open API file.
163-
164-
--write-merged-to Write the merged Open API spec to the given file.
165-
--no-elm-format Don't run elm-format on the outputs.
166-
"""
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"
171+
)
172+
)
173+
174+
175+
formatOption : String -> List String -> String
176+
formatOption key descriptionLines =
177+
descriptionLines
178+
|> List.indexedMap
179+
(\i line ->
180+
if i == 0 then
181+
" " ++ String.padRight 35 ' ' ("--" ++ key) ++ line
182+
183+
else if String.isEmpty line then
184+
""
185+
186+
else
187+
" " ++ String.padRight 35 ' ' "" ++ line
167188
)
189+
|> String.join "\n"
168190

169191

170192
autoConvertValidation : Maybe String -> Result String OpenApi.Config.AutoConvertSwagger

0 commit comments

Comments
 (0)