feat(cli): generalize 'doom make codeowners'
- Adds -o/--file option, - If -o/--file is passed a dash, print codeowners to stdout, - Adds --dryrun option, - Will accept literal string entries in doom-make-codeowners as standalone lines (useful for comments).
This commit is contained in:
parent
d92a81bf2d
commit
50f0cebe92
1 changed files with 47 additions and 19 deletions
|
@ -10,8 +10,16 @@
|
||||||
;;
|
;;
|
||||||
;;; Variables
|
;;; Variables
|
||||||
|
|
||||||
;; (defvar doom-make-codeowners ()
|
(defvar doom-make-codeowners-file ".github/CODEOWNERS"
|
||||||
;; "TODO")
|
"Where to write the CODEOWNERS file, relative to the repo's toplevel.")
|
||||||
|
|
||||||
|
(defvar doom-make-codeowners ()
|
||||||
|
"An alist of codeowners for this project.
|
||||||
|
|
||||||
|
Each entry can either be a string (inserted verbatim, surrounded by newlines) or
|
||||||
|
a pair of strings (in a cons cell) consisting of: (GLOB . CODEOWNERS).
|
||||||
|
|
||||||
|
The contents of this variable are inserted in reverse.")
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
@ -21,23 +29,43 @@
|
||||||
"(Re)Generate project files and boilerplate."
|
"(Re)Generate project files and boilerplate."
|
||||||
:partial t)
|
:partial t)
|
||||||
|
|
||||||
;; TODO Finish and generalize me
|
(defcli! (make codeowners)
|
||||||
(defstub! (make codeowners) ()
|
((outfile ("-o" "--file" (file stdout)) "Where to write the codeowners file")
|
||||||
"TODO"
|
(dryrun? ("--dryrun")))
|
||||||
(print! (start "Generating CODEOWNERS file"))
|
"Generate (or update) a CODEOWNERS file.
|
||||||
(let ((codeowners (doom-path doom-emacs-dir ".github/CODEOWNERS")))
|
|
||||||
(with-temp-file codeowners
|
By default, this means $GIT_WORK_TREE/.github/CODEOWNERS. This will throw an
|
||||||
(insert-file-contents codeowners)
|
error if not run in a Git repo.
|
||||||
(when (re-search-forward "^# Don't edit this by hand!" nil t)
|
|
||||||
(goto-char (line-end-position))
|
OPTIONS:
|
||||||
(delete-region (point) (point-max))
|
-o, --file
|
||||||
(insert "\n")
|
Pass this option a dash to print the codeowners file to stdout."
|
||||||
(dolist (path (cdr (doom-module-load-path (list doom-modules-dir))))
|
(when dryrun?
|
||||||
(when (string-match "/modules/\\([^/]+\\)/\\([^/]+\\)/$" path)
|
(setq outfile "-")
|
||||||
(insert (format "%-35s @doomemacs/maintainers @doomemacs/%s-%s\n"
|
(print! (warn "Running dry run; will only print to stdout:")))
|
||||||
(concat (substring (match-string-no-properties 0 path) 1) "*")
|
(with-temp-buffer
|
||||||
(match-string-no-properties 1 path)
|
(let ((codeowners-file
|
||||||
(match-string-no-properties 2 path)))))))))
|
(cond ((equal outfile "-") nil)
|
||||||
|
(outfile (expand-file-name outfile))
|
||||||
|
((file-name-concat (doom-git-toplevel) doom-make-codeowners-file)))))
|
||||||
|
(insert "# -*- mode: conf -*-\n"
|
||||||
|
"# Each line is a file pattern followed by one or more owners.\n"
|
||||||
|
"# This file was generated by 'doom make codeowners', do not edit it by hand.\n")
|
||||||
|
(dolist (entry (nreverse doom-make-codeowners))
|
||||||
|
(if (stringp entry)
|
||||||
|
(insert "\n" entry "\n")
|
||||||
|
(insert (car entry) " " (cdr entry) "\n")))
|
||||||
|
(insert "\n# End of CODEOWNERS")
|
||||||
|
(setq indent-tabs-mode nil) ; align w/ spaces, not tabs
|
||||||
|
(align-regexp (point-min) (point-max) "/\\(\\s-+\\)@" 1)
|
||||||
|
(if (null codeowners-file)
|
||||||
|
(print! "%s" (buffer-string))
|
||||||
|
(print! (start "%s codeowners file at: %s")
|
||||||
|
(if (file-exists-p codeowners-file)
|
||||||
|
"Regenerated"
|
||||||
|
"Generated")
|
||||||
|
(relpath codeowners-file))
|
||||||
|
(write-region (buffer-string) nil codeowners-file)))))
|
||||||
|
|
||||||
;; TODO Finish me
|
;; TODO Finish me
|
||||||
(defstub! (make changelog))
|
(defstub! (make changelog))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue