Skip to content

Commit a7c5a58

Browse files
committed
Better help message
1 parent 90df166 commit a7c5a58

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
@@ -61,21 +61,25 @@ program =
6161
|> Cli.Program.add
6262
(Cli.OptionsParser.build CliOptions
6363
|> Cli.OptionsParser.with
64-
(Cli.Option.requiredPositionalArg "entryFilePath"
64+
(Cli.Option.requiredPositionalArg "input-file"
65+
|> Cli.Option.withDisplayName "file.json|file.yaml"
6566
|> Cli.Option.map OpenApi.Config.pathFromString
6667
)
6768
|> Cli.OptionsParser.with
6869
(Cli.Option.optionalKeywordArg "output-dir"
6970
|> Cli.Option.withDefault "generated"
71+
|> Cli.Option.withDisplayName "dir"
7072
|> Cli.Option.withDescription "The directory to output to. Defaults to `generated/`."
7173
)
7274
|> Cli.OptionsParser.with
7375
(Cli.Option.optionalKeywordArg "module-name"
76+
|> Cli.Option.withDisplayName "Elm.Module.Name"
7477
|> Cli.Option.withDescription "The Elm module name. Defaults to `OAS info.title`."
7578
)
7679
|> Cli.OptionsParser.with
7780
(Cli.Option.optionalKeywordArg "effect-types"
7881
|> Cli.Option.validateMap effectTypesValidation
82+
|> Cli.Option.withDisplayName "pkg1.type1,..."
7983
|> Cli.Option.withDescription
8084
([ "A list of which kind of APIs to generate."
8185
, "Each item should be of the form `package.type`."
@@ -104,79 +108,71 @@ program =
104108
|> Cli.OptionsParser.with
105109
(Cli.Option.optionalKeywordArg "server"
106110
|> Cli.Option.validateMap serverValidation
111+
|> Cli.Option.withDisplayName "https://example.com"
107112
|> Cli.Option.withDescription
108113
([ "The base URL for the OpenAPI server."
109-
, "If not specified this will be extracted from the OAS"
110-
, "or default to root of the web application."
114+
, "If not specified this will be extracted from the OAS or default to root of the web application."
111115
, ""
112116
, "You can pass in an object to define multiple servers, like"
113117
, """ {"dev": "http://localhost", "prod": "https://example.com"}."""
114118
, ""
115-
, "This will add a `server` parameter to functions and define"
116-
, "a `Servers` module with your servers. You can pass in an"
117-
, "empty object if you have fully dynamic servers."
119+
, "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."
118120
]
119121
|> formatOptionDescription
120122
)
121123
)
122124
|> Cli.OptionsParser.with
123125
(Cli.Option.optionalKeywordArg "auto-convert-swagger"
124-
|> Cli.Option.validateMap autoConvertValidation
126+
|> Cli.Option.withDefault "ask"
127+
|> Cli.Option.oneOf
128+
[ ( "ask", OpenApi.Config.AskBeforeConversion )
129+
, ( "never", OpenApi.Config.NeverConvert )
130+
, ( "always", OpenApi.Config.AlwaysConvert )
131+
]
125132
|> Cli.Option.withDescription
126-
([ "\"ask\" If a Swagger doc is encountered, ask the user before converting"
127-
, "it to an Open API file. This is the default."
128-
, "\"never\" If a Swagger doc is encountered, error out."
129-
, "\"always\" If a Swagger doc is encountered, automatically convert it"
130-
, "to an Open API file."
133+
([ "- \"ask\" If a Swagger doc is encountered, ask the user before converting it to an Open API file. This is the default."
134+
, "- \"never\" If a Swagger doc is encountered, error out."
135+
, "- \"always\" If a Swagger doc is encountered, automatically convert it to an Open API file."
131136
]
132137
|> formatOptionDescription
133138
)
134139
)
135140
|> Cli.OptionsParser.with
136141
(Cli.Option.optionalKeywordArg "swagger-conversion-url"
142+
|> Cli.Option.withDisplayName "url"
137143
|> Cli.Option.withDescription
138-
([ "The URL to use to convert a Swagger doc to an Open API"
139-
, "file. Defaults to `https://converter.swagger.io/api/convert`."
144+
([ "The URL to use to convert a Swagger doc to an Open API file."
145+
, "Defaults to `https://converter.swagger.io/api/convert`."
140146
]
141147
|> formatOptionDescription
142148
)
143149
)
144150
|> Cli.OptionsParser.with
145151
(Cli.Option.optionalKeywordArg "swagger-conversion-command"
152+
|> Cli.Option.withDisplayName "cmd"
146153
|> Cli.Option.withDescription
147-
([ "Instead of making an HTTP request to convert"
148-
, "from Swagger to Open API, use this command."
149-
]
150-
|> formatOptionDescription
151-
)
154+
"Instead of making an HTTP request to convert from Swagger to Open API, use this command."
152155
)
153156
|> Cli.OptionsParser.with
154157
(Cli.Option.keywordArgList "swagger-conversion-command-args"
158+
|> Cli.Option.withDisplayName "args"
155159
|> Cli.Option.withDescription
156-
([ "Additional arguments to pass to the Swagger conversion command,"
157-
, "before the contents of the Swagger file are passed in."
158-
]
159-
|> formatOptionDescription
160-
)
160+
"Additional arguments to pass to the Swagger conversion command, before the contents of the Swagger file are passed in."
161161
)
162162
|> Cli.OptionsParser.with
163163
(Cli.Option.flag "generateTodos"
164164
|> Cli.Option.withDescription
165-
([ "Whether to generate TODOs for unimplemented endpoints,"
166-
, "or fail when something unexpected is encountered."
167-
, "Defaults to `no`. To generate `Debug.todo \"\"`"
168-
, "instead of failing use one of: `yes`, `y`, `true`."
169-
]
170-
|> formatOptionDescription
171-
)
165+
"Whether to generate `Debug.todo \"\"` instead of failing for unimplemented features."
172166
)
173167
|> Cli.OptionsParser.with
174168
(Cli.Option.keywordArgList "overrides"
169+
|> Cli.Option.withDisplayName "override.json|yaml"
175170
|> Cli.Option.map (List.map OpenApi.Config.pathFromString)
176171
|> Cli.Option.withDescription "Load an additional file to override parts of the original Open API file."
177172
)
178173
|> Cli.OptionsParser.with
179174
(Cli.Option.optionalKeywordArg "write-merged-to"
175+
|> Cli.Option.withDisplayName "dir"
180176
|> Cli.Option.withDescription "Write the merged Open API spec to the given file."
181177
)
182178
|> Cli.OptionsParser.with
@@ -211,28 +207,6 @@ formatOptionDescription descriptionLines =
211207
|> String.join "\n"
212208

213209

214-
autoConvertValidation : Maybe String -> Result String OpenApi.Config.AutoConvertSwagger
215-
autoConvertValidation input =
216-
case input of
217-
Nothing ->
218-
Ok OpenApi.Config.AskBeforeConversion
219-
220-
Just "ask" ->
221-
Ok OpenApi.Config.AskBeforeConversion
222-
223-
Just "" ->
224-
Ok OpenApi.Config.AlwaysConvert
225-
226-
Just "always" ->
227-
Ok OpenApi.Config.AlwaysConvert
228-
229-
Just "never" ->
230-
Ok OpenApi.Config.NeverConvert
231-
232-
Just value ->
233-
Err ("Unexpected value for auto-convert-swagger: " ++ value)
234-
235-
236210
effectTypesValidation : Maybe String -> Result String (List OpenApi.Config.EffectType)
237211
effectTypesValidation str =
238212
case str of

0 commit comments

Comments
 (0)