Skip to content

Commit c2c5cdd

Browse files
committed
--docRoot now has smart default: best among @pkg, @path
1 parent 9ee60cf commit c2c5cdd

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

compiler/commands.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
414414
expectArg(conf, switch, arg, pass, info)
415415
conf.docSeeSrcUrl = arg
416416
of "docroot":
417-
expectArg(conf, switch, arg, pass, info)
418-
conf.docRoot = arg
417+
conf.docRoot = if arg.len == 0: "@default" else: arg
419418
of "mainmodule", "m":
420419
discard "allow for backwards compatibility, but don't do anything"
421420
of "define", "d":

compiler/docgen.nim

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,24 @@ proc presentationPath*(conf: ConfigRef, file: AbsoluteFile, isTitle = false): Re
5959
let file2 = $file
6060
template bail() =
6161
result = relativeTo(file, conf.projectPath)
62+
proc nimbleDir(): AbsoluteDir =
63+
getNimbleFile(conf, file2).parentDir.AbsoluteDir
6264
case conf.docRoot:
65+
of "@default": # using `@` instead of `$` to avoid shell quoting complications
66+
result = getRelativePathFromConfigPath(conf, file)
67+
let dir = nimbleDir()
68+
if not dir.isEmpty:
69+
let result2 = relativeTo(file, dir)
70+
if not result2.isEmpty and (result.isEmpty or result2.string.len < result.string.len):
71+
result = result2
72+
if result.isEmpty: bail()
6373
of "@pkg":
64-
let dir = getNimbleFile(conf, file2).parentDir.AbsoluteDir
74+
let dir = nimbleDir()
6575
if dir.isEmpty: bail()
6676
else: result = relativeTo(file, dir)
6777
of "@path":
6878
result = getRelativePathFromConfigPath(conf, file)
6979
if result.isEmpty: bail()
70-
# we could consider a @besteffort mode that would returned the "best" match among @pkg and @path
7180
elif conf.docRoot.len > 0:
7281
doAssert conf.docRoot.isAbsolute, conf.docRoot # or globalError
7382
doAssert conf.docRoot.existsDir, conf.docRoot

doc/advopt.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Advanced options:
7171
generates: docs/sub/main.html
7272
if path == @pkg, will use nimble file enclosing dir
7373
if path == @path, will use first matching dir in --path
74+
if path == @default (the default), will use best match among @pkg,@path
7475
if these are nonexistant, will use project path
7576
--docSeeSrcUrl:url activate 'see source' for doc and doc2 commands
7677
(see doc.item.seesrc in config/nimdoc.cfg)

tools/kochdocs.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ proc buildDoc(nimArgs, destPath: string) =
321321
for d in items(doc):
322322
var nimArgs2 = nimArgs
323323
if d.isRelativeTo("compiler"):
324-
nimArgs2.add " --docroot:@pkg"
324+
nimArgs2.add " --docroot"
325325
commands[i] = nim & " doc $# --git.url:$# --outdir:$# --index:on $#" %
326326
[nimArgs2, gitUrl, destPath, d]
327327
i.inc

0 commit comments

Comments
 (0)