diff --git a/src/nimble.nim b/src/nimble.nim index 12c97aa5..639ccf77 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -1,7 +1,7 @@ # Copyright (C) Dominik Picheta. All rights reserved. # BSD License. Look at license.txt for more info. -import os, tables, strtabs, json, algorithm, sets, uri, sugar, sequtils, osproc, +import os, tables, strtabs, json, browsers, algorithm, sets, uri, sugar, sequtils, osproc, strformat import std/options as std_opt @@ -2276,6 +2276,14 @@ proc run(options: Options) = let exitCode = cmd.execCmd raise nimbleQuit(exitCode) +proc openNimbleManual = + const NimbleGuideURL = "https://nim-lang.github.io/nimble/index.html" + display( + "Opened", "the Nimble guide in your default browser." + ) + displayInfo("If it did not open, you can try going to the link manually: " & NimbleGuideURL) + openDefaultBrowser(NimbleGuideURL) + proc doAction(options: var Options) = if options.showHelp: writeHelp() @@ -2348,6 +2356,8 @@ proc doAction(options: var Options) = assert false of actionAdd: addPackages(options.action.packages, options) + of actionManual: + openNimbleManual() of actionCustom: var optsCopy = options optsCopy.task = options.action.command.normalize @@ -2374,7 +2384,9 @@ proc doAction(options: var Options) = raise nimbleError(msg = "Could not find task $1 in $2" % [options.action.command, nimbleFile], hint = "Run `nimble --help` and/or `nimble tasks` for" & - " a list of possible commands.") + " a list of possible commands." & '\n' & + "If you want a tutorial on how to use Nimble, run `nimble guide`." + ) proc setNimBin*(options: var Options) = # Find nim binary and set into options diff --git a/src/nimblepkg/options.nim b/src/nimblepkg/options.nim index 7119e94a..8f913b0e 100644 --- a/src/nimblepkg/options.nim +++ b/src/nimblepkg/options.nim @@ -70,7 +70,7 @@ type actionInstall, actionSearch, actionList, actionBuild, actionPath, actionUninstall, actionCompile, actionDoc, actionCustom, actionTasks, actionDevelop, actionCheck, actionLock, actionRun, actionSync, actionSetup, - actionClean, actionDeps, actionShellEnv, actionShell, actionAdd + actionClean, actionDeps, actionShellEnv, actionShell, actionAdd, actionManual DevelopActionType* = enum datAdd, datRemoveByPath, datRemoveByName, datInclude, datExclude @@ -80,7 +80,7 @@ type Action* = object case typ*: ActionType of actionNil, actionList, actionPublish, actionTasks, actionCheck, - actionSetup, actionClean: nil + actionSetup, actionClean, actionManual: nil of actionSync: listOnly*: bool of actionRefresh: @@ -173,6 +173,7 @@ Commands: build [opts, ...] [bin] Builds a package. Passes options to the Nim compiler. clean Clean build artifacts. + guide Open the Nimble User Guide in your preferred browser. add Adds packages to your project's dependencies. run [opts, ...] [bin] Builds and runs a package. Binary needs to be specified after any @@ -339,6 +340,8 @@ proc parseActionType*(action: string): ActionType = result = actionShell of "add": result = actionAdd + of "manual", "guide": + result = actionManual else: result = actionCustom @@ -918,4 +921,4 @@ proc isSubdirOf*(subdir, baseDir: string): bool = when defined(windows): normalizedSubdir.toLower.startsWith(normalizedBaseDir.toLower) else: - normalizedSubdir.startsWith(normalizedBaseDir) \ No newline at end of file + normalizedSubdir.startsWith(normalizedBaseDir)