Skip to content

Commit 9fa89d0

Browse files
committed
Remove workaround now that elm-pages handles no-tty scenarios
1 parent 0917c02 commit 9fa89d0

1 file changed

Lines changed: 9 additions & 59 deletions

File tree

‎cli/src/Cli.elm‎

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import Ansi
44
import Ansi.Color
55
import Ansi.Font
66
import BackendTask exposing (BackendTask)
7-
import BackendTask.Custom
8-
import BackendTask.Env
97
import BackendTask.Extra
108
import BackendTask.File
119
import BackendTask.Http
@@ -398,25 +396,16 @@ parseCliOptions cliOptions =
398396

399397

400398
type alias Step a =
401-
( Pages.Script.Spinner.Steps FatalError a
402-
, BackendTask FatalError a
403-
)
399+
Pages.Script.Spinner.Steps FatalError a
404400

405401

406402
withStep :
407403
String
408404
-> (a -> BackendTask FatalError b)
409405
-> Step a
410406
-> Step b
411-
withStep label toTask ( steps, task ) =
412-
( Pages.Script.Spinner.withStep label toTask steps
413-
, task
414-
|> BackendTask.andThen
415-
(\input ->
416-
Pages.Script.log label
417-
|> BackendTask.andThen (\() -> toTask input)
418-
)
419-
)
407+
withStep label toTask steps =
408+
Pages.Script.Spinner.withStep label toTask steps
420409

421410

422411
withInnerStep :
@@ -426,7 +415,7 @@ withInnerStep :
426415
-> (a -> BackendTask FatalError b)
427416
-> Step ( a, c, d )
428417
-> Step ( b, c, d )
429-
withInnerStep index total label toTask ( steps, task ) =
418+
withInnerStep index total label toTask steps =
430419
let
431420
fullLabel : String
432421
fullLabel =
@@ -436,16 +425,9 @@ withInnerStep index total label toTask ( steps, task ) =
436425
combinedTask ( input, acc1, acc2 ) =
437426
toTask input |> BackendTask.map (\result -> ( result, acc1, acc2 ))
438427
in
439-
( Pages.Script.Spinner.withStep fullLabel
428+
Pages.Script.Spinner.withStep fullLabel
440429
combinedTask
441430
steps
442-
, task
443-
|> BackendTask.andThen
444-
(\( input, acc1, acc2 ) ->
445-
Pages.Script.log fullLabel
446-
|> BackendTask.andThen (\() -> combinedTask ( input, acc1, acc2 ))
447-
)
448-
)
449431

450432

451433
withConfig : OpenApi.Config.Config -> BackendTask FatalError ()
@@ -527,10 +509,8 @@ withConfig config =
527509
)
528510
)
529511
( 1
530-
, ( Pages.Script.Spinner.steps
531-
|> Pages.Script.Spinner.withStep "Collecting configuration" (\_ -> BackendTask.succeed ( (), [], [] ))
532-
, Pages.Script.log "Collecting configuration" |> BackendTask.map (\() -> ( (), [], [] ))
533-
)
512+
, Pages.Script.Spinner.steps
513+
|> Pages.Script.Spinner.withStep "Collecting configuration" (\_ -> BackendTask.succeed ( (), [], [] ))
534514
)
535515
(OpenApi.Config.inputs config)
536516
|> Tuple.second
@@ -546,31 +526,11 @@ withConfig config =
546526
withStep "Format with elm-format" (onFirst attemptToFormat)
547527
)
548528
|> withStep "Write to disk" (onFirst (writeSdkToDisk (OpenApi.Config.outputDirectory config)))
549-
|> (\( steps, task ) ->
550-
terminalInfo
551-
|> BackendTask.andThen
552-
(\{ isTTY, noColor } ->
553-
if isTTY && not noColor then
554-
Pages.Script.Spinner.runSteps steps
555-
556-
else
557-
task
558-
)
559-
)
529+
|> Pages.Script.Spinner.runSteps
560530
|> BackendTask.map convertElmCodegenWarnings
561531
|> BackendTask.andThen printSuccessMessageAndWarnings
562532

563533

564-
terminalInfo : BackendTask FatalError { isTTY : Bool, noColor : Bool }
565-
terminalInfo =
566-
BackendTask.map2 (\isTTY noColor -> { isTTY = isTTY, noColor = noColor })
567-
(BackendTask.Custom.run "isTTY" Json.Encode.null Json.Decode.bool
568-
|> BackendTask.allowFatal
569-
|> BackendTask.quiet
570-
)
571-
(BackendTask.Env.get "NO_COLOR" |> BackendTask.map (\nc -> nc /= Nothing && nc /= Just ""))
572-
573-
574534
convertElmCodegenWarnings :
575535
( List ( String, List { declaration : String, warning : String } )
576536
, { warnings : List OpenApi.Generate.Message, requiredPackages : FastSet.Set String }
@@ -806,17 +766,7 @@ convertToSwaggerAndThenDecode config input value =
806766
parseOriginal input swagger
807767
|> BackendTask.andThen mergeOverrides
808768
)
809-
|> (\task ->
810-
terminalInfo
811-
|> BackendTask.andThen
812-
(\{ isTTY, noColor } ->
813-
if isTTY && not noColor then
814-
Pages.Script.Spinner.runTask "Convert Swagger to Open API" task
815-
816-
else
817-
task
818-
)
819-
)
769+
|> Pages.Script.Spinner.runTask "Convert Swagger to Open API"
820770
|> BackendTask.andThen (\converted -> decodeOpenApiSpecOrFail { hasAttemptedToConvertFromSwagger = True } config input converted)
821771

822772

0 commit comments

Comments
 (0)