-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.fs
executable file
·42 lines (32 loc) · 1.32 KB
/
Program.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module ExtDriver.Program
open CommandLine
open ExtDriver.Handlers
open Spectre.Console
[<Verb("mount", aliases = [| "m" |], HelpText = "Mount external drive.")>]
type MountArguments() =
inherit BaseMountArguments()
[<Verb("unmount", aliases = [| "u"; "un" |], HelpText = "Unmount external drive.")>]
type UnmountArguments() =
inherit BaseMountArguments()
[<Verb("list", isDefault = true, aliases = [| "l"; "ls" |], HelpText = "list all external drives.")>]
type ListArguments() =
[<Option('s', "simple", HelpText = "Output in simple format (no decorations).")>]
member val Simple = false with get, set
[<EntryPoint>]
let main args =
let parsedArgs =
Parser.Default.ParseArguments<ListArguments, MountArguments, UnmountArguments> args
let result =
match parsedArgs with
| :? Parsed<obj> as cmd ->
match cmd.Value with
| :? ListArguments as args -> printDrives (if args.Simple then Simple else Decorated)
| :? MountArguments as args -> driveAction Mount args
| :? UnmountArguments as args -> driveAction Unmount args
| _ -> Result.Error "Unexpected verb encountered"
| _ -> Result.Error "Could not parse cli arguments"
match result with
| Error e ->
AnsiConsole.MarkupLine $"[red]{e}[/]"
1
| Ok _ -> 0