generated from jackfirth/racket-package-template
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Improve cli and help #147
Open
Metaxal
wants to merge
4
commits into
jackfirth:master
Choose a base branch
from
Metaxal:hier-cli
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Improve cli and help #147
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
racket/match | ||
racket/path | ||
racket/string | ||
racket/vector | ||
rebellion/base/option | ||
rebellion/collection/entry | ||
rebellion/collection/hash | ||
|
@@ -21,7 +22,8 @@ | |
resyntax/file-group | ||
resyntax/refactoring-result | ||
resyntax/refactoring-suite | ||
resyntax/source) | ||
resyntax/source | ||
syntax/parse/define) | ||
|
||
|
||
;@---------------------------------------------------------------------------------------------------- | ||
|
@@ -30,31 +32,50 @@ | |
(define-record-type resyntax-options (targets suite)) | ||
|
||
|
||
;; Remove the first argument of the command line arguments | ||
(define-syntax-parse-rule (shift-command-line-arguments body ...) | ||
(λ args | ||
(parameterize ([current-command-line-arguments (vector-copy (current-command-line-arguments) 1)]) | ||
body ...))) | ||
|
||
|
||
;; If the command line arguments are empty, re-parameterize it to | ||
;; default to #("--help") | ||
(define-syntax-parse-rule (parameterize-help-if-empty-ccla body ...) | ||
(let ([ccla (current-command-line-arguments)]) | ||
(parameterize ([current-command-line-arguments | ||
(if (vector-empty? ccla) | ||
#("--help") | ||
ccla)]) | ||
body ...))) | ||
|
||
|
||
(define (resyntax-analyze-parse-command-line) | ||
(define targets (box (make-vector-builder))) | ||
(define suite (box default-recommendations)) | ||
(define (add-target! target) | ||
(set-box! targets (vector-builder-add (unbox targets) target))) | ||
(command-line | ||
#:program "resyntax analyze" | ||
#:multi | ||
("--file" filepath "A file to analyze." (add-target! (single-file-group filepath))) | ||
("--directory" | ||
dirpath | ||
"A directory to anaylze, including subdirectories." | ||
(add-target! (directory-file-group dirpath))) | ||
("--package" | ||
pkgname | ||
"An installed package to analyze." | ||
(add-target! (package-file-group pkgname))) | ||
#:once-each | ||
("--refactoring-suite" | ||
modpath | ||
suite-name | ||
"The refactoring suite to analyze code with." | ||
(define parsed-modpath (read (open-input-string modpath))) | ||
(define parsed-suite-name (read (open-input-string suite-name))) | ||
(set-box! suite (dynamic-require parsed-modpath parsed-suite-name)))) | ||
(parameterize-help-if-empty-ccla | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only this line has changed in this function. The rest is indentation. |
||
(command-line | ||
#:program "resyntax --analyze" | ||
#:multi | ||
("--file" filepath "A file to analyze." (add-target! (single-file-group filepath))) | ||
("--directory" | ||
dirpath | ||
"A directory to anaylze, including subdirectories." | ||
(add-target! (directory-file-group dirpath))) | ||
("--package" | ||
pkgname | ||
"An installed package to analyze." | ||
(add-target! (package-file-group pkgname))) | ||
#:once-each | ||
("--refactoring-suite" | ||
modpath | ||
suite-name | ||
"The refactoring suite to analyze code with." | ||
(define parsed-modpath (read (open-input-string modpath))) | ||
(define parsed-suite-name (read (open-input-string suite-name))) | ||
(set-box! suite (dynamic-require parsed-modpath parsed-suite-name))))) | ||
(resyntax-options #:targets (build-vector (unbox targets)) #:suite (unbox suite))) | ||
|
||
|
||
|
@@ -63,41 +84,41 @@ | |
(define suite (box default-recommendations)) | ||
(define (add-target! target) | ||
(set-box! targets (vector-builder-add (unbox targets) target))) | ||
(command-line | ||
#:program "resyntax fix" | ||
#:multi | ||
("--file" filepath "A file to fix." (add-target! (single-file-group filepath))) | ||
("--directory" | ||
dirpath | ||
"A directory to fix, including subdirectories." | ||
(add-target! (directory-file-group dirpath))) | ||
("--package" | ||
pkgname | ||
"An installed package to fix." | ||
(add-target! (package-file-group pkgname))) | ||
#:once-each | ||
("--refactoring-suite" | ||
modpath | ||
suite-name | ||
"The refactoring suite to analyze code with." | ||
(define parsed-modpath (read (open-input-string modpath))) | ||
(define parsed-suite-name (read (open-input-string suite-name))) | ||
(set-box! suite (dynamic-require parsed-modpath parsed-suite-name)))) | ||
(parameterize-help-if-empty-ccla | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only this line has changed n this function. The rest is indentation. |
||
(command-line | ||
#:program "resyntax --fix" | ||
#:multi | ||
("--file" filepath "A file to fix." (add-target! (single-file-group filepath))) | ||
("--directory" | ||
dirpath | ||
"A directory to fix, including subdirectories." | ||
(add-target! (directory-file-group dirpath))) | ||
("--package" | ||
pkgname | ||
"An installed package to fix." | ||
(add-target! (package-file-group pkgname))) | ||
#:once-each | ||
("--refactoring-suite" | ||
modpath | ||
suite-name | ||
"The refactoring suite to analyze code with." | ||
(define parsed-modpath (read (open-input-string modpath))) | ||
(define parsed-suite-name (read (open-input-string suite-name))) | ||
(set-box! suite (dynamic-require parsed-modpath parsed-suite-name))))) | ||
(resyntax-options #:targets (build-vector (unbox targets)) #:suite (unbox suite))) | ||
|
||
|
||
(define (resyntax-run) | ||
(command-line | ||
#:program "resyntax" | ||
#:args (command . leftover-args) | ||
(define leftover-arg-vector (vector->immutable-vector (list->vector leftover-args))) | ||
(match command | ||
["analyze" | ||
(parameterize ([current-command-line-arguments leftover-arg-vector]) | ||
(resyntax-analyze-run))] | ||
["fix" | ||
(parameterize ([current-command-line-arguments leftover-arg-vector]) | ||
(resyntax-fix-run))]))) | ||
(parameterize-help-if-empty-ccla | ||
(command-line | ||
#:program "resyntax" | ||
#:once-any | ||
["--analyze" => (shift-command-line-arguments | ||
(resyntax-analyze-run)) | ||
'("Analyze source code without applying changes")] | ||
["--fix" => (shift-command-line-arguments | ||
(resyntax-fix-run)) | ||
'("Analyze source code and apply changes")]))) | ||
|
||
|
||
(define (resyntax-analyze-run) | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we ought to try to add this to
command-line
as an opt-in feature. So that we could write something like:(command-line #:program-name "foo" #:print-help-by-default flags ...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would certainly be useful.