Skip to content

Commit 8486722

Browse files
authored
feature: Add command to clean log files (#97)
* feature: Add command to clean log files * Add tes
1 parent 48aa173 commit 8486722

File tree

7 files changed

+94
-6
lines changed

7 files changed

+94
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
3030
* Improve Eask-file loader to search file upward (#89)
3131
* Move command `activate` under test subcommand (#92)
3232
* Add command to create ELPA project (#94)
33+
* Add command to clean log files (#97)
3334

3435
## 0.7.x
3536
> Released Sep 08, 2022

cmds/clean/log-file.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (C) 2023 Jen-Chieh Shen
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3, or (at your option)
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with GNU Emacs; see the file COPYING. If not, write to the
16+
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17+
* Boston, MA 02110-1301, USA.
18+
*/
19+
20+
"use strict";
21+
22+
exports.command = ['log-file'];
23+
exports.desc = 'Remove all generated log files';
24+
25+
exports.handler = async (argv) => {
26+
await UTIL.e_call(argv, 'clean/log-file');
27+
};

docs/content/en/Getting Started/Commands and options.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,22 @@ $ eask [GLOBAL-OPTIONS] clean dist
356356

357357
Alias: `distribution`
358358

359+
## 🔍 eask clean log-file
360+
361+
Remove all generated log files.
362+
363+
```sh
364+
$ eask [GLOBAL-OPTIONS] clean log-file
365+
```
366+
359367
## 🔍 eask clean all
360368

361-
This command is combination of all other clean commands.
369+
This command is the combination of all other clean commands.
362370

363-
* `clean workspace`
364-
* `clean elc`
365-
* `clean dist`
371+
- `clean workspace`
372+
- `clean elc`
373+
- `clean dist`
374+
- `clean log-file`
366375

367376
```sh
368377
$ eask [GLOBAL-OPTIONS] clean all

lisp/clean/all.el

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
(eask-with-progress
3535
"Cleaning dist... \n"
3636
(eask-call "clean/dist")
37+
(if eask-no-cleaning-operation-p "skipped ✗" "done ✓")))
38+
(eask-msg "")
39+
(let (eask-no-cleaning-operation-p)
40+
(eask-with-progress
41+
"Cleaning log files... \n"
42+
(eask-call "clean/log-file")
3743
(if eask-no-cleaning-operation-p "skipped ✗" "done ✓"))))
3844

3945
;;; clean/all.el ends here

lisp/clean/elc.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
;;; clean/elc.el --- Remove byte compiled files generated by cask build -*- lexical-binding: t; -*-
1+
;;; clean/elc.el --- Remove byte compiled files generated by eask compile -*- lexical-binding: t; -*-
22

33
;;; Commentary:
44
;;
5-
;; Remove byte compiled files generated by cask build
5+
;; Remove byte compiled files generated by eask compile
66
;;
77
;; $ eask clean elc
88
;;

lisp/clean/log-file.el

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
;;; clean/log-file.el --- Remove all generated log files -*- lexical-binding: t; -*-
2+
3+
;;; Commentary:
4+
;;
5+
;; Remove all generated log files,
6+
;;
7+
;; $ eask clean log-file
8+
;;
9+
10+
;;; Code:
11+
12+
(load (expand-file-name
13+
"../_prepare.el"
14+
(file-name-directory (nth 1 (member "-scriptload" command-line-args))))
15+
nil t)
16+
17+
(defmacro eask--log-remove (file)
18+
"Remove log FILE."
19+
`(ignore-errors (delete-file (expand-file-name ,file log-dir))))
20+
21+
(defun eask--delete-log-file (file log-dir count)
22+
"Delete a log FILE."
23+
(when (eask-delete-file (expand-file-name file log-dir))
24+
(cl-incf count))
25+
count)
26+
27+
(eask-start
28+
(let ((log-dir (expand-file-name eask-log-path eask-file-root))
29+
(deleted 0)
30+
(log-files '("messages.log"
31+
"warnings.log"
32+
"backtrace.log"
33+
"compile-log.log")))
34+
(dolist (log-file log-files)
35+
(setq deleted (eask--delete-log-file log-file log-dir deleted)))
36+
(eask-msg "")
37+
(if (not (zerop deleted))
38+
(eask-info "(Total of %s log file%s deleted, %s skipped)" deleted
39+
(eask--sinr deleted "" "s")
40+
(- (length log-files) deleted))
41+
(eask-info "(No log file found in workspace)")
42+
(setq eask-no-cleaning-operation-p t))))
43+
44+
;;; clean/log-file.el ends here

test/commands/local/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ eask test activate
7171
eask clean .eask
7272
eask clean elc
7373
eask clean dist
74+
eask clean log-file
7475
eask clean all
7576

7677
# Util

0 commit comments

Comments
 (0)