Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

Commit

Permalink
Add chver command
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrolasting committed Aug 2, 2020
1 parent 11f45f6 commit 7ebcb66
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
55 changes: 55 additions & 0 deletions cli.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
["diff" diff-command]
["sandbox" sandbox-command]
["serve" serve-command]
["chver" chver-command]
["bundle" bundle-command]
[_ (printf "Unrecognized command: ~s. Run with -h for usage information.~n"
action)
Expand All @@ -94,6 +95,7 @@
diff Compare workspace to capture
sandbox Start sandboxed REPL for package's setup module.
serve Serve package artifacts
chver Change package version
bundle Prepare package for distribution

EOF
Expand Down Expand Up @@ -339,6 +341,59 @@ EOF
))


(define (chver-command args)
(run-command-line
#:program "chver"
#:arg-help-strings '("package-path" "revision-names")
#:flags
(settings->flag-specs
ZCPKG_EDITION
ZCPKG_REVISION_ZERO)
#:args args
(λ (flags package-path-string . revision-names)
(define info
(with-handlers ([exn:fail:filesystem?
(λ (e)
(printf "Could not read ~a. Double check that ~s points to a package directory.~n"
CONVENTIONAL_PACKAGE_INFO_FILE_NAME
package-path-string)
(raise 1))])
(read-zcpkg-info-from-directory package-path-string)))

(define errors (validate-zcpkg-info info))
(unless (null? errors)
(printf (~a "Cannot change version.~n"
"There are errors in the original info:~n~a~n")
(string-join errors "\n"))
(raise 1))

(define new-info
(struct-copy zcpkg-info info
[edition-name (or (~a (ZCPKG_EDITION))
(zcpkg-info-edition-name info))]
[revision-number (if (ZCPKG_REVISION_ZERO)
0
(add1 (zcpkg-info-revision-number info)))]
[revision-names revision-names]))

(define new-errors (validate-zcpkg-info new-info))
(unless (null? errors)
(printf (~a "Cannot change version.~n"
"There are errors in the new info:~n~a~n")
(string-join new-errors "\n"))
(raise 1))

(call-with-output-file
#:exists 'truncate/replace
(build-path package-path-string
CONVENTIONAL_PACKAGE_INFO_FILE_NAME)
(λ (o) (write-zcpkg-info new-info o)))

(printf "~a -> ~a~n"
(format-zcpkg-info info)
(format-zcpkg-info new-info)))))


(define (bundle-command args)
(run-command-line
#:program "bundle"
Expand Down
3 changes: 3 additions & 0 deletions format.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
(define (join-lines lines)
(string-join lines "\n"))

(define (format-zcpkg-info info)
(zcpkg-query->string (zcpkg-info->zcpkg-query info)))

(define (print-zcpkg-info-table unsorted-infos)
(define infos
(sort unsorted-infos
Expand Down
13 changes: 13 additions & 0 deletions zcpkg-settings.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"config.rkt"
"contract.rkt"
"setting.rkt"
"string.rkt"
"url.rkt"
"workspace.rkt")

Expand Down Expand Up @@ -129,6 +130,18 @@
boolean?
#f}

{ZCPKG_EDITION
"-e"
("The name of the edition. If not set, use existing name." "name")
(or/c #f symbol? name-string?)
#f}

{ZCPKG_REVISION_ZERO
"-z"
("Set revision number to 0.")
boolean?
#f}

{ZCPKG_SANDBOX_PATH_PERMISSIONS
"-P"
("A value for sandbox-path-permissions" "racket-value")
Expand Down

0 comments on commit 7ebcb66

Please sign in to comment.