From 48051ad829dbfba2c58c19eb67f2622fbd2357a6 Mon Sep 17 00:00:00 2001 From: Thien-Thi Nguyen Date: Tue, 18 Jan 2022 05:04:35 -0500 Subject: Add Emacs Lisp command ‘TDM-recursive-help’ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * manpages/TDM.el (TDM-recursive-help): New command. --- manpages/TDM.el | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/manpages/TDM.el b/manpages/TDM.el index b4fabc7a..a58fb1c8 100644 --- a/manpages/TDM.el +++ b/manpages/TDM.el @@ -1,6 +1,6 @@ ;;; TDM.el --- editing Taler docs.git/manpages/* -*- lexical-binding: t -*- -;; Copyright (C) 2021 Taler Systems SA +;; Copyright (C) 2021, 2022 Taler Systems SA ;; ;; This file is part of GNU TALER. ;; @@ -22,7 +22,10 @@ ;;; Commentary: -;; This library currently provides one command: ‘TDM-convert-options’. +;; This library currently provides two commands: ‘TDM-convert-options’ +;; and ‘TDM-recursive-help’. +;; +;; * ‘TDM-convert-options’ ;; The intended workflow is simple: ;; - Create a new file from template. ;; - Do the substitutions / deletions as necessary. @@ -49,6 +52,15 @@ ;; There are a couple TODO items, which point to situations that ;; have not yet arisen in practice, but that might theoretically ;; bother us in the future. +;; +;; * ‘TDM-recursive-help’ +;; This command is intended for libeufin programs, specifically +;; libeufin-sandbox, libeufin-nexus, and libeufin-cli. However, +;; it should work with any Java program that uses clikt, or any +;; Python program that uses click, for its command-line handling. +;; +;; You can obtain the --help output (recursively) in a buffer +;; and write it to a file for further analysis / processing. ;;; Code: @@ -121,6 +133,40 @@ Prefix arg KEEP-ORIG means don't delete them." (save-excursion (delete-region p q))))) +(defun TDM-recursive-help (command) + "Call COMMAND --help and recurse on its subcommands. +Subcommands are identified by \"Commands:\" in column 0 +in the output. + +Collect the output in a new buffer *COMMAND --help*, +with one page per --help output." + (interactive "sCommand: ") + (let ((out (get-buffer-create (format "*%s --help*" command)))) + (with-current-buffer out + (erase-buffer)) + (cl-labels + ;; visit command + ((v (c) (with-temp-buffer + (apply #'call-process (car c) nil t nil + (append (cdr c) (list "--help"))) + (goto-char (point-min)) + (when (re-search-forward "^Commands:\n" nil t) + (while (looking-at "[ ][ ]\\(\\S +\\)") + (let ((sub (match-string 1))) + (v (append c (list sub)))) + (forward-line 1) + (while (looking-at "[ ][ ][ ]") + (forward-line 1)))) + (let ((s (buffer-string))) + (message "c: %s" c) + (with-current-buffer out + (goto-char (point-min)) + (insert "\f\n") + (insert "$ " (substring (format "%s" c) 1 -1) "\n") + (insert s "\n")))))) + (v (list command))) + (switch-to-buffer out))) + (provide 'TDM) ;;; TDM.el ends here -- cgit v1.2.3