Browse Source

add validation to CLI and try-with block to add-grid.

Make minor spelling and editing fixes to errr
or messages.
master
Craig Oates 6 years ago
parent
commit
3275bac236
  1. 5
      DeathSocket/GridPainter.fs
  2. 28
      DeathSocketCLI/Commands.fs
  3. 1
      DeathSocketCLI/DeathSocketCLI.fsproj
  4. 41
      DeathSocketCLI/Validation.fs

5
DeathSocket/GridPainter.fs

@ -13,6 +13,5 @@ namespace DeathSocket
validateFilePath |> ignore
drawGrid spec |> ignore
with
| :? FileNotFoundException as ex -> printfn"%s" ex.Message
}
| :? FileNotFoundException as ex -> printfn "File could not be found at %s" ex.Message
}

28
DeathSocketCLI/Commands.fs

@ -1,17 +1,23 @@
namespace Commands
module ConsoleCommands =
open DeathSocket
open System.Drawing
open System
open DeathSocket.GridPainter
open Validation
open System.IO
let showEndOfCommandMessage = "[INFO.] Execution completed."
let test () = "Death Socket is working."
let ``add-grid`` imgPath numRows numColumns pWidth (colour: string) newPath =
let spec =
{ originalPath = imgPath
savePath = newPath
colour = Brushes.Red
penWidth = pWidth
rows = numRows
columns = numColumns }
GridPainter.applyGrid spec |> Async.RunSynchronously
let ``add-grid`` imgPath numRows numColumns pWidth colour newPath =
try
printfn "[INFO.] Adding grid to image..."
buildSpec imgPath numRows numColumns pWidth colour newPath
|> applyGrid
|> Async.RunSynchronously
showEndOfCommandMessage
with
| :? FileNotFoundException as ex -> "[ERROR] No file was found at " + ex.FileName
| :? ArgumentException as ex -> "[ERROR] Invalid argument: " + ex.Message
| _ as ex -> ex.Message

1
DeathSocketCLI/DeathSocketCLI.fsproj

@ -46,6 +46,7 @@
<Import Project="$(FSharpTargetsPath)" />
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Validation.fs" />
<Compile Include="Commands.fs" />
<Compile Include="Program.fs" />
<None Include="App.config" />

41
DeathSocketCLI/Validation.fs

@ -0,0 +1,41 @@
module Validation
open DeathSocket
open System.Drawing
open System
let colourList =
[ "blue", Brushes.AliceBlue
"brown", Brushes.Brown
"black", Brushes.Black
"gray", Brushes.Gray
"green", Brushes.Green
"purple", Brushes.Purple
"red", Brushes.Red
"white", Brushes.White
"yellow", Brushes.Yellow ]
|> Map.ofList
let isColourValid (colour: string) =
colourList
|> Map.containsKey (colour.ToLower())
let parseColour colour =
match (isColourValid colour) with
| true ->
colourList
|> Map.find (colour.ToLower())
| false ->
invalidArg "Colour"
(String.Concat("The colour specifed is invalid.\n",
"Please use the 'list-colours' command to see what you can use."))
let buildSpec imgPath numRows numColumns pWidth colour newPath =
let spec =
{ originalPath = imgPath
savePath = newPath
colour = parseColour colour
penWidth = pWidth
rows = numRows
columns = numColumns }
spec
Loading…
Cancel
Save