raco pkg: adjust error messages that include command-line flags

A new `#:from-command-line?` argument to various functions indicates
whether error messages should try to suggest command line flags (since
the suggested flags do not make sense for other contexts, such as the
GUI package manager).
This commit is contained in:
Matthew Flatt 2013-11-12 07:34:36 -07:00
parent cb943909e4
commit 13a3c6c5c8
3 changed files with 84 additions and 20 deletions

View File

@ -1,5 +1,6 @@
#lang scribble/manual #lang scribble/manual
@(require (for-label (except-in racket/base @(require "common.rkt"
(for-label (except-in racket/base
remove) remove)
racket/contract/base racket/contract/base
pkg pkg
@ -167,12 +168,16 @@ The package lock must be held (allowing writes if @racket[set?] is true); see
@defproc[(pkg-create [format (or/c 'zip 'tgz 'plt 'MANIFEST)] @defproc[(pkg-create [format (or/c 'zip 'tgz 'plt 'MANIFEST)]
[dir path-string?] [dir path-string?]
[#:quiet? quiet? boolean? #f]) [#:quiet? quiet? boolean? #f]
[#:from-command-line? from-command-line? boolean? #f])
void?]{ void?]{
Implements @racket[pkg-create-command]. Implements @racket[pkg-create-command].
Unless @racket[quiet?] is true, information about the output is repotred to the current output port.} Unless @racket[quiet?] is true, information about the output is
reported to the current output port. If @racket[from-command-line?]
is true, error messages may suggest specific command-line flags for
@command-ref{create}.}
@defproc[(pkg-install [descs (listof pkg-desc?)] @defproc[(pkg-install [descs (listof pkg-desc?)]
@ -183,6 +188,7 @@ Unless @racket[quiet?] is true, information about the output is repotred to the
[#:force? force? boolean? #f] [#:force? force? boolean? #f]
[#:ignore-checksums? ignore-checksums? boolean? #f] [#:ignore-checksums? ignore-checksums? boolean? #f]
[#:quiet? boolean? quiet? #f] [#:quiet? boolean? quiet? #f]
[#:from-command-line? from-command-line? boolean? #f]
[#:strip strip (or/c #f 'source 'binary) #f] [#:strip strip (or/c #f 'source 'binary) #f]
[#:link-dirs? link-dirs? boolean? #f]) [#:link-dirs? link-dirs? boolean? #f])
(or/c 'skip (or/c 'skip
@ -205,6 +211,9 @@ named @racket['pkg], but information that is especially relevant to a
user (such as a download action) is reported to the current output user (such as a download action) is reported to the current output
port, unless @racket[quiet?] is true. port, unless @racket[quiet?] is true.
If @racket[from-command-line?] is true, error messages may suggest
specific command-line flags for @command-ref{install}.
The package lock must be held; see @racket[with-pkg-lock].} The package lock must be held; see @racket[with-pkg-lock].}
@ -217,6 +226,7 @@ The package lock must be held; see @racket[with-pkg-lock].}
[#:force? force? boolean? #f] [#:force? force? boolean? #f]
[#:ignore-checksums? ignore-checksums? boolean? #f] [#:ignore-checksums? ignore-checksums? boolean? #f]
[#:quiet? boolean? quiet? #f] [#:quiet? boolean? quiet? #f]
[#:from-command-line? from-command-line? boolean? #f]
[#:strip strip (or/c #f 'source 'binary) #f] [#:strip strip (or/c #f 'source 'binary) #f]
[#:link-dirs? link-dirs? boolean? #f]) [#:link-dirs? link-dirs? boolean? #f])
(or/c 'skip (or/c 'skip
@ -231,6 +241,9 @@ A string in @racket[names] refers to an installed package that should
be checked for updates. A @racket[pkg-desc] in @racket[names] indicates be checked for updates. A @racket[pkg-desc] in @racket[names] indicates
a package source that should replace the current installation. a package source that should replace the current installation.
If @racket[from-command-line?] is true, error messages may suggest
specific command-line flags for @command-ref{update}.
The package lock must be held; see @racket[with-pkg-lock].} The package lock must be held; see @racket[with-pkg-lock].}
@ -238,7 +251,8 @@ The package lock must be held; see @racket[with-pkg-lock].}
[#:demote? demote? boolean? #f] [#:demote? demote? boolean? #f]
[#:auto? auto? boolean? #f] [#:auto? auto? boolean? #f]
[#:force? force? boolean? #f] [#:force? force? boolean? #f]
[#:quiet? boolean? quiet? #f]) [#:quiet? boolean? quiet? #f]
[#:from-command-line? from-command-line? boolean? #f])
(or/c 'skip (or/c 'skip
#f #f
(listof (or/c path-string? (listof (or/c path-string?
@ -248,6 +262,9 @@ Implements @racket[pkg-remove-command]. The result is the same as for
@racket[pkg-install], indicating collects that should be setup via @racket[pkg-install], indicating collects that should be setup via
@exec{raco setup}. @exec{raco setup}.
If @racket[from-command-line?] is true, error messages may suggest
specific command-line flags for @command-ref{remove}.
The package lock must be held; see @racket[with-pkg-lock].} The package lock must be held; see @racket[with-pkg-lock].}
@ -270,6 +287,7 @@ The package lock must be held to allow reads; see
[#:force? force? boolean? #f] [#:force? force? boolean? #f]
[#:ignore-checksums? ignore-checksums? boolean? #f] [#:ignore-checksums? ignore-checksums? boolean? #f]
[#:quiet? boolean? quiet? #f] [#:quiet? boolean? quiet? #f]
[#:from-command-line? from-command-line? boolean? #f]
[#:strip strip (or/c #f 'source 'binary) #f]) [#:strip strip (or/c #f 'source 'binary) #f])
(or/c 'skip (or/c 'skip
#f #f
@ -279,6 +297,9 @@ The package lock must be held to allow reads; see
Implements @racket[pkg-migrate-command]. The result is the same as for Implements @racket[pkg-migrate-command]. The result is the same as for
@racket[pkg-install]. @racket[pkg-install].
If @racket[from-command-line?] is true, error messages may suggest
specific command-line flags for @command-ref{migrate}.
The package lock must be held; see @racket[with-pkg-lock].} The package lock must be held; see @racket[with-pkg-lock].}

View File

@ -803,7 +803,8 @@
#:demote? [demote? #f] #:demote? [demote? #f]
#:force? [force? #f] #:force? [force? #f]
#:auto? [auto? #f] #:auto? [auto? #f]
#:quiet? [quiet? #f]) #:quiet? [quiet? #f]
#:from-command-line? [from-command-line? #f])
(define db (read-pkg-db)) (define db (read-pkg-db))
(define all-pkgs (define all-pkgs
(hash-keys db)) (hash-keys db))
@ -1374,6 +1375,7 @@
#:force? force? #:force? force?
#:all-platforms? all-platforms? #:all-platforms? all-platforms?
#:quiet? quiet? #:quiet? quiet?
#:from-command-line? from-command-line?
#:conversation conversation #:conversation conversation
#:strip strip-mode #:strip strip-mode
#:link-dirs? link-dirs? #:link-dirs? link-dirs?
@ -1527,9 +1529,15 @@
(match this-dep-behavior (match this-dep-behavior
['fail ['fail
(clean!) (clean!)
(pkg-error (~a "missing dependencies, specify --deps search-auto to install them or --deps search-ask to be asked about installing them\n" (pkg-error (~a "missing dependencies"
" for package: ~a\n" (if from-command-line?
" missing packages:~a") (~a ";\n"
" specify `--deps search-auto' to install them, or\n"
" specify `--deps search-ask' to be asked about installing them")
"")
"\n"
" for package: ~a\n"
" missing packages:~a")
pkg pkg
(format-list unsatisfied-deps))] (format-list unsatisfied-deps))]
['search-auto ['search-auto
@ -1571,7 +1579,8 @@
#:namespace metadata-ns #:namespace metadata-ns
#:all-platforms? all-platforms? #:all-platforms? all-platforms?
#:ignore-checksums? ignore-checksums? #:ignore-checksums? ignore-checksums?
#:use-cache? use-cache?) #:use-cache? use-cache?
#:from-command-line? from-command-line?)
name)) name))
null)) null))
deps)) deps))
@ -1673,7 +1682,8 @@
#:namespace metadata-ns #:namespace metadata-ns
#:all-platforms? all-platforms? #:all-platforms? all-platforms?
#:ignore-checksums? ignore-checksums? #:ignore-checksums? ignore-checksums?
#:use-cache? use-cache?) #:use-cache? use-cache?
#:from-command-line? from-command-line?)
update-pkgs)]) update-pkgs)])
(λ () (for-each (compose (remove-package quiet?) pkg-desc-name) to-update)))) (λ () (for-each (compose (remove-package quiet?) pkg-desc-name) to-update))))
(match this-dep-behavior (match this-dep-behavior
@ -1917,6 +1927,7 @@
#:update-cache [update-cache (make-hash)] #:update-cache [update-cache (make-hash)]
#:updating? [updating? #f] #:updating? [updating? #f]
#:quiet? [quiet? #f] #:quiet? [quiet? #f]
#:from-command-line? [from-command-line? #f]
#:conversation [conversation #f] #:conversation [conversation #f]
#:strip [strip-mode #f] #:strip [strip-mode #f]
#:link-dirs? [link-dirs? #f] #:link-dirs? [link-dirs? #f]
@ -1974,6 +1985,7 @@
#:pre-succeed pre-succeed #:pre-succeed pre-succeed
#:updating? updating? #:updating? updating?
#:quiet? quiet? #:quiet? quiet?
#:from-command-line? from-command-line?
#:conversation conversation #:conversation conversation
#:strip strip-mode #:strip strip-mode
#:link-dirs? link-dirs? #:link-dirs? link-dirs?
@ -2014,7 +2026,8 @@
#:update-cache update-cache #:update-cache update-cache
#:all-platforms? all-platforms? #:all-platforms? all-platforms?
#:ignore-checksums? ignore-checksums? #:ignore-checksums? ignore-checksums?
#:use-cache? use-cache?) #:use-cache? use-cache?
#:from-command-line? from-command-line?)
pkg-name) pkg-name)
(cond (cond
[(pkg-desc? pkg-name) [(pkg-desc? pkg-name)
@ -2065,7 +2078,8 @@
#:namespace metadata-ns #:namespace metadata-ns
#:all-platforms? all-platforms? #:all-platforms? all-platforms?
#:ignore-checksums? ignore-checksums? #:ignore-checksums? ignore-checksums?
#:use-cache? use-cache?) #:use-cache? use-cache?
#:from-command-line? from-command-line?)
name) name)
null))] null))]
[(eq? #t (hash-ref update-cache pkg-name #f)) [(eq? #t (hash-ref update-cache pkg-name #f))
@ -2081,9 +2095,12 @@
(match orig-pkg (match orig-pkg
[`(,(or 'link 'static-link) ,_) [`(,(or 'link 'static-link) ,_)
(if must-update? (if must-update?
(pkg-error (~a "cannot update linked packages without --link\n" (pkg-error (~a "cannot update linked packages~a\n"
" package name: ~a\n" " package name: ~a\n"
" package source: ~a") " package source: ~a")
(if from-command-line?
" without `--link'"
" without new link")
pkg-name pkg-name
orig-pkg) orig-pkg)
null)] null)]
@ -2130,7 +2147,8 @@
#:namespace metadata-ns #:namespace metadata-ns
#:all-platforms? all-platforms? #:all-platforms? all-platforms?
#:ignore-checksums? ignore-checksums? #:ignore-checksums? ignore-checksums?
#:use-cache? use-cache?) #:use-cache? use-cache?
#:from-command-line? from-command-line?)
((package-dependencies metadata-ns db all-platforms? ((package-dependencies metadata-ns db all-platforms?
#:only-implies? (not deps?)) #:only-implies? (not deps?))
pkg-name)) pkg-name))
@ -2171,6 +2189,7 @@
#:update-deps? [update-deps? #f] #:update-deps? [update-deps? #f]
#:update-implies? [update-implies? #t] #:update-implies? [update-implies? #t]
#:quiet? [quiet? #f] #:quiet? [quiet? #f]
#:from-command-line? [from-command-line? #f]
#:strip [strip-mode #f] #:strip [strip-mode #f]
#:link-dirs? [link-dirs? #f]) #:link-dirs? [link-dirs? #f])
(define download-printf (if quiet? void printf)) (define download-printf (if quiet? void printf))
@ -2190,12 +2209,17 @@
#:namespace metadata-ns #:namespace metadata-ns
#:all-platforms? all-platforms? #:all-platforms? all-platforms?
#:ignore-checksums? ignore-checksums? #:ignore-checksums? ignore-checksums?
#:use-cache? use-cache?) #:use-cache? use-cache?
#:from-command-line? from-command-line?)
pkgs)) pkgs))
(cond (cond
[(empty? pkgs) [(empty? pkgs)
(unless quiet? (unless quiet?
(printf/flush "No packages given to update, did you mean to pass -a?\n")) (printf/flush (~a "No packages given to update"
(if from-command-line?
";\n use `--all' to update all packages"
"")
"\n")))
'skip] 'skip]
[(empty? to-update) [(empty? to-update)
(unless quiet? (unless quiet?
@ -2215,6 +2239,7 @@
#:update-implies? update-implies? #:update-implies? update-implies?
#:update-cache update-cache #:update-cache update-cache
#:quiet? quiet? #:quiet? quiet?
#:from-command-line? from-command-line?
#:strip strip-mode #:strip strip-mode
#:all-platforms? all-platforms? #:all-platforms? all-platforms?
#:force? force? #:force? force?
@ -2281,6 +2306,7 @@
#:all-platforms? [all-platforms? #f] #:all-platforms? [all-platforms? #f]
#:force? [force? #f] #:force? [force? #f]
#:quiet? [quiet? #f] #:quiet? [quiet? #f]
#:from-command-line? [from-command-line? #f]
#:ignore-checksums? [ignore-checksums? #f] #:ignore-checksums? [ignore-checksums? #f]
#:use-cache? [use-cache? #t] #:use-cache? [use-cache? #t]
#:dep-behavior [dep-behavior #f] #:dep-behavior [dep-behavior #f]
@ -2327,6 +2353,7 @@
#:skip-installed? #t #:skip-installed? #t
#:dep-behavior (or dep-behavior 'search-auto) #:dep-behavior (or dep-behavior 'search-auto)
#:quiet? quiet? #:quiet? quiet?
#:from-command-line? from-command-line?
#:strip strip-mode) #:strip strip-mode)
(unless quiet? (unless quiet?
(printf "Packages migrated\n"))))) (printf "Packages migrated\n")))))
@ -2391,6 +2418,7 @@
(define (create-as-is create:format pkg-name dir orig-dir (define (create-as-is create:format pkg-name dir orig-dir
#:quiet? [quiet? #f] #:quiet? [quiet? #f]
#:from-command-line? [from-command-line? #f]
#:hide-src? [hide-src? #f] #:hide-src? [hide-src? #f]
#:dest [dest-dir #f]) #:dest [dest-dir #f])
(begin (begin
@ -2471,6 +2499,7 @@
(define (stripped-create mode name dir (define (stripped-create mode name dir
#:format [create:format 'zip] #:format [create:format 'zip]
#:quiet? [quiet? #f] #:quiet? [quiet? #f]
#:from-command-line? [from-command-line? #f]
#:dest [archive-dest-dir #f]) #:dest [archive-dest-dir #f])
(define tmp-dir (make-temporary-file "create-binary-~a" 'directory)) (define tmp-dir (make-temporary-file "create-binary-~a" 'directory))
(dynamic-wind (dynamic-wind
@ -2482,6 +2511,7 @@
(create-as-is create:format name dest-dir dir (create-as-is create:format name dest-dir dir
#:hide-src? #t #:hide-src? #t
#:quiet? quiet? #:quiet? quiet?
#:from-command-line? from-command-line?
#:dest (if archive-dest-dir #:dest (if archive-dest-dir
(path->complete-path archive-dest-dir) (path->complete-path archive-dest-dir)
(current-directory)))) (current-directory))))
@ -2492,7 +2522,8 @@
#:dest [dest-dir #f] #:dest [dest-dir #f]
#:source [source 'dir] #:source [source 'dir]
#:mode [mode 'as-is] #:mode [mode 'as-is]
#:quiet? [quiet? #f]) #:quiet? [quiet? #f]
#:from-command-line? [from-command-line? #f])
(define pkg-name (define pkg-name
(if (eq? source 'dir) (if (eq? source 'dir)
(path->string (let-values ([(base name dir?) (split-path dir-or-name)]) (path->string (let-values ([(base name dir?) (split-path dir-or-name)])
@ -2519,11 +2550,13 @@
[(as-is) [(as-is)
(create-as-is create:format pkg-name dir dir (create-as-is create:format pkg-name dir dir
#:dest dest-dir #:dest dest-dir
#:quiet? quiet?)] #:quiet? quiet?
#:from-command-line? from-command-line?)]
[else (stripped-create mode pkg-name dir [else (stripped-create mode pkg-name dir
#:dest dest-dir #:dest dest-dir
#:format create:format #:format create:format
#:quiet? quiet?)])) #:quiet? quiet?
#:from-command-line? from-command-line?)]))
(define (pkg-catalog-copy srcs dest (define (pkg-catalog-copy srcs dest
#:from-config? [from-config? #f] #:from-config? [from-config? #f]
@ -3030,6 +3063,7 @@
(#:source (or/c 'dir 'name) (#:source (or/c 'dir 'name)
#:mode (or/c 'as-is 'source 'binary 'built) #:mode (or/c 'as-is 'source 'binary 'built)
#:quiet? boolean? #:quiet? boolean?
#:from-command-line? boolean?
#:dest (or/c (and/c path-string? complete-path?) #f)) #:dest (or/c (and/c path-string? complete-path?) #f))
void?)] void?)]
[pkg-update [pkg-update
@ -3039,6 +3073,7 @@
#:update-deps? boolean? #:update-deps? boolean?
#:update-implies? boolean? #:update-implies? boolean?
#:quiet? boolean? #:quiet? boolean?
#:from-command-line? boolean?
#:all-platforms? boolean? #:all-platforms? boolean?
#:force? boolean? #:force? boolean?
#:ignore-checksums? boolean? #:ignore-checksums? boolean?
@ -3051,6 +3086,7 @@
(#:auto? boolean? (#:auto? boolean?
#:force? boolean? #:force? boolean?
#:quiet? boolean? #:quiet? boolean?
#:from-command-line? boolean?
#:demote? boolean?) #:demote? boolean?)
(or/c #f 'skip (listof (or/c path-string? (non-empty-listof path-string?)))))] (or/c #f 'skip (listof (or/c path-string? (non-empty-listof path-string?)))))]
[pkg-show [pkg-show
@ -3069,6 +3105,7 @@
#:use-cache? boolean? #:use-cache? boolean?
#:skip-installed? boolean? #:skip-installed? boolean?
#:quiet? boolean? #:quiet? boolean?
#:from-command-line? boolean?
#:strip (or/c #f 'source 'binary) #:strip (or/c #f 'source 'binary)
#:link-dirs? boolean?) #:link-dirs? boolean?)
(or/c #f 'skip (listof (or/c path-string? (non-empty-listof path-string?)))))] (or/c #f 'skip (listof (or/c path-string? (non-empty-listof path-string?)))))]
@ -3080,6 +3117,7 @@
#:ignore-checksums? boolean? #:ignore-checksums? boolean?
#:use-cache? boolean? #:use-cache? boolean?
#:quiet? boolean? #:quiet? boolean?
#:from-command-line? boolean?
#:strip (or/c #f 'source 'binary)) #:strip (or/c #f 'source 'binary))
(or/c #f 'skip (listof (or/c path-string? (non-empty-listof path-string?)))))] (or/c #f 'skip (listof (or/c path-string? (non-empty-listof path-string?)))))]
[pkg-catalog-show [pkg-catalog-show

View File

@ -178,7 +178,8 @@
(with-pkg-lock (with-pkg-lock
(parameterize ([current-pkg-catalogs (and catalog (parameterize ([current-pkg-catalogs (and catalog
(list (catalog->url catalog)))]) (list (catalog->url catalog)))])
(pkg-install #:dep-behavior (if auto 'search-auto deps) (pkg-install #:from-command-line? #t
#:dep-behavior (if auto 'search-auto deps)
#:all-platforms? all-platforms #:all-platforms? all-platforms
#:force? force #:force? force
#:ignore-checksums? ignore-checksums #:ignore-checksums? ignore-checksums
@ -234,6 +235,7 @@
(if (eq? pkg-type 'name) (if (eq? pkg-type 'name)
pkg-name pkg-name
(pkg-desc pkg-source a-type name checksum #f))])) (pkg-desc pkg-source a-type name checksum #f))]))
#:from-command-line? #t
#:all? all #:all? all
#:dep-behavior (if auto 'search-auto deps) #:dep-behavior (if auto 'search-auto deps)
#:all-platforms? all-platforms #:all-platforms? all-platforms
@ -264,6 +266,7 @@
(define setup-collects (define setup-collects
(with-pkg-lock (with-pkg-lock
(pkg-remove pkg (pkg-remove pkg
#:from-command-line? #t
#:demote? demote #:demote? demote
#:auto? auto #:auto? auto
#:force? force))) #:force? force)))
@ -335,6 +338,7 @@
(parameterize ([current-pkg-catalogs (and catalog (parameterize ([current-pkg-catalogs (and catalog
(list (catalog->url catalog)))]) (list (catalog->url catalog)))])
(pkg-migrate from-version (pkg-migrate from-version
#:from-command-line? #t
#:dep-behavior deps #:dep-behavior deps
#:force? force #:force? force
#:all-platforms? all-platforms #:all-platforms? all-platforms
@ -364,6 +368,7 @@
(parameterize ([current-pkg-error (pkg-error 'create)]) (parameterize ([current-pkg-error (pkg-error 'create)])
(pkg-create (if manifest 'MANIFEST (or format 'zip)) (pkg-create (if manifest 'MANIFEST (or format 'zip))
directory-or-package directory-or-package
#:from-command-line? #t
#:dest (and dest #:dest (and dest
(path->complete-path dest)) (path->complete-path dest))
#:source (cond #:source (cond