Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bin: Add --inc and --loose

  • Loading branch information...
commit 4496c20e3a54c26458178bbdde8c1af08be97a95 1 parent f8b92a6
@isaacs isaacs authored
Showing with 67 additions and 19 deletions.
  1. +5 −4 README.md
  2. +62 −15 bin/semver
View
9 README.md
@@ -16,11 +16,12 @@ As a command-line utility:
$ semver -h
- Usage: semver -v <version> [-r <range>]
- Test if version(s) satisfy the supplied range(s),
- and sort them.
+ Usage: semver <version> [<version> [...]] [-r <range> | -i <inc> | -d <dec>]
+ Test if version(s) satisfy the supplied range(s), and sort them.
- Multiple versions or ranges may be supplied.
+ Multiple versions or ranges may be supplied, unless increment
+ or decrement options are specified. In that case, only a single
+ version may be used, and it is incremented by the specified level
Program exits successfully if any valid version satisfies
all supplied ranges, and prints all satisfying versions.
View
77 bin/semver
@@ -9,6 +9,9 @@ var argv = process.argv.slice(2)
, gt = []
, lt = []
, eq = []
+ , inc = null
+ , version = require("../package.json").version
+ , loose = false
, semver = require("../semver")
main()
@@ -16,11 +19,29 @@ main()
function main () {
if (!argv.length) return help()
while (argv.length) {
- var a
- switch (a = argv.shift()) {
+ var a = argv.shift()
+ var i = a.indexOf('=')
+ if (i !== -1) {
+ a = a.slice(0, i)
+ argv.unshift(a.slice(i + 1))
+ }
+ switch (a) {
+ case "-l": case "--loose":
+ loose = true
+ break
case "-v": case "--version":
versions.push(argv.shift())
break
+ case "-i": case "--inc": case "--increment":
+ switch (argv[0]) {
+ case "major": case "minor": case "patch": case "prerelease":
+ inc = argv.shift()
+ break
+ default:
+ inc = "patch"
+ break
+ }
+ break
case "-r": case "--range":
range.push(argv.shift())
break
@@ -32,41 +53,67 @@ function main () {
}
}
- versions = versions.filter(semver.valid)
+ versions = versions.filter(function (v) {
+ return semver.valid(v, loose)
+ })
if (!versions.length) return fail()
+ if (inc && (versions.length !== 1 || range.length))
+ return failInc()
+
for (var i = 0, l = range.length; i < l ; i ++) {
versions = versions.filter(function (v) {
- return semver.satisfies(v, range[i])
+ return semver.satisfies(v, range[i], loose)
})
if (!versions.length) return fail()
}
return success(versions)
}
+function failInc () {
+ console.error("--inc can only be used on a single version with no range")
+ fail()
+}
+
function fail () { process.exit(1) }
function success () {
- versions.sort(semver.compare)
- .map(semver.clean)
- .forEach(function (v,i,_) { console.log(v) })
+ versions.sort(function (a, b) {
+ return semver.compare(a, b, loose)
+ }).map(function (v) {
+ return semver.clean(v, loose)
+ }).map(function (v) {
+ return inc ? semver.inc(v, inc, loose) : v
+ }).forEach(function (v,i,_) { console.log(v) })
}
function help () {
- console.log(["Usage: semver -v <version> [-r <range>]"
- ,"Test if version(s) satisfy the supplied range(s),"
- ,"and sort them."
+ console.log(["SemVer " + version
,""
- ,"Multiple versions or ranges may be supplied."
+ ,"A JavaScript implementation of the http://semver.org/ specification"
+ ,"Copyright Isaac Z. Schlueter"
+ ,""
+ ,"Usage: semver [options] <version> [<version> [...]]"
+ ,"Prints valid versions sorted by SemVer precedence"
+ ,""
+ ,"Options:"
+ ,"-r --range <range>"
+ ," Print versions that match the specified range."
+ ,""
+ ,"-i --increment [<level>]"
+ ," Increment a version by the specified level. Level can"
+ ," be one of: major, minor, patch, or prerelease"
+ ," Default level is 'patch'."
+ ," Only one version may be specified."
+ ,""
+ ,"-l --loose"
+ ," Interpret versions and ranges loosely"
,""
,"Program exits successfully if any valid version satisfies"
,"all supplied ranges, and prints all satisfying versions."
,""
- ,"If no versions are valid, or ranges are not satisfied,"
- ,"then exits failure."
+ ,"If no satisfying versions are found, then exits failure."
,""
,"Versions are printed in ascending order, so supplying"
,"multiple versions to the utility will just sort them."
].join("\n"))
}
-
-
Please sign in to comment.
Something went wrong with that request. Please try again.