mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-24 20:31:42 +03:00
Do fuzzy search suggestion for missing secret.
This commit is contained in:
parent
d3a61d5146
commit
7d14d8de88
3
elm.json
3
elm.json
@ -32,7 +32,8 @@
|
||||
"lukewestby/elm-string-interpolate": "1.0.4 <= v < 2.0.0",
|
||||
"mdgriffith/elm-markup": "3.0.1 <= v < 4.0.0",
|
||||
"miniBill/elm-codec": "1.2.0 <= v < 2.0.0",
|
||||
"noahzgordon/elm-color-extra": "1.0.2 <= v < 2.0.0"
|
||||
"noahzgordon/elm-color-extra": "1.0.2 <= v < 2.0.0",
|
||||
"tripokey/elm-fuzzy": "5.2.1 <= v < 6.0.0"
|
||||
},
|
||||
"test-dependencies": {
|
||||
"avh4/elm-program-test": "3.1.0 <= v < 4.0.0",
|
||||
|
@ -30,7 +30,8 @@
|
||||
"mdgriffith/elm-ui": "1.1.5",
|
||||
"miniBill/elm-codec": "1.2.0",
|
||||
"noahzgordon/elm-color-extra": "1.0.2",
|
||||
"rtfeldman/elm-hex": "1.0.0"
|
||||
"rtfeldman/elm-hex": "1.0.0",
|
||||
"tripokey/elm-fuzzy": "5.2.1"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/bytes": "1.0.8",
|
||||
|
@ -2,6 +2,7 @@ module Secrets exposing (..)
|
||||
|
||||
import BuildError exposing (BuildError)
|
||||
import Dict exposing (Dict)
|
||||
import Fuzzy
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import TerminalText as Terminal
|
||||
|
||||
@ -51,13 +52,22 @@ buildError secretName availableEnvironmentVariables =
|
||||
[ Terminal.text "I expected to find this Secret in your environment variables but didn't find a match:\nSecrets.get \""
|
||||
, Terminal.red (Terminal.text secretName)
|
||||
, Terminal.text "\"\n\n"
|
||||
|
||||
-- , Terminal.text "Maybe you meant one of:\n"
|
||||
-- , Terminal.text (String.join ", " availableEnvironmentVariables)
|
||||
, Terminal.text "So maybe "
|
||||
, Terminal.yellow <| Terminal.text (sortMatches secretName availableEnvironmentVariables |> List.head |> Maybe.withDefault "")
|
||||
, Terminal.text " should be "
|
||||
, Terminal.green <| Terminal.text secretName
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
sortMatches missingSecret availableSecrets =
|
||||
let
|
||||
simpleMatch config separators needle hay =
|
||||
Fuzzy.match config separators needle hay |> .score
|
||||
in
|
||||
List.sortBy (simpleMatch [] [] missingSecret) availableSecrets
|
||||
|
||||
|
||||
decoder : Decoder Secrets
|
||||
decoder =
|
||||
Decode.dict Decode.string
|
||||
|
@ -9,6 +9,8 @@ type Text
|
||||
type Color
|
||||
= Red
|
||||
| Blue
|
||||
| Green
|
||||
| Yellow
|
||||
|
||||
|
||||
text : String -> Text
|
||||
@ -16,6 +18,16 @@ text value =
|
||||
RawText value
|
||||
|
||||
|
||||
green : Text -> Text
|
||||
green inner =
|
||||
Style (colorToString Green) inner
|
||||
|
||||
|
||||
yellow : Text -> Text
|
||||
yellow inner =
|
||||
Style (colorToString Yellow) inner
|
||||
|
||||
|
||||
red : Text -> Text
|
||||
red inner =
|
||||
Style (colorToString Red) inner
|
||||
@ -49,6 +61,12 @@ colorToString color =
|
||||
Blue ->
|
||||
"[34m"
|
||||
|
||||
Green ->
|
||||
"[32;1m"
|
||||
|
||||
Yellow ->
|
||||
"[33;1m"
|
||||
|
||||
|
||||
toString : List Text -> String
|
||||
toString list =
|
||||
|
Loading…
Reference in New Issue
Block a user