Skip to content

Commit 30e7014

Browse files
authored
Add nimble guide (#1318)
* (add) `guide`/`manual` command This command opens up the Nimble guide (https://nim-lang.github.io/nimble/index.html) in the user's preferred web browser. Related to #1272 * (add) show reference to `nimble guide` on error This allows new users to check how to use Nimble. * (add) show `nimble guide` in help message
1 parent 5a5e2a4 commit 30e7014

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/nimble.nim

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) Dominik Picheta. All rights reserved.
22
# BSD License. Look at license.txt for more info.
33

4-
import os, tables, strtabs, json, algorithm, sets, uri, sugar, sequtils, osproc,
4+
import os, tables, strtabs, json, browsers, algorithm, sets, uri, sugar, sequtils, osproc,
55
strformat
66

77
import std/options as std_opt
@@ -2276,6 +2276,14 @@ proc run(options: Options) =
22762276
let exitCode = cmd.execCmd
22772277
raise nimbleQuit(exitCode)
22782278

2279+
proc openNimbleManual =
2280+
const NimbleGuideURL = "https://nim-lang.github.io/nimble/index.html"
2281+
display(
2282+
"Opened", "the Nimble guide in your default browser."
2283+
)
2284+
displayInfo("If it did not open, you can try going to the link manually: " & NimbleGuideURL)
2285+
openDefaultBrowser(NimbleGuideURL)
2286+
22792287
proc doAction(options: var Options) =
22802288
if options.showHelp:
22812289
writeHelp()
@@ -2348,6 +2356,8 @@ proc doAction(options: var Options) =
23482356
assert false
23492357
of actionAdd:
23502358
addPackages(options.action.packages, options)
2359+
of actionManual:
2360+
openNimbleManual()
23512361
of actionCustom:
23522362
var optsCopy = options
23532363
optsCopy.task = options.action.command.normalize
@@ -2374,7 +2384,9 @@ proc doAction(options: var Options) =
23742384
raise nimbleError(msg = "Could not find task $1 in $2" %
23752385
[options.action.command, nimbleFile],
23762386
hint = "Run `nimble --help` and/or `nimble tasks` for" &
2377-
" a list of possible commands.")
2387+
" a list of possible commands." & '\n' &
2388+
"If you want a tutorial on how to use Nimble, run `nimble guide`."
2389+
)
23782390

23792391
proc setNimBin*(options: var Options) =
23802392
# Find nim binary and set into options

src/nimblepkg/options.nim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type
7070
actionInstall, actionSearch, actionList, actionBuild, actionPath,
7171
actionUninstall, actionCompile, actionDoc, actionCustom, actionTasks,
7272
actionDevelop, actionCheck, actionLock, actionRun, actionSync, actionSetup,
73-
actionClean, actionDeps, actionShellEnv, actionShell, actionAdd
73+
actionClean, actionDeps, actionShellEnv, actionShell, actionAdd, actionManual
7474

7575
DevelopActionType* = enum
7676
datAdd, datRemoveByPath, datRemoveByName, datInclude, datExclude
@@ -80,7 +80,7 @@ type
8080
Action* = object
8181
case typ*: ActionType
8282
of actionNil, actionList, actionPublish, actionTasks, actionCheck,
83-
actionSetup, actionClean: nil
83+
actionSetup, actionClean, actionManual: nil
8484
of actionSync:
8585
listOnly*: bool
8686
of actionRefresh:
@@ -173,6 +173,7 @@ Commands:
173173
build [opts, ...] [bin] Builds a package. Passes options to the Nim
174174
compiler.
175175
clean Clean build artifacts.
176+
guide Open the Nimble User Guide in your preferred browser.
176177
add Adds packages to your project's dependencies.
177178
run [opts, ...] [bin] Builds and runs a package.
178179
Binary needs to be specified after any
@@ -339,6 +340,8 @@ proc parseActionType*(action: string): ActionType =
339340
result = actionShell
340341
of "add":
341342
result = actionAdd
343+
of "manual", "guide":
344+
result = actionManual
342345
else:
343346
result = actionCustom
344347

@@ -918,4 +921,4 @@ proc isSubdirOf*(subdir, baseDir: string): bool =
918921
when defined(windows):
919922
normalizedSubdir.toLower.startsWith(normalizedBaseDir.toLower)
920923
else:
921-
normalizedSubdir.startsWith(normalizedBaseDir)
924+
normalizedSubdir.startsWith(normalizedBaseDir)

0 commit comments

Comments
 (0)