Skip to content

Commit 3ae8911

Browse files
committed
add first basic implementation of the init command
1 parent 410c75d commit 3ae8911

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed

src/fsdocs-tool/InitCommand.fs

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,72 @@ open CommandLine
55

66
[<Verb("init", HelpText = "initialize the necessary folder structure and files for creating documentation with fsdocs.")>]
77
type InitCommand() =
8-
class
9-
end
8+
9+
let dir = Path.GetDirectoryName(typeof<InitCommand>.Assembly.Location)
10+
11+
// get template locations for in-package and in-repo and decide which to use later
12+
let inPackageLocations = Common.InPackageLocations(Path.Combine(dir, "..", "..", ".."))
13+
let inRepoLocations = Common.InRepoLocations(Path.Combine(dir, "..", "..", "..", "..", ".."))
14+
15+
[<Option("output",
16+
Required = false,
17+
Default = "docs",
18+
HelpText = "The output path for the documentation folder structure")>]
19+
member val output: string = "docs" with get, set
20+
21+
member this.Execute() =
22+
23+
let outputPath = Path.GetFullPath(this.output)
24+
let repoRoot = Path.GetFullPath(Path.Combine(outputPath, ".."))
25+
let initLocations = Common.InRepoLocations(repoRoot)
26+
27+
let ensureOutputDirs () =
28+
[ outputPath; initLocations.docs; initLocations.docs_img ]
29+
|> List.iter ensureDirectory
30+
31+
if inPackageLocations.Exist() then
32+
ensureOutputDirs ()
33+
34+
try
35+
[ (inPackageLocations.template_html, initLocations.template_html)
36+
(inPackageLocations.template_ipynb, initLocations.template_ipynb)
37+
(inPackageLocations.template_tex, initLocations.template_tex)
38+
(inPackageLocations.dockerfile, initLocations.dockerfile)
39+
(inPackageLocations.nuget_config, initLocations.nuget_config)
40+
(inPackageLocations.logo_template, Path.GetFullPath(Path.Combine(initLocations.docs_img, "logo.png")))
41+
(inPackageLocations.index_md_template, Path.GetFullPath(Path.Combine(initLocations.docs, "index.md")))
42+
(inPackageLocations.literate_sample_template,
43+
Path.GetFullPath(Path.Combine(initLocations.docs, "literate_sample.fsx"))) ]
44+
|> List.iter (fun (src, dst) -> File.Copy(src, dst, true))
45+
46+
0
47+
with e as exn ->
48+
printfn "Error: %s" exn.Message
49+
1
50+
51+
elif inRepoLocations.Exist() then
52+
ensureOutputDirs ()
53+
54+
try
55+
[ (inRepoLocations.template_html, initLocations.template_html)
56+
(inRepoLocations.template_ipynb, initLocations.template_ipynb)
57+
(inRepoLocations.template_tex, initLocations.template_tex)
58+
(inRepoLocations.dockerfile, initLocations.dockerfile)
59+
(inRepoLocations.nuget_config, initLocations.nuget_config)
60+
(inRepoLocations.logo_template, Path.GetFullPath(Path.Combine(initLocations.docs_img, "logo.png")))
61+
(inRepoLocations.index_md_template, Path.GetFullPath(Path.Combine(initLocations.docs, "index.md")))
62+
(inRepoLocations.literate_sample_template,
63+
Path.GetFullPath(Path.Combine(initLocations.docs, "literate_sample.fsx"))) ]
64+
|> List.iter (fun (src, dst) -> File.Copy(src, dst, true))
65+
66+
0
67+
with e as exn ->
68+
printfn "Error: %s" exn.Message
69+
1
70+
else
71+
printfn
72+
"no sources for default files found from either %s or %s"
73+
inPackageLocations.RelAssemblyPath
74+
inRepoLocations.RelAssemblyPath
75+
76+
1

src/fsdocs-tool/Program.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ do ()
88
[<EntryPoint>]
99
let main argv =
1010
CommandLine.Parser.Default
11-
.ParseArguments<BuildCommand, WatchCommand>(argv)
11+
.ParseArguments<BuildCommand, WatchCommand, InitCommand>(argv)
1212
.MapResult(
1313
(fun (opts: BuildCommand) -> opts.Execute()),
1414
(fun (opts: WatchCommand) -> opts.Execute()),
15+
(fun (opts: InitCommand) -> opts.Execute()),
1516
(fun _ -> 1)
1617
)

0 commit comments

Comments
 (0)