-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateDay.fsx
More file actions
50 lines (39 loc) · 1.32 KB
/
CreateDay.fsx
File metadata and controls
50 lines (39 loc) · 1.32 KB
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
43
44
45
46
47
48
49
50
open System
open System.IO
let getArguments (args: string array) =
if args.Length > 1 then args[1..] else [||]
let args = fsi.CommandLineArgs |> getArguments
// Check if the correct number of arguments are provided
if args.Length <> 1 then
printfn "Usage: fsi CreateDay.fsx <DayNum>"
else
let dayName = $"Day{args[0]}"
let dayPath = $"{dayName}.fs"
if File.Exists(dayPath) then
printfn "Day already exists. Exiting"
Environment.Exit(1)
// Create input directory
let inputDirectory = $"Inputs/{dayName}"
Directory.CreateDirectory(inputDirectory) |> ignore
// Create stub files
File.Create($"{inputDirectory}/test.txt").Dispose()
File.Create($"{inputDirectory}/input.txt").Dispose()
let content =
$"""module {dayName}
module Tests =
open Xunit
[<Theory>]
[<InlineData("{inputDirectory}/test.txt", -1)>]
[<InlineData("{inputDirectory}/input.txt", -1)>]
let ``Part 1`` (filename: string, expected: int) =
let result = 0
Assert.Equal(expected, result)
[<Theory>]
[<InlineData("{inputDirectory}/test.txt", -1)>]
[<InlineData("{inputDirectory}/input.txt", -1)>]
let ``Part 2`` (filename: string, expected: int) =
let result = 0
Assert.Equal(expected, result)"""
use writer = new StreamWriter(dayPath)
writer.WriteLine(content)
printfn $"'{dayName}' created successfully"