summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob L. Kreuze <zerodaysfordays@sdf.lonestar.org>2019-04-26 12:33:26 -0400
committerJakob L. Kreuze <zerodaysfordays@sdf.lonestar.org>2019-04-26 12:33:26 -0400
commitef74951d4cdda3aff051951d1099ff4da16c89ed (patch)
tree163616d863dc046b9b8ac31a6e5678f21624b10d
parentfabad48a0a0e0523eaeb854bacb528c2bcce90f6 (diff)
Implement `list-groups'
-rw-r--r--brisket.hy32
1 files changed, 17 insertions, 15 deletions
diff --git a/brisket.hy b/brisket.hy
index bf4d0d3..1489813 100644
--- a/brisket.hy
+++ b/brisket.hy
@@ -2,7 +2,7 @@
(import [os [getenv makedirs]])
(import [os.path [dirname expanduser]])
(import [sys [argv exit stderr]])
-(import re)
+(import [re [match]])
(import [nntplib [NNTP-SSL]])
(import [subprocess [Popen PIPE]])
@@ -29,6 +29,16 @@
(let [handler (get (globals) (.replace command "-" "_"))]
(print (. handler __doc__)))))
+(defn list-groups [session &rest args]
+ "List groups on the server, matching a pattern if one is given.
+
+usage: list-groups [pattern (optional)]"
+ (let [pattern (if (>= (len args) 1) (nth args 0))
+ groups (second (.list session))]
+ (for [group groups]
+ (if (or (is pattern None) (match pattern group.group))
+ (print group.group)))))
+
(defn make-config []
"Create a default configuration file.
@@ -116,23 +126,15 @@ The lookup order is:
;; connection to the NNTP server.
(if (= command "help")
(help #* (drop 2 argv))
- (with [session (NNTP_SSL HOST :user USER :password PASSWORD)]
- ;; Otherwise, pull the function out of the global namespace.
- (let [handler (get (globals) (.replace command "-" "_"))]
- (handler #* (drop 2 argv)))))))
+ (let [user (get-username host)
+ password (get-password host)]
+ (with [session (NNTP_SSL host :user user :password password)]
+ ;; Otherwise, pull the function out of the global namespace.
+ (let [handler (get (globals) (.replace command "-" "_"))]
+ (handler session #* (drop 2 argv))))))))
;; # To-be-converted Python
;;
-;;
-;; def list_groups(n, *args):
-;; pattern = args[0] if len(args) >= 1 else None
-;;
-;; _, groups = n.list()
-;;
-;; for group in groups:
-;; if pattern is None or re.match(pattern, group.group):
-;; print(group.group)
-;;
;; def describe_group(n, *args):
;; if len(args) < 1:
;; err("usage: describe-group [group]")