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

Cli ux improvements docs #1328

Merged
merged 6 commits into from
Jan 9, 2025
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
8 changes: 4 additions & 4 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2381,10 +2381,10 @@ proc doAction(options: var Options) =
init(options)
of actionPublish:
var pkgInfo = getPkgInfo(getCurrentDir(), options)
if options.action.publishAction == "tags":
publishTags(pkgInfo, options)
else:
publish(pkgInfo, options)
publish(pkgInfo, options)
of actionPublishTags:
var pkgInfo = getPkgInfo(getCurrentDir(), options)
publishTags(pkgInfo, options)
of actionDump:
dump(options)
of actionTasks:
Expand Down
23 changes: 20 additions & 3 deletions src/nimblepkg/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ type
actionInstall, actionSearch, actionList, actionBuild, actionPath,
actionUninstall, actionCompile, actionDoc, actionCustom, actionTasks,
actionDevelop, actionCheck, actionLock, actionRun, actionSync, actionSetup,
actionClean, actionDeps, actionShellEnv, actionShell, actionAdd, actionManual
actionClean, actionDeps, actionShellEnv, actionShell, actionAdd, actionManual,
actionPublishTags

DevelopActionType* = enum
datAdd, datRemoveByPath, datRemoveByName, datInclude, datExclude
Expand Down Expand Up @@ -124,6 +125,8 @@ type
depsAction*: string
of actionPublish:
publishAction*: string
of actionPublishTags:
onlyListTags*: bool
of actionShellEnv, actionShell:
discard

Expand Down Expand Up @@ -177,6 +180,10 @@ Commands:
publish Publishes a package on nim-lang/packages.
The current working directory needs to be the
top level directory of the Nimble package.
publishTags Finds and publishes new tags based on the
commits where a package's Nimble file changed.
[-l, --listOnly] Only list the tags and versions which are found without
actually performing tag or publishing them.
uninstall [pkgname, ...] Uninstalls a list of packages.
[-i, --inclDeps] Uninstalls package and dependent package(s).
build [opts, ...] [bin] Builds a package. Passes options to the Nim
Expand Down Expand Up @@ -216,9 +223,11 @@ Commands:
[--ini, --json] Selects the output format (the default is --ini).
lock Generates or updates a package lock file.
upgrade [pkgname, ...] Upgrades a list of packages in the lock file.
deps Outputs dependency tree
deps Outputs dependencies for current package.
[--tree] Outputs dependency tree.
[--inverted] Outputs inverted (reversed) dependency tree.
[--format type] Specify the output format. Json is the only supported
format
format. Only some commands support it.
sync Synchronizes develop mode dependencies with
the content of the lock file.
[-l, --listOnly] Only lists the packages which are not synced
Expand Down Expand Up @@ -329,6 +338,8 @@ proc parseActionType*(action: string): ActionType =
result = actionUninstall
of "publish":
result = actionPublish
of "publishtags":
result = actionPublishTags
of "upgrade":
result = actionUpgrade
of "tasks":
Expand Down Expand Up @@ -762,6 +773,12 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
result.action.publishAction = "tags"
else:
wasFlagHandled = false
of actionPublishTags:
case f
of "l", "listonly":
result.action.onlyListTags = true
else:
wasFlagHandled = false
of actionDeps:
case f
of "format":
Expand Down
25 changes: 11 additions & 14 deletions src/nimblepkg/publish.nim
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ proc createTag*(tag: string, commit: Sha1Hash, message, repoDir, nimbleFile: str
of DownloadMethod.hg:
assert false, "hg not supported"

proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, downloadMethod: DownloadMethod) =
proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string, downloadMethod: DownloadMethod, options: Options) =
## parse the versions
var
versions: HashSet[Version]
Expand All @@ -305,23 +305,20 @@ proc findVersions(commits: seq[(Sha1Hash, string)], projdir, nimbleFile: string,
if version notin versions:
versions.incl(version)
if version in existingTags:
displayInfo(&"Found existing tag for version {version}", MediumPriority)
displayInfo(&"Found existing tag for version {version} at commit {commit}", HighPriority)
else:
displayInfo(&"Found new version {version} at {commit}", MediumPriority)
let res = createTag(&"v{version}", commit, message, projdir, nimbleFile, downloadMethod)
if not res:
displayError(&"Unable to create tag {version}")
displayInfo(&"Found new version {version} at {commit}", HighPriority)
if not options.action.onlyListTags:
displayWarning(&"Creating tag for new version {version} at {commit}", HighPriority)
let res = createTag(&"v{version}", commit, message, projdir, nimbleFile, downloadMethod)
if not res:
displayError(&"Unable to create tag {version}", HighPriority)

proc publishTags*(p: PackageInfo, o: Options) =
discard
echo "publishTags:myPath: ", $p.myPath
echo "publishTags:basic: ", $p.basicInfo
# echo "publishTags: ", $p
proc publishTags*(p: PackageInfo, options: Options) =
displayInfo(&"Searcing for new tags for {$p.basicInfo.name} @{$p.basicInfo.version}", HighPriority)
let (projdir, file, ext) = p.myPath.splitFile()
let nimblefile = file & ext
let dlmethod = p.metadata.downloadMethod
let commits = vcsFindCommits(projdir, nimbleFile, dlmethod)
echo "publishTags:commits: ", $commits.len()

findVersions(commits, projdir, nimbleFile, dlmethod)
echo ""
findVersions(commits, projdir, nimbleFile, dlmethod, options)
Loading