Skip to content

Commit 03d74dd

Browse files
committed
Better help message
1 parent 65d3e54 commit 03d74dd

1 file changed

Lines changed: 27 additions & 53 deletions

File tree

cli/src/Cli.elm

Lines changed: 27 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,25 @@ program =
6060
|> Cli.Program.add
6161
(Cli.OptionsParser.build CliOptions
6262
|> Cli.OptionsParser.with
63-
(Cli.Option.requiredPositionalArg "entryFilePath"
63+
(Cli.Option.requiredPositionalArg "input-file"
64+
|> Cli.Option.withDisplayName "file.json|file.yaml"
6465
|> Cli.Option.map OpenApi.Config.pathFromString
6566
)
6667
|> Cli.OptionsParser.with
6768
(Cli.Option.optionalKeywordArg "output-dir"
6869
|> Cli.Option.withDefault "generated"
70+
|> Cli.Option.withDisplayName "dir"
6971
|> Cli.Option.withDescription "The directory to output to. Defaults to `generated/`."
7072
)
7173
|> Cli.OptionsParser.with
7274
(Cli.Option.optionalKeywordArg "module-name"
75+
|> Cli.Option.withDisplayName "Elm.Module.Name"
7376
|> Cli.Option.withDescription "The Elm module name. Defaults to `OAS info.title`."
7477
)
7578
|> Cli.OptionsParser.with
7679
(Cli.Option.optionalKeywordArg "effect-types"
7780
|> Cli.Option.validateMap effectTypesValidation
81+
|> Cli.Option.withDisplayName "pkg1.type1,..."
7882
|> Cli.Option.withDescription
7983
([ "A list of which kind of APIs to generate."
8084
, "Each item should be of the form `package.type`."
@@ -103,79 +107,71 @@ program =
103107
|> Cli.OptionsParser.with
104108
(Cli.Option.optionalKeywordArg "server"
105109
|> Cli.Option.validateMap serverValidation
110+
|> Cli.Option.withDisplayName "https://example.com"
106111
|> Cli.Option.withDescription
107112
([ "The base URL for the OpenAPI server."
108-
, "If not specified this will be extracted from the OAS"
109-
, "or default to root of the web application."
113+
, "If not specified this will be extracted from the OAS or default to root of the web application."
110114
, ""
111115
, "You can pass in an object to define multiple servers, like"
112116
, """ {"dev": "http://localhost", "prod": "https://example.com"}."""
113117
, ""
114-
, "This will add a `server` parameter to functions and define"
115-
, "a `Servers` module with your servers. You can pass in an"
116-
, "empty object if you have fully dynamic servers."
118+
, "This will add a `server` parameter to functions and define a `Servers` module with your servers. You can pass in an empty object if you have fully dynamic servers."
117119
]
118120
|> formatOptionDescription
119121
)
120122
)
121123
|> Cli.OptionsParser.with
122124
(Cli.Option.optionalKeywordArg "auto-convert-swagger"
123-
|> Cli.Option.validateMap autoConvertValidation
125+
|> Cli.Option.withDefault "ask"
126+
|> Cli.Option.oneOf
127+
[ ( "ask", OpenApi.Config.AskBeforeConversion )
128+
, ( "never", OpenApi.Config.NeverConvert )
129+
, ( "always", OpenApi.Config.AlwaysConvert )
130+
]
124131
|> Cli.Option.withDescription
125-
([ "\"ask\" If a Swagger doc is encountered, ask the user before converting"
126-
, "it to an Open API file. This is the default."
127-
, "\"never\" If a Swagger doc is encountered, error out."
128-
, "\"always\" If a Swagger doc is encountered, automatically convert it"
129-
, "to an Open API file."
132+
([ "- \"ask\" If a Swagger doc is encountered, ask the user before converting it to an Open API file. This is the default."
133+
, "- \"never\" If a Swagger doc is encountered, error out."
134+
, "- \"always\" If a Swagger doc is encountered, automatically convert it to an Open API file."
130135
]
131136
|> formatOptionDescription
132137
)
133138
)
134139
|> Cli.OptionsParser.with
135140
(Cli.Option.optionalKeywordArg "swagger-conversion-url"
141+
|> Cli.Option.withDisplayName "url"
136142
|> Cli.Option.withDescription
137-
([ "The URL to use to convert a Swagger doc to an Open API"
138-
, "file. Defaults to `https://converter.swagger.io/api/convert`."
143+
([ "The URL to use to convert a Swagger doc to an Open API file."
144+
, "Defaults to `https://converter.swagger.io/api/convert`."
139145
]
140146
|> formatOptionDescription
141147
)
142148
)
143149
|> Cli.OptionsParser.with
144150
(Cli.Option.optionalKeywordArg "swagger-conversion-command"
151+
|> Cli.Option.withDisplayName "cmd"
145152
|> Cli.Option.withDescription
146-
([ "Instead of making an HTTP request to convert"
147-
, "from Swagger to Open API, use this command."
148-
]
149-
|> formatOptionDescription
150-
)
153+
"Instead of making an HTTP request to convert from Swagger to Open API, use this command."
151154
)
152155
|> Cli.OptionsParser.with
153156
(Cli.Option.keywordArgList "swagger-conversion-command-args"
157+
|> Cli.Option.withDisplayName "args"
154158
|> Cli.Option.withDescription
155-
([ "Additional arguments to pass to the Swagger conversion command,"
156-
, "before the contents of the Swagger file are passed in."
157-
]
158-
|> formatOptionDescription
159-
)
159+
"Additional arguments to pass to the Swagger conversion command, before the contents of the Swagger file are passed in."
160160
)
161161
|> Cli.OptionsParser.with
162162
(Cli.Option.flag "generateTodos"
163163
|> Cli.Option.withDescription
164-
([ "Whether to generate TODOs for unimplemented endpoints,"
165-
, "or fail when something unexpected is encountered."
166-
, "Defaults to `no`. To generate `Debug.todo \"\"`"
167-
, "instead of failing use one of: `yes`, `y`, `true`."
168-
]
169-
|> formatOptionDescription
170-
)
164+
"Whether to generate `Debug.todo \"\"` instead of failing for unimplemented features."
171165
)
172166
|> Cli.OptionsParser.with
173167
(Cli.Option.keywordArgList "overrides"
168+
|> Cli.Option.withDisplayName "override.json|yaml"
174169
|> Cli.Option.map (List.map OpenApi.Config.pathFromString)
175170
|> Cli.Option.withDescription "Load an additional file to override parts of the original Open API file."
176171
)
177172
|> Cli.OptionsParser.with
178173
(Cli.Option.optionalKeywordArg "write-merged-to"
174+
|> Cli.Option.withDisplayName "dir"
179175
|> Cli.Option.withDescription "Write the merged Open API spec to the given file."
180176
)
181177
|> Cli.OptionsParser.with
@@ -206,28 +202,6 @@ formatOptionDescription descriptionLines =
206202
|> String.join "\n"
207203

208204

209-
autoConvertValidation : Maybe String -> Result String OpenApi.Config.AutoConvertSwagger
210-
autoConvertValidation input =
211-
case input of
212-
Nothing ->
213-
Ok OpenApi.Config.AskBeforeConversion
214-
215-
Just "ask" ->
216-
Ok OpenApi.Config.AskBeforeConversion
217-
218-
Just "" ->
219-
Ok OpenApi.Config.AlwaysConvert
220-
221-
Just "always" ->
222-
Ok OpenApi.Config.AlwaysConvert
223-
224-
Just "never" ->
225-
Ok OpenApi.Config.NeverConvert
226-
227-
Just value ->
228-
Err ("Unexpected value for auto-convert-swagger: " ++ value)
229-
230-
231205
effectTypesValidation : Maybe String -> Result String (List OpenApi.Config.EffectType)
232206
effectTypesValidation str =
233207
case str of

0 commit comments

Comments
 (0)