Death Socket consists of three projects. They are a .Net Standard 2.0 library, a console program and a Test Centre. The purpose of this repository is to provide a way for people to add grids to images. https://www.craigoates.net/Software/project/13
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
5.3 KiB

namespace Commands
module ConsoleCommands =
open System
open DeathSocket.GridPainter
open DeathSocketCLI.Validation
open System.IO
open Console.Waterworks
open Console.Waterworks.Attributes
open DeathSocket.Domain
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..."
Brush (buildDefaultSpec imgPath newPath)
|> applyGridToImageAsync
|> Async.Start
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
[<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..."
Brush (buildSpec imgPath numRows numColumns pWidth colour newPath)
|> applyGridToImageAsync
|> Async.Start
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
[<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
printfn "%s" item.Key
showEndOfCommandMessage
(* ALIASES
=======================================================================
These command-methods will not show up in the help section. Before
adding extra aliases, make sure the main version is as clear and
helpful to someone new to the program as possible. Aliases should be
treated as commands for experienced users and documented on the wiki,
hosted alongside the repository on GitHub.
URL: https://github.com/CraigOates/Death-Socket/wiki *)
let ad imgPath newPath = ``add-default`` imgPath newPath
let ag imgPath numRows numColumns pWidth colour newPath =
``add-grid`` imgPath numRows numColumns pWidth colour newPath
let lc () = ``list-colours`` ()
(* SkiaSharp Command-Methods -- NOT FOR MASS CONSUMPTION
=======================================================================
These command-methods will not show up in the help section. These
command-methods are here for testing purposes. They mimic the command-
methods above, apart from using SkiaSharp. So, including these command-
methods will create a sense of duplicated functionality. Seeing as you
are reading this, it is assumed you can understand it. If so, please
feel free to use them -- just keep their exposure to a minimum.*)
let ``list-skia-colours`` () =
printfn "[INFO.] Listing available SkiaSharp colours..."
for item in skiaColourList do
printfn "%s" item.Key
showEndOfCommandMessage
let``add-skia-grid`` imgPath numRows numColumns pWidth colour newPath =
printfn "[INFO.] Adding SkiaSharp grid to image..."
Skia (buildSkiaSpec imgPath numRows numColumns pWidth colour newPath)
|> applyGridToImageAsync
|> Async.Start
showEndOfCommandMessage
let``add-skia-rgb-grid`` imgPath numRows numColumns pWidth r g b newPath =
printfn "[INFO.] Adding SkiaSharp grid to image..."
SkiaRGB (buildSkiaRGBSpec imgPath numRows numColumns pWidth r g b newPath)
|> applyGridToImageAsync
|> Async.Start
showEndOfCommandMessage