-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b0db74
commit 7ea1365
Showing
3 changed files
with
75 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,94 @@ | ||
;; Copyright (c) 2021-2024 by Greg Hendershott. | ||
;; SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#lang racket/base | ||
#lang at-exp racket/base | ||
|
||
(require racket/match | ||
(require racket/format | ||
racket/logging | ||
racket/match | ||
racket/path | ||
(only-in raco/command-name | ||
short-program+command-name) | ||
"main.rkt") | ||
"analyze.rkt" | ||
"common.rkt" | ||
(only-in (submod "store.rkt" stats) | ||
db-stats | ||
file-stats)) | ||
|
||
(define (err format-string . args) | ||
(apply eprintf | ||
(string-append (short-program+command-name) ": " format-string "\n") | ||
args)) | ||
args) | ||
(exit 1)) | ||
|
||
(define (parse vec) | ||
(match (vector->list vec) | ||
[(list* "analyze" | ||
(? path-string? (app simple-form-path path)) _) | ||
(define depth (or (and (= (vector-length vec) 3) | ||
(match (vector-ref vec 2) | ||
["0" 0] | ||
["1" 1] | ||
["all" 9999])) | ||
0)) | ||
(cond | ||
[(directory-exists? path) | ||
(list 'analyze 'dir path depth)] | ||
[(file-exists? path) | ||
(list 'analyze 'file path depth)] | ||
[else | ||
(err "~v is not an existing file or directory" path)])] | ||
[(list "forget" (? path-string? (app simple-form-path path))) | ||
(cond | ||
[(equal? path (path-only path)) ;directory? | ||
(list 'forget 'dir path)] | ||
[else | ||
(list 'forget 'file path )])] | ||
[(list "stats") | ||
(define (analyze-file-or-dir path [depth 0]) | ||
(cond | ||
[(directory-exists? path) | ||
(void (add-directory path #:import-depth depth))] | ||
[(file-exists? path) | ||
(unless (fresh-analysis? (analyze-path path #:import-depth depth)) | ||
(displayln "Already in cache"))] | ||
[else | ||
(err "~v is not an existing file or directory" path)])) | ||
|
||
(define (forget-file-or-dir path) | ||
(cond | ||
[(equal? path (path-only path)) ;directory? | ||
(forget-directory path)] | ||
[else | ||
(forget-path path)])) | ||
|
||
(define (parse* vec) | ||
(match vec | ||
[(vector (or "analyze" "add") | ||
(app simple-form-path path) | ||
(app string->number depth)) | ||
(analyze-file-or-dir path (or depth 0))] | ||
[(vector (or "analyze" "add") | ||
(app simple-form-path path)) | ||
(analyze-file-or-dir path)] | ||
[(vector (or "analyze" "add")) | ||
(analyze-file-or-dir (simple-form-path (current-directory)))] | ||
[(vector "forget" | ||
(app simple-form-path path)) | ||
(forget-file-or-dir path)] | ||
[(vector "forget") | ||
(forget-file-or-dir (simple-form-path (current-directory)))] | ||
[(vector "stats") | ||
(displayln (db-stats))] | ||
[(list "stats" (app simple-form-path path)) | ||
[(vector "stats" | ||
(app simple-form-path path)) | ||
(displayln (file-stats path))] | ||
[_ | ||
(err "~v is not a valid command" vec) | ||
(usage)])) | ||
(usage) | ||
(exit 1)])) | ||
|
||
(define (usage) | ||
(eprintf "todo\n")) | ||
(define (parse vec) | ||
(with-logging-to-port | ||
#:logger pdb-logger | ||
(current-error-port) | ||
(λ () (parse* vec)) | ||
'info 'pdb)) | ||
|
||
(module+ example | ||
(parse (vector "analyze" "cli.rkt")) | ||
(parse (vector "analyze" "cli.rkt" "1")) | ||
(parse (vector "analyze" "cli.rkt" "all")) | ||
(parse (vector "analyze" (current-directory))) | ||
(parse (vector "analyze" (current-directory) "1")) | ||
(parse (vector "analyze" (current-directory) "all")) | ||
(define (usage) | ||
(displayln | ||
@~a{Usage: | ||
|
||
(parse (vector "forget" "cli.rkt")) | ||
(parse (vector "forget" (current-directory))) | ||
raco pdb add [<file-or-directory> [<import-depth>]] | ||
|
||
(parse (vector "stats")) | ||
(parse (vector "stats" "cli.rkt"))) | ||
<file-or-directory> defaults to the current directory. | ||
<import-depth> defaults to 0, and says how far to analyze | ||
transitively imported files. | ||
|
||
raco pdb forget [<file-or-directory>] | ||
|
||
#;(parse (current-command-line-arguments )) | ||
<file-or-directory> defaults to the current directory. | ||
|
||
raco pdb stats [<file>] | ||
|
||
When <file> is supplied, show stats about the file. | ||
Otherwise show stats about the entire database. | ||
} | ||
(current-error-port))) | ||
|
||
(parse (current-command-line-arguments)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters