Skip to content

Commit

Permalink
(add) guide/manual command
Browse files Browse the repository at this point in the history
This command opens up the Nimble guide
(https://nim-lang.github.io/nimble/index.html) in the user's preferred
web browser.

Related to nim-lang#1272
  • Loading branch information
xTrayambak committed Dec 17, 2024
1 parent 123f97a commit b19a375
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/nimble.nim
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -2275,6 +2275,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()
Expand Down Expand Up @@ -2347,6 +2355,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
Expand Down
8 changes: 5 additions & 3 deletions src/nimblepkg/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -339,6 +339,8 @@ proc parseActionType*(action: string): ActionType =
result = actionShell
of "add":
result = actionAdd
of "manual", "guide":
result = actionManual
else:
result = actionCustom

Expand Down Expand Up @@ -918,4 +920,4 @@ proc isSubdirOf*(subdir, baseDir: string): bool =
when defined(windows):
normalizedSubdir.toLower.startsWith(normalizedBaseDir.toLower)
else:
normalizedSubdir.startsWith(normalizedBaseDir)
normalizedSubdir.startsWith(normalizedBaseDir)

0 comments on commit b19a375

Please sign in to comment.