ソースを参照

restructure command line parsing and mode specification. the latter now operates as switches

George C. Privon 1 年間 前
コミット
3b6786a844
2 ファイル変更25 行追加34 行削除
  1. 1 0
      CHANGELOG.md
  2. 24 34
      proposal_database.rkt

+ 1 - 0
CHANGELOG.md

@@ -8,6 +8,7 @@
 - Add `--reuse-parameters`/`-r` for `add`. This will auto-fill the proposal type, submiting organzation, solicitation, and telescope from the most recent submission.
 - bugfix in database creation
 - combine creation and update scripts into a single file/tool
+- Modes are now specified as switches rather than as a free-form string. This change enables a more coherent/consistent method of parsing the arguments and getting program argument help (i.e., with `--help`)
 
 ## v0.2.x
 

+ 24 - 34
proposal_database.rkt

@@ -21,37 +21,31 @@
 ; if #t, use proposal type, submitting organiation, solicitation/call, and
 ; telescope name from the most recently submitted (i.e., highest ID) proposal
 (define reuse-params (make-parameter #f))
+; Set up the mode as a parameter to be provided by command line switches
+(define mode (make-parameter #f))
 
 ; set up command line arguments
-(define mode (command-line
-              #:program "proposal_database"
-              #:once-each
-              [("-s" "--start-date") sd "Start of date range (YYYY-MM-DD)"
-                                     (start-date sd)]
-              [("-e" "--end-date") ed "End of date range (YYYY-MM-DD)"
-                                   (end-date ed)]
-              [("-r" "--reuse-parameters") "Reuse/auto-fill proposal type, submitting organization, solicitation/call and telescope name from the most recently added proposal."
-                                           (reuse-params #t)]
-              #:args ([updatetype "help"]) ; (add, update, list-open, list-closed, help)
-              updatetype))
-
-; print some help
-(define (printhelp)
-  (displayln (string-append "Usage: "
-                            progname " MODE"))
-  (newline)
-  (displayln "Where MODE is one of:")
-  (displayln " create-database - initialize the proposal database.")
-  (displayln " add\t\t - add new proposal to database.")
-  (displayln " update\t\t - update a proposal with results.")
-  (displayln " stats\t\t - print summary statistics.")
-  (displayln " list-open\t - Show all submitted (but not resolved) proposals.")
-  (displayln " list-closed\t - Show all resolved (accepted and rejected) proposals.")
-  (displayln " list-accepted\t - Show accepted proposals.")
-  (displayln " list-rejected\t - Show rejected proposals.")
-  (displayln " help\t\t - Show this help message.")
-  (newline)
-  (displayln "Copyright 2019-2020, 2022-2024 George C. Privon"))
+(command-line
+ #:program progname
+ #:once-each
+ [("-s" "--start-date") sd "Start of date range (YYYY-MM-DD)"
+                        (start-date sd)]
+ [("-e" "--end-date") ed "End of date range (YYYY-MM-DD)"
+                      (end-date ed)]
+ [("-r" "--reuse-parameters") "Reuse/auto-fill proposal type, submitting organization, solicitation/call and telescope name from the most recently added proposal."
+                              (reuse-params #t)]
+ #:once-any
+ [("-c" "--create-database") "Create a new database" (mode "create-database")]
+ [("-a" "--add") "Add a new proposal" (mode "add")]
+ [("-u" "--update") "Update a proposal outcome" (mode "update")]
+ [("-s" "--stats") "Calculate and display summary statistics" (mode "stats")]
+ [("-o" "--list-open") "Show all submitted (but not resolved) proposals" (mode "list-open")]
+ [("-c" "--list-closed") "Show all resolved (accepted and rejected) proposals" (mode "list-closed")]
+ [("--list-accepted") "Show accepted proposals" (mode "list-accepted")]
+ [("-r" "--list-rejected") "Show rejected proposals" (mode "list-rejected")]
+ #:ps "Copyright 2019-2020, 2022-2024 George Privon"
+
+ )
 
 ; set up a condensed prompt for getting information
 (define (getinput prompt)
@@ -353,9 +347,5 @@ resultdate TEXT DEFAULT '')")
   (disconnect conn))
 
 
-; First see if the user wants help or if we need to pass to one of the other
-; procedures
-(cond
-  [(regexp-match "help" mode) (printhelp)]
-  [else (querysys mode)])
+(querysys (mode))