add vcs to the new created project (#729)
* add git vcs and a default .nim.cfg file to the new created project * remove the gitapi dependency * add vcs support for new nimble project * add vcs support for new nimble project * update pull request #729 * add --git/hg flag instead of --vcs flag for nimble init command
This commit is contained in:
parent
b3abee937d
commit
bbb586dbfc
2 changed files with 29 additions and 1 deletions
|
|
@ -3,12 +3,13 @@
|
|||
|
||||
import system except TResult
|
||||
|
||||
import os, tables, strtabs, json, algorithm, sets, uri, sugar, sequtils
|
||||
import os, tables, strtabs, json, algorithm, sets, uri, sugar, sequtils, osproc
|
||||
import std/options as std_opt
|
||||
|
||||
import strutils except toLower
|
||||
from unicode import toLower
|
||||
from sequtils import toSeq
|
||||
from strformat import fmt
|
||||
|
||||
import nimblepkg/packageinfo, nimblepkg/version, nimblepkg/tools,
|
||||
nimblepkg/download, nimblepkg/config, nimblepkg/common,
|
||||
|
|
@ -724,6 +725,11 @@ proc dump(options: Options) =
|
|||
echo "backend: ", p.backend.escape
|
||||
|
||||
proc init(options: Options) =
|
||||
# Check whether the vcs is installed.
|
||||
let vcsBin = options.action.vcsOption
|
||||
if vcsBin != "" and findExe(vcsBin, true) == "":
|
||||
raise newException(NimbleError, "Please install git or mercurial first")
|
||||
|
||||
# Determine the package name.
|
||||
let pkgName =
|
||||
if options.action.projName != "":
|
||||
|
|
@ -858,6 +864,17 @@ js - Compile using JavaScript backend.""",
|
|||
pkgRoot
|
||||
)
|
||||
|
||||
# Create a git or hg repo in the new nimble project.
|
||||
if vcsBin != "":
|
||||
let cmd = fmt"cd {pkgRoot} && {vcsBin} init"
|
||||
let ret: tuple[output: string, exitCode: int] = execCmdEx(cmd)
|
||||
if ret.exitCode != 0: quit ret.output
|
||||
|
||||
var ignoreFile = if vcsBin == "git": ".gitignore" else: ".hgignore"
|
||||
var fd = open(joinPath(pkgRoot, ignoreFile), fmWrite)
|
||||
fd.write(pkgName & "\n")
|
||||
fd.close()
|
||||
|
||||
display("Success:", "Package $# created successfully" % [pkgName], Success,
|
||||
HighPriority)
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ type
|
|||
search*: seq[string] # Search string.
|
||||
of actionInit, actionDump:
|
||||
projName*: string
|
||||
vcsOption*: string
|
||||
of actionCompile, actionDoc, actionBuild:
|
||||
file*: string
|
||||
backend*: string
|
||||
|
|
@ -80,6 +81,8 @@ Commands:
|
|||
init [pkgname] Initializes a new Nimble project in the
|
||||
current directory or if a name is provided a
|
||||
new directory of the same name.
|
||||
--git
|
||||
--hg Create a git or hg repo in the new nimble project.
|
||||
publish Publishes a package on nim-lang/packages.
|
||||
The current working directory needs to be the
|
||||
toplevel directory of the Nimble package.
|
||||
|
|
@ -201,8 +204,10 @@ proc initAction*(options: var Options, key: string) =
|
|||
else: options.action.backend = keyNorm
|
||||
of actionInit:
|
||||
options.action.projName = ""
|
||||
options.action.vcsOption = ""
|
||||
of actionDump:
|
||||
options.action.projName = ""
|
||||
options.action.vcsOption = ""
|
||||
options.forcePrompts = forcePromptYes
|
||||
of actionRefresh:
|
||||
options.action.optionalURL = ""
|
||||
|
|
@ -349,6 +354,12 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
|
|||
result.action.passNimFlags.add(val)
|
||||
else:
|
||||
wasFlagHandled = false
|
||||
of actionInit:
|
||||
case f
|
||||
of "git", "hg":
|
||||
result.action.vcsOption = f
|
||||
else:
|
||||
wasFlagHandled = false
|
||||
of actionUninstall:
|
||||
case f
|
||||
of "incldeps", "i":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue