Skip to content

Commit 63ed3c2

Browse files
authored
fix: Improve file expand error message (#102)
* fix: Improve file expand error message * fix * show help on fail * comment * print no issue for relint
1 parent 3b1fbd5 commit 63ed3c2

File tree

21 files changed

+319
-180
lines changed

21 files changed

+319
-180
lines changed

cmds/checker/check-eask.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ exports.builder = {
4141
exports.handler = async (argv) => {
4242
await UTIL.e_call(argv, 'checker/check-eask'
4343
, argv.files
44-
, UTIL.def_flag(argv.json, '--json', argv.json));
44+
, UTIL.def_flag(argv.json, '--json', argv.json)
45+
, UTIL.def_flag(argv.output, '--output', argv.output));
4546
};

cmds/core/clean.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ exports.builder = function (yargs) {
2626
.usage(`${exports.desc}
2727
2828
Usage: eask clean <command> [options..]`)
29-
.commandDir('../clean/');
29+
.commandDir('../clean/')
30+
.demandCommand();
3031
};
3132

3233
exports.handler = async (argv) => { };

cmds/core/concat.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@ exports.builder = {
3232
requiresArg: true,
3333
alias: 'dest',
3434
type: 'string',
35-
}
35+
},
36+
output: {
37+
description: 'Output result to a file',
38+
alias: 'o',
39+
type: 'string',
40+
},
3641
};
3742

3843
exports.handler = async (argv) => {
3944
await UTIL.e_call(argv, 'core/concat'
4045
, argv.names
41-
, UTIL.def_flag(argv.dest, '--dest', argv.dest));
46+
, UTIL.def_flag(argv.dest, '--dest', argv.dest)
47+
, UTIL.def_flag(argv.output, '--output', argv.output));
4248
};

cmds/core/create.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ exports.builder = function (yargs) {
2626
.usage(`${exports.desc}
2727
2828
Usage: eask create <command> [options..]`)
29-
.commandDir('../create/');
29+
.commandDir('../create/')
30+
.demandCommand();
3031
};
3132

3233
exports.handler = async (argv) => { };

cmds/core/lint.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ exports.builder = function (yargs) {
2626
.usage(`${exports.desc}
2727
2828
Usage: eask lint <command> [options..]`)
29-
.commandDir('../lint/');
29+
.commandDir('../lint/')
30+
.demandCommand();
3031
};
3132

3233
exports.handler = async (argv) => { };

cmds/core/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ exports.builder = function (yargs) {
2626
.usage(`${exports.desc}
2727
2828
Usage: eask test <command> [options..]`)
29-
.commandDir('../test/');
29+
.commandDir('../test/')
30+
.demandCommand();
3031
};
3132

3233
exports.handler = async (argv) => { };

lisp/_prepare.el

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ the `eask-start' execution.")
444444
(defun eask-json-p () (eask--flag "--json")) ; --json
445445

446446
;;; String (with arguments)
447-
(defun eask-output () (eask--flag-value "-o")) ; --o, --output
447+
(defun eask-output () (eask--flag-value "--output")) ; --o, --output
448448
(defun eask-proxy () (eask--flag-value "--proxy")) ; --proxy
449449
(defun eask-http-proxy () (eask--flag-value "--http-proxy")) ; --http-proxy
450450
(defun eask-https-proxy () (eask--flag-value "--https-proxy")) ; --https-proxy
@@ -511,7 +511,7 @@ other scripts internally. See function `eask-call'.")
511511

512512
(defconst eask--option-args
513513
(eask--form-options
514-
'("-o"
514+
'("--output"
515515
"--proxy" "--http-proxy" "--https-proxy" "--no-proxy"
516516
"--verbose" "--silent"
517517
"--depth" "--dest"))
@@ -1128,12 +1128,6 @@ Standard is, 0 (error), 1 (warning), 2 (info), 3 (log), 4 or above (debug)."
11281128
(setq elcs (cl-remove-if-not (lambda (elm) (file-exists-p elm)) elcs))
11291129
elcs))
11301130

1131-
(defun eask-args-or-package-el-files ()
1132-
"Return args if specified, else return package files by default."
1133-
(if (eask-args)
1134-
(eask-expand-file-specs (eask-args))
1135-
(eask-package-el-files)))
1136-
11371131
(defun eask-package-multi-p ()
11381132
"Return t if multi-files package."
11391133
(< 1 (length (eask-package-files))))
@@ -1225,12 +1219,6 @@ Standard is, 0 (error), 1 (warning), 2 (info), 3 (log), 4 or above (debug)."
12251219
(eask-msg (ansi-white (buffer-string)))))
12261220
(eask-error "Help manual missig %s" help-file))))
12271221

1228-
(defun eask--print-no-matching-files ()
1229-
"Print message for no matching files found."
1230-
(eask-log "")
1231-
(eask-log "Cannot find matching files with given pattern %s" (eask-args))
1232-
(eask-log ""))
1233-
12341222
;;
12351223
;;; Checker
12361224

lisp/checker/check-eask.el

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,42 @@
104104
eask-depends-on-dev)
105105
,@body))
106106

107+
(defun eask--check-file (files)
108+
"Lint list of Eask FILES."
109+
(let (checked-files content)
110+
;; Linting
111+
(dolist (file files)
112+
(eask--save-eask-file-state
113+
(eask--setup-env
114+
(eask--alias-env
115+
(when (ignore-errors (load file 'noerror t))
116+
(push file checked-files))))))
117+
118+
;; Print result
119+
(eask-msg "")
120+
(cond ((and (eask-json-p) ; JSON format
121+
(or eask--checker-warnings eask--checker-errors))
122+
(setq content
123+
(eask--pretty-json (json-encode
124+
`((warnings . ,eask--checker-warnings)
125+
(errors . ,eask--checker-errors)))))
126+
(eask-msg content))
127+
(eask--checker-log ; Plain text
128+
(setq content
129+
(with-temp-buffer
130+
(dolist (msg (reverse eask--checker-log))
131+
(insert msg "\n"))
132+
(buffer-string)))
133+
(mapc #'eask-msg (reverse eask--checker-log)))
134+
(t
135+
(eask-info "(Checked %s file%s)"
136+
(length checked-files)
137+
(eask--sinr checked-files "" "s"))))
138+
139+
;; Output file
140+
(when (and content (eask-output))
141+
(write-region content nil (eask-output)))))
142+
107143
;;
108144
;;; Program Entry
109145

@@ -113,41 +149,21 @@
113149

114150
(let* ((default-directory (if (eask-global-p) user-emacs-directory
115151
default-directory))
116-
(files (or (eask-expand-file-specs (eask-args))
117-
(eask-expand-file-specs '("Eask*" "**/Eask*"))))
118-
checked-files
119-
content)
120-
;; Linting
121-
(dolist (file files)
122-
(eask--save-eask-file-state
123-
(eask--setup-env
124-
(eask--alias-env
125-
(when (ignore-errors (load file 'noerror t))
126-
(push file checked-files))))))
127-
128-
;; Print result
129-
(eask-msg "")
130-
(cond ((and (eask-json-p) ; JSON format
131-
(or eask--checker-warnings eask--checker-errors))
132-
(setq content
133-
(eask--pretty-json (json-encode
134-
`((warnings . ,eask--checker-warnings)
135-
(errors . ,eask--checker-errors)))))
136-
(eask-msg content))
137-
(eask--checker-log ; Plain text
138-
(setq content
139-
(with-temp-buffer
140-
(dolist (msg (reverse eask--checker-log))
141-
(insert msg "\n"))
142-
(buffer-string)))
143-
(mapc #'eask-msg (reverse eask--checker-log)))
144-
(t
145-
(eask-info "(Checked %s file%s)"
146-
(length checked-files)
147-
(eask--sinr checked-files "" "s"))))
148-
149-
;; Output file
150-
(when (and content (eask-output))
151-
(write-region content nil (eask-output))))
152+
(patterns (eask-args))
153+
(files (if patterns
154+
(eask-expand-file-specs patterns)
155+
(eask-expand-file-specs '("Eask*" "**/Eask*")))))
156+
(cond
157+
;; Files found, do the action!
158+
(files
159+
(eask--check-file files))
160+
;; Pattern defined, but no file found!
161+
(patterns
162+
(eask-info "No files found with wildcard pattern: %s"
163+
(mapconcat #'identity patterns " ")))
164+
;; Default, print help!
165+
(t
166+
(eask-info "(No Eask-files have been checked)")
167+
(eask-help "checker/check-eask"))))
152168

153169
;;; checker/check-eask.el ends here

lisp/core/compile.el

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,21 @@
6565

6666
(eask-start
6767
(eask-defvc< 27 (eask-pkg-init)) ; XXX: remove this after we drop 26.x
68-
(if-let ((files (or (eask-expand-file-specs (eask-args))
69-
(eask-package-el-files))))
70-
(eask--compile-files files)
71-
(eask-info "(No files have been compiled)")
72-
(eask-help "core/compile")))
68+
(let* ((patterns (eask-args))
69+
(files (if patterns
70+
(eask-expand-file-specs patterns)
71+
(eask-package-el-files))))
72+
(cond
73+
;; Files found, do the action!
74+
(files
75+
(eask--compile-files files))
76+
;; Pattern defined, but no file found!
77+
(patterns
78+
(eask-info "No files found with wildcard pattern: %s"
79+
(mapconcat #'identity patterns " ")))
80+
;; Default, print help!
81+
(t
82+
(eask-info "(No files have been compiled)")
83+
(eask-help "core/compile")))))
7384

7485
;;; core/compile.el ends here

lisp/core/concat.el

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
;; Action options:
1515
;;
1616
;; [destination] optional output destination
17+
;; [output] optional output filename
1718
;;
1819

1920
;;; Code:
@@ -25,23 +26,36 @@
2526

2627
(eask-start
2728
(let* ((name (eask-guess-package-name))
28-
(files (or (eask-expand-file-specs (eask-args))
29-
(eask-package-el-files)))
29+
(patterns (eask-args))
30+
(files (if patterns (eask-expand-file-specs patterns)
31+
(eask-package-el-files)))
3032
(eask-dist-path (or (eask-dest) eask-dist-path))
3133
(eask-dist-path (expand-file-name eask-dist-path))
3234
(target-file (concat name ".built.el"))
33-
(target-filename (expand-file-name target-file eask-dist-path)))
34-
(eask-debug "Destination path in %s" eask-dist-path)
35-
(ignore-errors (make-directory eask-dist-path t))
35+
(target-filename (or (and (eask-output) (expand-file-name (eask-output)))
36+
(expand-file-name target-file eask-dist-path))))
37+
(cond
38+
;; Files found, do the action!
39+
(files
40+
(eask-debug "Destination path in %s" eask-dist-path)
41+
(ignore-errors (make-directory eask-dist-path t))
3642

37-
(eask-info "Prepare to concatenate files %s..." target-filename)
38-
(write-region "" nil target-filename)
43+
(eask-info "Prepare to concatenate files %s..." target-filename)
44+
(write-region "" nil target-filename)
3945

40-
(eask-with-verbosity 'log
41-
(with-temp-buffer
42-
(eask-progress-seq " - Visiting" files "appended! ✓" #'insert-file-contents)
43-
(write-region (buffer-string) nil target-filename)
44-
(eask-msg "")
45-
(eask-info "Done. (Wrote file in %s)" target-filename)))))
46+
(eask-with-verbosity 'log
47+
(with-temp-buffer
48+
(eask-progress-seq " - Visiting" files "appended! ✓" #'insert-file-contents)
49+
(write-region (buffer-string) nil target-filename)
50+
(eask-msg "")
51+
(eask-info "Done. (Wrote file in %s)" target-filename))))
52+
;; Pattern defined, but no file found!
53+
(patterns
54+
(eask-info "No files found with wildcard pattern: %s"
55+
(mapconcat #'identity patterns " ")))
56+
;; Default, print help!
57+
(t
58+
(eask-info "(No files have been concatenated)")
59+
(eask-help "core/concat")))))
4660

4761
;;; core/concat.el ends here

0 commit comments

Comments
 (0)