From ef74951d4cdda3aff051951d1099ff4da16c89ed Mon Sep 17 00:00:00 2001 From: "Jakob L. Kreuze" Date: Fri, 26 Apr 2019 12:33:26 -0400 Subject: Implement `list-groups' --- brisket.hy | 32 +++++++++++++++++--------------- 1 file 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]") -- cgit v1.3