-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(generate): Add command to generate ignore file (#169)
* feat(generate): Add command to generate ignore file * Changelog * fix comment * update doc * Add generate test
- Loading branch information
Showing
9 changed files
with
168 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright (C) 2023 Jen-Chieh Shen | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with GNU Emacs; see the file COPYING. If not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
"use strict"; | ||
|
||
exports.command = ['ignore <name>']; | ||
exports.desc = 'Generate ignore file using .gitignore templates'; | ||
exports.builder = yargs => yargs | ||
.positional( | ||
'<name>', { | ||
description: 'name of the ignore template', | ||
type: 'string', | ||
}) | ||
.options({ | ||
'output': { | ||
description: 'output result to a file; the default is `.gitignore`', | ||
alias: 'o', | ||
type: 'string', | ||
group: TITLE_CMD_OPTION, | ||
}, | ||
}); | ||
|
||
exports.handler = async (argv) => { | ||
await UTIL.e_call(argv, 'generate/ignore' | ||
, argv.name | ||
, UTIL.def_flag(argv.output, '--output', argv.output)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
;;; generate/ignore.el --- Generate ignore file -*- lexical-binding: t; -*- | ||
|
||
;;; Commentary: | ||
;; | ||
;; Command use generate ignore file, | ||
;; | ||
;; $ eask generate ignore <name> | ||
;; | ||
;; | ||
;; Positionals: | ||
;; | ||
;; <name> Name of the ignore template | ||
;; | ||
;; Optional arguments: | ||
;; | ||
;; --output Output result to a file; the default is `.gitignore` | ||
;; | ||
|
||
;;; Code: | ||
|
||
(let ((dir (file-name-directory (nth 1 (member "-scriptload" command-line-args))))) | ||
(load (expand-file-name "_prepare.el" | ||
(locate-dominating-file dir "_prepare.el")) | ||
nil t)) | ||
|
||
(defun eask--print-ignore-menu () | ||
"Print all available ignore." | ||
(eask-msg "available via `eask generate ignore`") | ||
(eask-msg "") | ||
(let ((names (gitignore-templates-names))) | ||
(dolist (data names) | ||
(eask-msg " %s" data)) | ||
(eask-msg "") | ||
(eask-info "(Total of %s available ignore file%s)" (length names) | ||
(eask--sinr names "" "s")))) | ||
|
||
(eask-start | ||
;; Preparation | ||
(eask-with-archives "melpa" | ||
(eask-package-install 'gitignore-templates)) | ||
|
||
;; Start the task | ||
(require 'gitignore-templates) | ||
(let* ((name (car (eask-args))) ; type of the ignore | ||
(basename (or (eask-output) ".gitignore")) | ||
(filename (expand-file-name basename))) | ||
(eask-msg "") | ||
(cond ((file-exists-p filename) | ||
(eask-info "(The ignore file already exists `%s`)" filename)) | ||
((not (member name (gitignore-templates-names))) | ||
(eask-info "(Invalid ignore type: `%s`)" name) | ||
(eask--print-ignore-menu)) | ||
(t | ||
(eask-with-progress | ||
(format "Generating ignore file in %s... " filename) | ||
(with-current-buffer (find-file filename) | ||
(gitignore-templates-insert name) | ||
(save-buffer)) | ||
"done ✓"))))) | ||
|
||
;;; generate/ignore.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters