diff options
author | Thien-Thi Nguyen <ttn@gnuvola.org> | 2022-01-18 05:04:35 -0500 |
---|---|---|
committer | Thien-Thi Nguyen <ttn@gnuvola.org> | 2022-01-18 05:04:35 -0500 |
commit | 48051ad829dbfba2c58c19eb67f2622fbd2357a6 (patch) | |
tree | 2c2931a45e7616269bba23a4d17a4a1a9dcb5b53 /manpages/TDM.el | |
parent | cba3d9666c9cf50e574370da6f6d79def1c013bc (diff) | |
download | docs-48051ad829dbfba2c58c19eb67f2622fbd2357a6.tar.gz docs-48051ad829dbfba2c58c19eb67f2622fbd2357a6.tar.bz2 docs-48051ad829dbfba2c58c19eb67f2622fbd2357a6.zip |
Add Emacs Lisp command ‘TDM-recursive-help’
* manpages/TDM.el (TDM-recursive-help): New command.
Diffstat (limited to 'manpages/TDM.el')
-rw-r--r-- | manpages/TDM.el | 50 |
1 files 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 <FOO> 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 |