-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmake.sml
59 lines (47 loc) · 1.43 KB
/
smake.sml
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
51
52
53
54
55
56
57
58
59
(* A simple project-scaffolding tool for SML *)
(*
This will make a program with the following structure:
project/ ← the root folder
project/README.md ← a readme file
project/src/ ← the folder containing the source code
project.sml ← a file which will `use' the actual src files and serve as a compiler target
*)
structure Smake = struct
fun printNF s = TextIO.output (TextIO.stdOut, s)
fun callForHelp () =
(printNF "Usage:\n";
printNF " smake new <name> => creates a new project in dir `name'\n";
TextIO.flushOut TextIO.stdOut)
fun printToFile file text =
let
val strm = TextIO.openOut file
fun defer () = TextIO.closeOut strm
in
(TextIO.output (strm, text);
TextIO.flushOut strm;
defer ())
end
fun new name =
let
open OS.FileSys
fun subDir (p, c) = p ^ "/" ^ c
val this = subDir (getDir (), name)
val rmString = "# " ^ name ^ "\n"
in
(mkDir this;
mkDir (subDir (this, "src"));
printToFile (subDir (this, "README.md")) rmString;
printToFile (subDir (this, name ^ ".sml")) "")
end
fun crash s =
(printNF "Error: ";
printNF s;
printNF "\n";
TextIO.flushOut TextIO.stdOut;
callForHelp ())
fun dispatch () =
case CommandLine.arguments () of
"new"::name::trash => new name
| trash => crash "Unknown arguments!"
end
fun main () = Smake.dispatch ()