Skip to content
This repository has been archived by the owner on Sep 26, 2020. It is now read-only.

Commit

Permalink
Check validity of new project name and project directory. (#56)
Browse files Browse the repository at this point in the history
* Prompt with check

* Check for validity of new project path.

* Use IsNullOrWhiteSpace
  • Loading branch information
jindraivanek authored and Krzysztof-Cieslak committed Mar 16, 2017
1 parent 9f1c283 commit ac63b00
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/Forge.Core/Templates.fs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,27 @@ module Project =

let templates = GetList()

let pathCheck path =
let path' = directory </> path
try Path.GetFullPath path' |> ignore; isValidPath path' && not (String.IsNullOrWhiteSpace path)
with _ -> false

let projectName' =
match projectName with
| Some p -> p
| None -> prompt "Enter project name:"
| None ->
promptCheck
"Enter project name:"
pathCheck
(sprintf "\"%s\" is not a valid project name.")
let projectDir' =
match projectDir with
| Some p -> p
| None -> prompt "Enter project directory (relative to working directory):"
| None ->
promptCheck
"Enter project directory (relative to working directory):"
pathCheck
(sprintf "\"%s\" is not a valid directory name.")
let templateName' =
match templateName with
| Some p -> p
Expand All @@ -168,7 +181,11 @@ module Project =
let templateDir = templatesLocation </> templateName'
let gitignorePath = (templatesLocation </> ".vcsignore" </> ".gitignore")

if templates |> Seq.contains templateName' then
if pathCheck projectFolder |> not then
printfn "\"%s\" is not a valid project folder." projectFolder
elif templates |> Seq.contains templateName' |> not then
printfn "Wrong template name"
else
printfn "Generating project..."
copyDir projectFolder templateDir (fun _ -> true)
applicationNameToProjectName projectFolder projectName'
Expand Down Expand Up @@ -199,8 +216,6 @@ module Project =
let perms = FilePermissions.S_IRWXU ||| FilePermissions.S_IRGRP ||| FilePermissions.S_IROTH // 0x744
Syscall.chmod(buildSh, perms) |> ignore
printfn "Done!"
else
printfn "Wrong template name"

module File =
open System
Expand Down
9 changes: 9 additions & 0 deletions src/Forge.ProjectSystem/Prelude.fs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ let promptSelect2 text list =
Console.Write("> ")
Console.ReadLine () |> String.stripControls

let promptCheck text checkF wrongInputMessage =
let rec ask() =
let x = prompt text
if checkF x then x
else
printfn "%s" (wrongInputMessage x)
ask()

ask()

let inline mapOpt (opt:'a option) mapfn (x:'b) =
match opt with
Expand Down

0 comments on commit ac63b00

Please sign in to comment.