distros.nim: better documenation
This commit is contained in:
parent
33b8ade07c
commit
f6c2c4a6a0
1 changed files with 20 additions and 7 deletions
|
|
@ -8,14 +8,22 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
## This module implements the basics for Linux distribution ("distro")
|
## This module implements the basics for Linux distribution ("distro")
|
||||||
## detection and the OS's native package manager. Its primary purpose is in
|
## detection and the OS's native package manager. Its primary purpose is to
|
||||||
## producing output for Nimble packages like::
|
## produce output for Nimble packages like::
|
||||||
##
|
##
|
||||||
## To complete the installation, run:
|
## To complete the installation, run:
|
||||||
##
|
##
|
||||||
## sudo apt-get libblas-dev
|
## sudo apt-get libblas-dev
|
||||||
## sudo apt-get libvoodoo
|
## sudo apt-get libvoodoo
|
||||||
##
|
##
|
||||||
|
## The above output could be the result of a code snippet like:
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
##
|
||||||
|
## if detectOs(Ubuntu):
|
||||||
|
## foreignDep "lbiblas-dev"
|
||||||
|
## foreignDep "libvoodoo"
|
||||||
|
##
|
||||||
|
|
||||||
from strutils import contains, toLowerAscii
|
from strutils import contains, toLowerAscii
|
||||||
|
|
||||||
|
|
@ -23,8 +31,7 @@ when not defined(nimscript):
|
||||||
from osproc import execProcess
|
from osproc import execProcess
|
||||||
|
|
||||||
type
|
type
|
||||||
Distribution* {.pure.} = enum ## an enum so that the poor programmer
|
Distribution* {.pure.} = enum ## the list of known distributions
|
||||||
## cannot introduce typos
|
|
||||||
Windows ## some version of Windows
|
Windows ## some version of Windows
|
||||||
Posix ## some Posix system
|
Posix ## some Posix system
|
||||||
MacOSX ## some version of OSX
|
MacOSX ## some version of OSX
|
||||||
|
|
@ -161,12 +168,17 @@ proc detectOsImpl(d: Distribution): bool =
|
||||||
result = toLowerAscii($d) in toLowerAscii(uname())
|
result = toLowerAscii($d) in toLowerAscii(uname())
|
||||||
|
|
||||||
template detectOs*(d: untyped): bool =
|
template detectOs*(d: untyped): bool =
|
||||||
|
## Distro/OS detection. For convenience the
|
||||||
|
## required ``Distribution.`` qualifier is added to the
|
||||||
|
## enum value.
|
||||||
detectOsImpl(Distribution.d)
|
detectOsImpl(Distribution.d)
|
||||||
|
|
||||||
when not defined(nimble):
|
when not defined(nimble):
|
||||||
var foreignDeps: seq[string] = @[]
|
var foreignDeps: seq[string] = @[]
|
||||||
|
|
||||||
proc foreignCmd*(cmd: string; requiresSudo=false) =
|
proc foreignCmd*(cmd: string; requiresSudo=false) =
|
||||||
|
## Registers a foreign command to the intern list of commands
|
||||||
|
## that can be queried later.
|
||||||
let c = (if requiresSudo: "sudo " else: "") & cmd
|
let c = (if requiresSudo: "sudo " else: "") & cmd
|
||||||
when defined(nimble):
|
when defined(nimble):
|
||||||
nimscriptapi.foreignDeps.add(c)
|
nimscriptapi.foreignDeps.add(c)
|
||||||
|
|
@ -174,7 +186,7 @@ proc foreignCmd*(cmd: string; requiresSudo=false) =
|
||||||
foreignDeps.add(c)
|
foreignDeps.add(c)
|
||||||
|
|
||||||
proc foreignDepInstallCmd*(foreignPackageName: string): (string, bool) =
|
proc foreignDepInstallCmd*(foreignPackageName: string): (string, bool) =
|
||||||
## returns the distro's native command line to install 'foreignPackageName'
|
## Returns the distro's native command line to install 'foreignPackageName'
|
||||||
## and whether it requires root/admin rights.
|
## and whether it requires root/admin rights.
|
||||||
let p = foreignPackageName
|
let p = foreignPackageName
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
|
|
@ -211,16 +223,17 @@ proc foreignDepInstallCmd*(foreignPackageName: string): (string, bool) =
|
||||||
result = ("brew install " & p, true)
|
result = ("brew install " & p, true)
|
||||||
|
|
||||||
proc foreignDep*(foreignPackageName: string) =
|
proc foreignDep*(foreignPackageName: string) =
|
||||||
|
## Registers 'foreignPackageName' to the internal list of foreign deps.
|
||||||
|
## It is your job to ensure the package name
|
||||||
let (installCmd, sudo) = foreignDepInstallCmd(foreignPackageName)
|
let (installCmd, sudo) = foreignDepInstallCmd(foreignPackageName)
|
||||||
foreignCmd installCmd, sudo
|
foreignCmd installCmd, sudo
|
||||||
|
|
||||||
proc echoForeignDeps*() =
|
proc echoForeignDeps*() =
|
||||||
## Writes the list of registered foreign deps to stdout.
|
## Writes the list of registered foreign deps to stdout.
|
||||||
echo "To finish the installation, run:"
|
|
||||||
for d in foreignDeps:
|
for d in foreignDeps:
|
||||||
echo d
|
echo d
|
||||||
|
|
||||||
when isMainModule:
|
when false:
|
||||||
foreignDep("libblas-dev")
|
foreignDep("libblas-dev")
|
||||||
foreignDep "libfoo"
|
foreignDep "libfoo"
|
||||||
echoForeignDeps()
|
echoForeignDeps()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue