Browse Source

add help attributes to command-methods.

Set pen pen width programmatically when building  the default spec in CLI.
master
Craig Oates 6 years ago
parent
commit
b2a27353d5
  1. 31
      DeathSocketCLI/Commands.fs
  2. 26
      DeathSocketCLI/Validation.fs

31
DeathSocketCLI/Commands.fs

@ -6,15 +6,34 @@
open Validation
open System.IO
open Console.Waterworks
open Console.Waterworks.Attributes
let showEndOfCommandMessage = "[INFO.] Task completed."
[<ListCommand>]
[<Parameters "none">]
[<Description
"Display a text message indicating this program is running properly.">]
[<Usage "test">]
let test () = "[SUCCESS] Death Socket is working."
[<ListCommand>]
[<Parameters "none">]
[<Description "Displays a list of available commands provided by this program.">]
[<Usage "help">]
let help () = CW_Liaison().RequestHelpDocumentation("Commands")
[<ListCommand>]
[<Parameters "none">]
[<Description "Exits out of the program.">]
[<Usage "exit">]
let exit () = Environment.Exit (Environment.ExitCode)
[<ListCommand>]
[<Parameters "(image-path: string) (new-path: string)">]
[<Description
"Takes the image at 'image-path' applies a 10x10 grid (in white) to it and saves the result at 'new-path'.">]
[<Usage "add-default C:/base-image.png C:/final-image.png">]
let ``add-default`` imgPath newPath =
try
printfn "[INFO.] Adding default grid to image..."
@ -27,6 +46,13 @@
| :? ArgumentException as ex -> "[ERROR] Invalid argument: " + ex.Message
| _ as ex -> ex.Message
[<ListCommand>]
[<Parameters
("(image-path: string) (no-of-rows: int) (no-of-columns: int) " +
"(pen-width: float32) (colour: string) (new-path: string)")>]
[<Description "Adds a grid to an image, using the specified parameters, and saves it.">]
[<Usage
"add-grid C:/orignal-image.png 10 5 2 red C:/new-image.png">]
let ``add-grid`` imgPath numRows numColumns pWidth colour newPath =
try
printfn "[INFO.] Adding grid to image..."
@ -39,6 +65,11 @@
| :? ArgumentException as ex -> "[ERROR] Invalid argument: " + ex.Message
| _ as ex -> ex.Message
[<ListCommand>]
[<Parameters "none">]
[<Description
"Lists out the colours this program uses to draw its grids.">]
[<Usage "list-colours">]
let ``list-colours`` () =
printfn "[INFO.] Listing available colours..."
for item in colourList do

26
DeathSocketCLI/Validation.fs

@ -3,6 +3,7 @@
open DeathSocket
open System.Drawing
open System
open System.IO
let colourList =
[ "blue", Brushes.AliceBlue
@ -30,6 +31,13 @@
(String.Concat("The colour specifed is invalid.\n",
"Please use the 'list-colours' command to see what you can use."))
let setPenWidth imgWidth imgHeight =
let width = float32 imgWidth
let height = float32 imgHeight
if (width >= height) then
height * (float32 0.01)
else width * (float32 0.01)
let buildSpec imgPath numRows numColumns pWidth colour newPath =
{ originalPath = imgPath
savePath = newPath
@ -39,9 +47,15 @@
columns = numColumns }
let buildDefaultSpec imgPath newPath =
{ originalPath = imgPath
savePath = newPath
colour = Brushes.White
penWidth = float32 (2)
rows = 10
columns = 10 }
let stream = new FileStream (imgPath, FileMode.Open)
let image = Image.FromStream (stream, false, false)
let spec =
{ originalPath = imgPath
savePath = newPath
colour = Brushes.White
penWidth = setPenWidth (image.Width) (image.Height)
rows = 10
columns = 10 }
stream.Dispose ()
image.Dispose ()
spec
Loading…
Cancel
Save