Skip to content

Commit

Permalink
feat: Add loc command (#227)
Browse files Browse the repository at this point in the history
* feat: Add loc command

* Add test for loc command

* comment out test
  • Loading branch information
jcs090218 authored Feb 20, 2024
1 parent 5468053 commit 6510311
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 1 deletion.
31 changes: 31 additions & 0 deletions cmds/core/loc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (C) 2024 the Eask authors.
*
* 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/

"use strict";

exports.command = ['loc [files..]'];
exports.desc = UTIL.hide_cmd('Print LOC information');
exports.builder = yargs => yargs
.positional(
'[files..]', {
description: 'files to print LOC information',
type: 'array',
});

exports.handler = async (argv) => {
await UTIL.e_call(argv, 'core/loc', argv.files);
};
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,14 @@ Concatenate all Emacs Lisp files into one file.
$ eask [GLOBAL-OPTIONS] concate [FILES..]
```

## 🔍 eask loc

Print LOC information.

```sh
$ eask [GLOBAL-OPTIONS] loc [FILES..]
```

# 🚩 Execution

Commands allow you to execute on top of the Eask core.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ $ eask [GLOBAL-OPTIONS] cat [PATTERNS..]
$ eask [GLOBAL-OPTIONS] concate [FILES..]
```

## 🔍 eask loc

列印 LOC 信息。

```sh
$ eask [GLOBAL-OPTIONS] loc [FILES..]
```

# 🚩 執行

指令允許執行在 Eask 核心之上。
Expand Down
5 changes: 5 additions & 0 deletions lisp/core/load.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
;;
;; $ eask load
;;
;;
;; Positionals:
;;
;; [files..] specify files to load
;;

;;; Code:

Expand Down
68 changes: 68 additions & 0 deletions lisp/core/loc.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
;;; core/loc.el --- Print LOC information -*- lexical-binding: t; -*-

;;; Commentary:
;;
;; Command use to print loc (accept multiple)
;;
;; $ eask loc
;;
;;
;; Positionals:
;;
;; [files..] specify files to print LOC information
;;

;;; 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))

(defvar eask-loc-lines 0)
(defvar eask-loc-chars 0)

(defun eask--loc-file (file)
"Insert LOC information for FILE."
(unless (file-directory-p file)
(let ((lines) (chars))
(with-temp-buffer
(insert-file-contents file)
(setq lines (line-number-at-pos (point-max))
chars (point-max)))
(cl-incf eask-loc-lines lines)
(cl-incf eask-loc-chars chars)
(insert (format "| %s | %s | %s |\n" file lines chars)))))

(eask-start
;; Preparation
(eask-with-archives '("gnu" "melpa")
(eask-package-install 'markdown-mode))

(require 'markdown-mode)
;; Start LOC
(if-let ((files (or (eask-expand-file-specs (eask-args))
(eask-package-files)))
(eask-output (get-buffer-create "*eask-output*")))
(with-current-buffer eask-output
(erase-buffer)
(progn ; Print header
(insert (format "|---|---|---|\n"))
(insert (format "| File | Lines | Characters |\n"))
(insert (format "|---|---|---|\n")))
(eask-with-progress
"Retrieving LOC information... "
(mapc #'eask--loc-file files)
"done ✓")
(progn ; Print total
(insert (format "|---|---|---|\n"))
(insert (format "| Total | %s | %s |\n" eask-loc-lines eask-loc-chars)))
(progn ; Organize
(goto-char (point-min))
(markdown-table-align))
(eask-println "")
(eask-print (buffer-string))
(eask-println ""))
(eask-info "(No LOC information to print.)")))

;;; core/loc.el ends here
4 changes: 3 additions & 1 deletion test/commands/local/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ eask status
eask archives
eask archives --all
eask list --depth=0
eask bump major minor patch
eask cat package.json --insecure
eask cat package.json --number --insecure
eask concat
eask bump major minor patch
#eask loc # Only 27.1+
#eask loc Eask # Only 27.1+

# PATH environment
eask path
Expand Down

0 comments on commit 6510311

Please sign in to comment.