Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nimble guide #1318

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions 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 All @@ -2373,7 +2383,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
Expand Down
9 changes: 6 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 @@ -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
Expand Down Expand Up @@ -339,6 +340,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 +921,4 @@ proc isSubdirOf*(subdir, baseDir: string): bool =
when defined(windows):
normalizedSubdir.toLower.startsWith(normalizedBaseDir.toLower)
else:
normalizedSubdir.startsWith(normalizedBaseDir)
normalizedSubdir.startsWith(normalizedBaseDir)
Loading