mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-30 03:11:30 +03:00
Extract helper for module name CLI options parsing.
This commit is contained in:
parent
da132b13f3
commit
5aeade0daf
@ -5,7 +5,6 @@ import BackendTask
|
||||
import Cli.Option as Option
|
||||
import Cli.OptionsParser as OptionsParser
|
||||
import Cli.Program as Program
|
||||
import Cli.Validate
|
||||
import Elm
|
||||
import Elm.Annotation
|
||||
import Elm.Case
|
||||
@ -58,19 +57,11 @@ program =
|
||||
Program.config
|
||||
|> Program.add
|
||||
(OptionsParser.build CliOptions
|
||||
|> OptionsParser.with
|
||||
(Option.requiredPositionalArg "module"
|
||||
|> Option.validate (Cli.Validate.regex moduleNameRegex)
|
||||
)
|
||||
|> OptionsParser.with (Option.requiredPositionalArg "module" |> Pages.Generate.moduleNameCliArg)
|
||||
|> OptionsParser.withRestArgs AddFormHelp.restArgsParser
|
||||
)
|
||||
|
||||
|
||||
moduleNameRegex : String
|
||||
moduleNameRegex =
|
||||
"^[A-Z][a-zA-Z0-9_]*(\\.([A-Z][a-zA-Z0-9_]*))*$"
|
||||
|
||||
|
||||
createFile : List String -> List ( String, AddFormHelp.Kind ) -> Elm.File
|
||||
createFile moduleName fields =
|
||||
let
|
||||
|
@ -4,6 +4,7 @@ module Pages.Generate exposing
|
||||
, serverRender
|
||||
, preRender, single
|
||||
, addDeclarations
|
||||
, moduleNameCliArg
|
||||
)
|
||||
|
||||
{-| This module provides some functions for scaffolding code for a new Route Module. It uses [`elm-codegen`'s API](https://package.elm-lang.org/packages/mdgriffith/elm-codegen/latest/) for generating code.
|
||||
@ -33,14 +34,33 @@ Learn more about [the `elm-pages run` CLI command in its docs page](https://elm-
|
||||
|
||||
@docs addDeclarations
|
||||
|
||||
|
||||
## CLI Options Parsing Helpers
|
||||
|
||||
@docs moduleNameCliArg
|
||||
|
||||
-}
|
||||
|
||||
import Cli.Option as Option
|
||||
import Cli.Validate
|
||||
import Elm
|
||||
import Elm.Annotation
|
||||
import Elm.Declare
|
||||
import Pages.Internal.RoutePattern as RoutePattern
|
||||
|
||||
|
||||
{-| A positional argument for elm-cli-options-parser that does a Regex validation to check that the module name is a valid Elm Route module name.
|
||||
-}
|
||||
moduleNameCliArg : Option.Option from String builderState -> Option.Option from String builderState
|
||||
moduleNameCliArg =
|
||||
Option.validate (Cli.Validate.regex moduleNameRegex)
|
||||
|
||||
|
||||
moduleNameRegex : String
|
||||
moduleNameRegex =
|
||||
"^[A-Z][a-zA-Z0-9_]*(\\.([A-Z][a-zA-Z0-9_]*))*$"
|
||||
|
||||
|
||||
{-| -}
|
||||
type Type
|
||||
= Alias Elm.Annotation.Annotation
|
||||
|
Loading…
Reference in New Issue
Block a user