From 3cdf0389aec96e85ec84ba5d80652d69c32a4eca Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sun, 12 Nov 2023 19:08:59 -0800 Subject: [PATCH 1/4] feat(source): Add source and its subcommands --- CHANGELOG.md | 1 + cmds/core/source.js | 38 +++++++ cmds/link/delete.js | 2 +- cmds/source/add.js | 36 +++++++ cmds/source/delete.js | 32 ++++++ cmds/source/list.js | 26 +++++ .../en/Getting-Started/Basic-Usage/_index.md | 1 + .../Getting-Started/Commands-and-options.md | 58 ++++++++--- .../en/Getting-Started/Introduction.md | 4 +- .../Getting-Started/Basic-Usage/_index.md | 1 + .../Getting-Started/Commands-and-options.md | 65 +++++++++--- lisp/help/source/add | 7 ++ lisp/help/source/delete | 4 + lisp/source/add.el | 99 +++++++++++++++++++ lisp/source/delete.el | 39 ++++++++ lisp/source/list.el | 20 ++++ src/util.js | 21 ++-- 17 files changed, 416 insertions(+), 38 deletions(-) create mode 100644 cmds/core/source.js create mode 100644 cmds/source/add.js create mode 100644 cmds/source/delete.js create mode 100644 cmds/source/list.js create mode 100644 lisp/help/source/add create mode 100644 lisp/help/source/delete create mode 100644 lisp/source/add.el create mode 100644 lisp/source/delete.el create mode 100644 lisp/source/list.el diff --git a/CHANGELOG.md b/CHANGELOG.md index 6100c6ce..1ceb6106 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how * Add command `commnad` for custom commands (#195) * Merge the two commands `run` and `command` (#196) * Add `melpazoid` command (#202) +* Add `source` command and its subcommands (#203) ## 0.8.x > Released Mar 08, 2023 diff --git a/cmds/core/source.js b/cmds/core/source.js new file mode 100644 index 00000000..7ad46049 --- /dev/null +++ b/cmds/core/source.js @@ -0,0 +1,38 @@ +/** + * Copyright (C) 2023 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 . + */ + +"use strict"; + +exports.command = ['source ']; +exports.desc = UTIL.hide_cmd('Add/Remove source from DSL'); +exports.builder = function (yargs) { + yargs.usage(`${exports.desc} + +Usage: eask source [options..]`) + .commandDir('../source/') + .demandCommand(); + + /* XXX: Configure only in the menu. */ + if (UTIL.cmd_count() == 1) { + yargs.positional( + '', { + description: 'type of the control', + }); + } +} + +exports.handler = async (argv) => {}; diff --git a/cmds/link/delete.js b/cmds/link/delete.js index 0bd5d171..c25c370a 100644 --- a/cmds/link/delete.js +++ b/cmds/link/delete.js @@ -17,7 +17,7 @@ "use strict"; -exports.command = ['delete [names..]']; +exports.command = ['delete [names..]', 'remove [names..]']; exports.desc = 'Delete local linked packages'; exports.builder = yargs => yargs .positional( diff --git a/cmds/source/add.js b/cmds/source/add.js new file mode 100644 index 00000000..256bc8c4 --- /dev/null +++ b/cmds/source/add.js @@ -0,0 +1,36 @@ +/** + * Copyright (C) 2023 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 . + */ + +"use strict"; + +exports.command = ['add [url]']; +exports.desc = 'Add an archive source'; +exports.builder = yargs => yargs + .positional( + '', { + description: 'name of the archive', + type: 'array', + }) + .positional( + '[url]', { + description: 'link to the archive', + type: 'string', + }); + +exports.handler = async (argv) => { + await UTIL.e_call(argv, 'source/add', argv.name, argv.url); +}; diff --git a/cmds/source/delete.js b/cmds/source/delete.js new file mode 100644 index 00000000..1e16b78a --- /dev/null +++ b/cmds/source/delete.js @@ -0,0 +1,32 @@ +/** + * Copyright (C) 2023 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 . + */ + +"use strict"; + +exports.command = ['delete ', 'remove ']; +exports.desc = 'Remove an archive source'; +exports.builder = yargs => yargs + .positional( + '', { + description: 'name of the archive', + type: 'array', + }); + +exports.handler = async (argv) => { + await UTIL.e_call(argv, 'source/delete', argv.name); +}; + diff --git a/cmds/source/list.js b/cmds/source/list.js new file mode 100644 index 00000000..51672e29 --- /dev/null +++ b/cmds/source/list.js @@ -0,0 +1,26 @@ +/** + * Copyright (C) 2023 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 . + */ + +"use strict"; + +exports.command = ['list']; +exports.desc = 'List all source information'; + +exports.handler = async (argv) => { + await UTIL.e_call(argv, 'source/list'); +}; + diff --git a/docs/content/en/Getting-Started/Basic-Usage/_index.md b/docs/content/en/Getting-Started/Basic-Usage/_index.md index 785c89d5..ad222eee 100644 --- a/docs/content/en/Getting-Started/Basic-Usage/_index.md +++ b/docs/content/en/Getting-Started/Basic-Usage/_index.md @@ -146,6 +146,7 @@ Here is a list of known nested subcommands: - eask link - eask lint - eask run +- eask source - eask test ## ๐Ÿ“Œ Knowing your `elpa` directory diff --git a/docs/content/en/Getting-Started/Commands-and-options.md b/docs/content/en/Getting-Started/Commands-and-options.md index 9927d142..ef165edf 100644 --- a/docs/content/en/Getting-Started/Commands-and-options.md +++ b/docs/content/en/Getting-Started/Commands-and-options.md @@ -328,12 +328,12 @@ $ eask [GLOBAL-OPTIONS] run script [NAMES..] Run the command. +Alias: `cmd` + ```sh $ eask [GLOBAL-OPTIONS] run command [NAMES..] ``` -Alias: `cmd` - ## ๐Ÿ” eask docker Launch specified Emacs version in a Docker container. @@ -540,6 +540,8 @@ $ eask [GLOBAL-OPTIONS] link add Deletes the link for the given packages. +Alias: `remove` + ```sh $ eask [GLOBAL-OPTIONS] link delete [names..] ``` @@ -558,6 +560,8 @@ $ eask [GLOBAL-OPTIONS] link list Delete `.eask` from the current workspace. +Alias: `.eask` + ```sh $ eask [GLOBAL-OPTIONS] clean workspace ``` @@ -568,8 +572,6 @@ $ eask [GLOBAL-OPTIONS] clean workspace $ eask clean workspace -g ``` -Alias: `.eask` - ## ๐Ÿ” eask clean elc Delete all `.elc` files. This would respect to your `Eask` file. @@ -582,12 +584,12 @@ $ eask [GLOBAL-OPTIONS] clean elc Delete dist subdirectory. +Alias: `distribution` + ```sh $ eask [GLOBAL-OPTIONS] clean dist ``` -Alias: `distribution` - ## ๐Ÿ” eask clean autoloads Remove generated autoloads file. @@ -623,13 +625,13 @@ This command is the combination of all other clean commands. - `clean pkg-file` - `clean log-file` +Alias: `everything` + ```sh $ eask [GLOBAL-OPTIONS] clean all ``` -Alias: `everything` - -# ๐Ÿšฉ Linter +# ๐Ÿšฉ Linting Commands that lint your Emacs package. @@ -711,12 +713,12 @@ $ eask [GLOBAL-OPTIONS] lint declare [FILES..] Run [relint](https://github.com/mattiase/relint). +Alias: `lint relint` + ```sh $ eask [GLOBAL-OPTIONS] lint regexps [FILES..] ``` -Alias: `lint relint` - # ๐Ÿšฉ Testing ## ๐Ÿ” eask test activate @@ -769,6 +771,40 @@ $ eask [GLOBAL-OPTIONS] test melpazoid [DIRECTORIES..] ๐Ÿ’ก If **[DIRECTORIES..]** is not passed in; it will use the current workspace instead. {{< /hint >}} +# ๐Ÿšฉ Control DSL + +List of commands that control DSL. + +## ๐Ÿ” eask source add + +Add an archive source. + +```sh +$ eask [GLOBAL-OPTIONS] source add [URL] +``` + +## ๐Ÿ” eask source delete + +Remove an archive source. + +Alias: `remove` + +```sh +$ eask [GLOBAL-OPTIONS] source delete +``` + +## ๐Ÿ” eask source list + +List all source information. + +```sh +$ eask [GLOBAL-OPTIONS] source list +``` + +{{< hint info >}} +๐Ÿ’ก This command is the same as `$ eask archives`! +{{< /hint >}} + # ๐Ÿšฉ Utilities Other helper commands. diff --git a/docs/content/en/Getting-Started/Introduction.md b/docs/content/en/Getting-Started/Introduction.md index 04a2177a..e3d4cee4 100644 --- a/docs/content/en/Getting-Started/Introduction.md +++ b/docs/content/en/Getting-Started/Introduction.md @@ -114,11 +114,11 @@ list. ### ๐Ÿ” Core commands -- [ ] [FEAT] Add `publish` command; to publish package to eask archive? +- [ ] [FEAT] Add `publish` command; to publish the package to the eask archive? ### ๐Ÿ” Eask-file commands -- [ ] [FEAT] Add `add-source` command +- [x] [FEAT] Add `source add` command ## ๐Ÿ“‚ Underlying Projects diff --git a/docs/content/zh-TW/Getting-Started/Basic-Usage/_index.md b/docs/content/zh-TW/Getting-Started/Basic-Usage/_index.md index 0a6a0e69..fca68134 100644 --- a/docs/content/zh-TW/Getting-Started/Basic-Usage/_index.md +++ b/docs/content/zh-TW/Getting-Started/Basic-Usage/_index.md @@ -141,6 +141,7 @@ Positionals: - eask link - eask lint - eask run +- eask source - eask test ## ๐Ÿ“Œ ไบ†่งฃไฝ ็š„ `elpa` ็›ฎ้Œ„ diff --git a/docs/content/zh-TW/Getting-Started/Commands-and-options.md b/docs/content/zh-TW/Getting-Started/Commands-and-options.md index 766efbbb..515f57a8 100644 --- a/docs/content/zh-TW/Getting-Started/Commands-and-options.md +++ b/docs/content/zh-TW/Getting-Started/Commands-and-options.md @@ -324,12 +324,12 @@ $ eask [GLOBAL-OPTIONS] run script [NAMES..] ้‹่กŒๆŒ‡ไปคใ€‚ +ๅˆฅๅ: `cmd` + ```sh $ eask [GLOBAL-OPTIONS] run command [NAMES..] ``` -ๅˆฅๅ: `cmd` - ## ๐Ÿ” eask docker ๅœจ Docker ๅฎนๅ™จไธญๅ•Ÿๅ‹•ๆŒ‡ๅฎš็š„ Emacs ็‰ˆๆœฌ @@ -352,7 +352,7 @@ $ eask docker 26.1 info ## ๐Ÿ” eask archives -ๅˆ—ๅ‡บๆ‰€ๆœ‰ๅŒ…ๆช”ๆกˆใ€‚ +ๅˆ—ๅ‡บๆ‰€ๆœ‰ๅŒ…ๆบใ€‚ ```sh $ eask [GLOBAL-OPTIONS] archives @@ -360,7 +360,7 @@ $ eask [GLOBAL-OPTIONS] archives ## ๐Ÿ” eask search -ๅพžๆช”ๆกˆไธญๆœ็ดขๅŒ…ใ€‚ +ๅพžๅŒ…ๆบไธญๆœ็ดขๅŒ…ใ€‚ ```sh $ eask [GLOBAL-OPTIONS] search [QUEIRES..] @@ -392,7 +392,7 @@ $ eask [GLOBAL-OPTIONS] outdated [--depth] ## ๐Ÿ” eask refresh -ๅˆทๆ–ฐๅŒ… archivesใ€‚ +ๅˆทๆ–ฐๅŒ…ๆบใ€‚ ```sh $ eask [GLOBAL-OPTIONS] refresh @@ -527,6 +527,8 @@ $ eask [GLOBAL-OPTIONS] link add ๅˆช้™ค็ตฆๅฎšๅŒ…็š„้ˆๆŽฅใ€‚ +ๅˆฅๅ: `remove` + ```sh $ eask [GLOBAL-OPTIONS] link delete [names..] ``` @@ -545,19 +547,18 @@ $ eask [GLOBAL-OPTIONS] link list ๅพž็•ถๅ‰ๅทฅไฝœๅ€ไธญๅˆช้™ค `.eask` ใ€‚ +ๅˆฅๅ: `.eask` + ```sh $ eask [GLOBAL-OPTIONS] clean workspace ``` โ›”๏ธ ไธ่ฆๆŒ‡ๅฎš้ธ้ … `--config, -c`๏ผŒๅฆๅ‰‡ๅฎƒๆœƒๅˆช้™คไฝ ็š„ๆ•ดๅ€‹ `~/.emacs.d`ใ€‚ - ```elisp $ eask clean workspace -g ``` -ๅˆฅๅ: `.eask` - ## ๐Ÿ” eask clean elc ๅˆช้™คๆ‰€ๆœ‰ `.elc` ๆ–‡ไปถใ€‚ ้€™ๅฐ‡ๅฐŠ้‡ๆ‚จ็š„ `Eask` ๆ–‡ไปถใ€‚ @@ -570,12 +571,12 @@ $ eask [GLOBAL-OPTIONS] clean elc ๅˆช้™ค dist ๅญ็›ฎ้Œ„ใ€‚ +ๅˆฅๅ: `distribution` + ```sh $ eask [GLOBAL-OPTIONS] clean dist ``` -ๅˆฅๅ: `distribution` - ## ๐Ÿ” eask clean autoloads ๅˆช้™ค็”Ÿๆˆ็š„ autoload ๆ–‡ไปถใ€‚ @@ -611,13 +612,13 @@ $ eask [GLOBAL-OPTIONS] clean log-file - `clean pkg-file` - `clean log-file` +ๅˆฅๅ: `everything` + ```sh $ eask [GLOBAL-OPTIONS] clean all ``` -ๅˆฅๅ: `everything` - -# ๐Ÿšฉ ๆฃ€ๆŸฅๅ™จ +# ๐Ÿšฉ ๆฃ€ๆŸฅ ๅฐ Emacs ๅŒ…้€ฒ่กŒ lint ็š„ๅ‘ฝไปคใ€‚ @@ -699,12 +700,12 @@ $ eask [GLOBAL-OPTIONS] lint declare [FILES..] Run [relint](https://github.com/mattiase/relint). +ๅˆฅๅ: `lint relint` + ```sh $ eask [GLOBAL-OPTIONS] lint regexps [FILES..] ``` -ๅˆฅๅ: `lint relint` - # ๐Ÿšฉ ๆธฌ่ฉฆๆก†ๆžถ ## ๐Ÿ” eask test activate @@ -757,6 +758,40 @@ $ eask [GLOBAL-OPTIONS] test melpazoid [DIRECTORIES..] ๐Ÿ’ก ๅฆ‚ๆžœๆœชๅ‚ณๅ…ฅ **[DIRECTORIES..]**๏ผŒๅฎƒๅฐ‡ไฝฟ็”จ็›ฎๅ‰ๅทฅไฝœ็ฉบ้–“ใ€‚ {{< /hint >}} +# ๐Ÿšฉ ๆŽงๅˆถ DSL + +ๆŽงๅˆถ DSL ็š„ๆŒ‡ไปคๅˆ—่กจใ€‚ + +## ๐Ÿ” eask source add + +ๆ–ฐๅขžไธ€ๅ€‹ๅŒ…ๆบใ€‚ + +```sh +$ eask [GLOBAL-OPTIONS] source add [URL] +``` + +## ๐Ÿ” eask source delete + +็งป้™คไธ€ๅ€‹ๅŒ…ๆบใ€‚ + +ๅˆฅๅ: `remove` + +```sh +$ eask [GLOBAL-OPTIONS] source delete +``` + +## ๐Ÿ” eask source list + +ๅˆ—ๅ‡บๆ‰€ๆœ‰ๅŒ…ๆบใ€‚ + +```sh +$ eask [GLOBAL-OPTIONS] source list +``` + +{{< hint info >}} +๐Ÿ’ก ๆŒ‡ไปค่ˆ‡ `$ eask archives` ็›ธๅŒ! +{{< /hint >}} + # ๐Ÿšฉ ๅฏฆ็”จๅทฅๅ…ท ๅ…ถไป–่ผ”ๅŠฉๅ‘ฝไปคใ€‚ diff --git a/lisp/help/source/add b/lisp/help/source/add new file mode 100644 index 00000000..bd897e92 --- /dev/null +++ b/lisp/help/source/add @@ -0,0 +1,7 @@ + +๐Ÿ’ก The given source name is not found in our database. You have following options: + +Options are, + + - [ ] Pass in one extra argument to specify an `[url]` + - [ ] Edit variable `eask-source-mapping` and create a pull request to https://github.com/emacs-eask/cli diff --git a/lisp/help/source/delete b/lisp/help/source/delete new file mode 100644 index 00000000..58ad8f0b --- /dev/null +++ b/lisp/help/source/delete @@ -0,0 +1,4 @@ + +๐Ÿ’ก The given source name is not found in your Eask-file. List all the archives with: + + $ eask source list diff --git a/lisp/source/add.el b/lisp/source/add.el new file mode 100644 index 00000000..94bf39d0 --- /dev/null +++ b/lisp/source/add.el @@ -0,0 +1,99 @@ +;;; source/add.el --- Add an archive source -*- lexical-binding: t; -*- + +;;; Commentary: +;; +;; Commmand use to add an archive source +;; +;; $ eask source add +;; +;; +;; Positionals: +;; +;; name of the archive +;; link to the archive +;; + +;;; 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--source-add (name url exists) + "Add an archive source by NAME. + +If argument URL is nil; ignore the insertion. + +Arguments EXISTS is used to print the information." + (let* ((style-sym (string-match "([ \t\n\r]*source[ \t\n\r]*[']+" (buffer-string))) + (name-str (if style-sym (concat "'" name) + (concat "\"" name "\"")))) + (if url + (insert "(source " name-str " \"" url "\")\n") + (insert "(source " name-str ")\n")) + (eask-info "(New source `%s' added and points to `%s')" name (or url (cdr exists))))) + +(defun eask--source-write (name url exists) + "Write source construct by NAME and URL. + +The argument URL can be nil. + +The argument EXISTS is use to search for correct position to insert new source." + (with-current-buffer (find-file eask-file) + (goto-char (point-min)) + (cond + (exists + (if (re-search-forward (concat "([ \t\n\r]*source[ \t\n\r]*['\"]+" name) nil t) + (progn + (re-search-forward "[ \t\r\n]*" nil t) ; Forward to non-space characters! + (pcase (string (char-after)) + (")" + (insert " \"" url "\"")) + ("\"" + (let ((old (thing-at-point 'string)) + (new (concat "\"" url "\""))) + (delete-region (point) (+ (point) (length old))) + (insert new)))) + (eask-info "(Changed archive `%s's location from `%s' to `%s')" + name (cdr exists) url)) + (goto-char (point-max)) + (eask--source-add name url exists))) + (t + (if (re-search-forward "([ \t\n\r]*source[ \t\n\r]*['\"]+" nil t) + (forward-paragraph) + (goto-char (point-max))) + (eask--source-add name url exists))) + (save-buffer))) + +(defun eask--source-ask-if-overwrite (name url) + "Ask source overwrite if needed. + +Arguments NAME and URL are main arguments for this command." + (if-let ((exists (assoc name package-archives)) + (old-url (cdr exists))) + (if (and (not (string= old-url url)) + (yes-or-no-p + (format + (concat + "The archive `%s' is already exists and currently points to `%s'. + +Do you want to overwrite it? ") + name old-url))) + (eask--source-write name url exists) + (eask-info "(Nothing has changed due to the URLs are the same)")) + (eask--source-write name url nil))) + +(eask-start + (let* ((args (eask-args)) + (name (nth 0 args)) + (url (nth 1 args))) + (cond + (url (eask--source-ask-if-overwrite name url)) + (t + (if-let ((archive (assoc (eask-intern name) eask-source-mapping))) + (eask--source-ask-if-overwrite name url) + (eask-info "(Invalid source name, `%s')" name) + (eask-help "source/add")))))) + +;;; source/add.el ends here diff --git a/lisp/source/delete.el b/lisp/source/delete.el new file mode 100644 index 00000000..67173d21 --- /dev/null +++ b/lisp/source/delete.el @@ -0,0 +1,39 @@ +;;; source/delete.el --- Remove an archive source -*- lexical-binding: t; -*- + +;;; Commentary: +;; +;; Commmand use to remove an archive source +;; +;; $ eask source delete +;; +;; +;; Positionals: +;; +;; name of the archive +;; + +;;; 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--source-delete (name) + "Delete an archive source by NAME." + (with-current-buffer (find-file eask-file) + (goto-char (point-min)) + (when (re-search-forward (concat "([ \t\n\r]*source[ \t\n\r]*['\"]+" name) nil t) + (delete-region (line-beginning-position) (1+ (line-end-position))) + (eask-info "(Delete source `%s')" name)) + (save-buffer))) + +(eask-start + (let* ((args (eask-args)) + (name (nth 0 args))) + (if-let ((exists (assoc name package-archives))) + (eask--source-delete name) + (eask-info "(Invalid source name, `%s')" name) + (eask-help "source/delete")))) + +;;; source/delete.el ends here diff --git a/lisp/source/list.el b/lisp/source/list.el new file mode 100644 index 00000000..7d645dbc --- /dev/null +++ b/lisp/source/list.el @@ -0,0 +1,20 @@ +;;; source/list.el --- List all source information -*- lexical-binding: t; -*- + +;;; Commentary: +;; +;; Commmand use to list all source information +;; +;; $ eask source list +;; + +;;; 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)) + +(eask-start + (eask-call "core/archives")) + +;;; source/list.el ends here diff --git a/src/util.js b/src/util.js index 280b8ada..0f08bb4d 100644 --- a/src/util.js +++ b/src/util.js @@ -236,15 +236,6 @@ async function e_call(argv, script, ...args) { }); } -/** - * Hide command unless options `--show-hidden` is specified. - * @param { string | boolean } description - to display when comand is showed, - * @return Return a string to show command, else we return false. - */ -function hide_cmd(description) { - return (process.argv.includes('--show-hidden')) ? description : false; -} - /** * Get the command count, not including options. * @return Return a size of the command array. @@ -255,6 +246,18 @@ function cmd_count() { return args.length; } +/** + * Hide command unless options `--show-hidden` is specified. + * @param { string | boolean } description - to display when comand is showed, + * @return Return a string to show command, else we return false. + */ +function hide_cmd(description) { + if ((process.argv.includes('--show-hidden')) + || 1 <= cmd_count()) // When display in submenu! + return description; + return false; +} + /* * Module Exports From e473afcff049274aa92b4a60b466d2f6763fa7e0 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sun, 12 Nov 2023 20:16:43 -0800 Subject: [PATCH 2/4] fix: correct logic --- lisp/_prepare.el | 20 ++++++++++---- lisp/core/archives.el | 2 +- lisp/source/add.el | 54 +++++++++++++++++++++++++------------- test/commands/local/run.sh | 9 +++++-- 4 files changed, 59 insertions(+), 26 deletions(-) diff --git a/lisp/_prepare.el b/lisp/_prepare.el index 42a4cd65..3807a3e1 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -1118,6 +1118,20 @@ This uses function `locate-dominating-file' to look up directory tree." (nongnu-devel . "https://elpa.nongnu.org/nongnu-devel/")) "Mapping of source name and url.") +(defun eask-2url (url) + "Convert secure/insecure URL." + (if (and url + (gnutls-available-p) + (eask-network-insecure-p)) + (eask-s-replace "https://" "http://" url) + url)) + +(defun eask-source-url (name &optional location) + "Get the source url by it's NAME and LOCATION." + (setq location (or location (cdr (assq (intern (eask-2str name)) eask-source-mapping))) + location (eask-2url location)) + location) + (defvar eask-package nil) (defvar eask-package-desc nil) ; package descriptor (defvar eask-package-descriptor nil) @@ -1299,12 +1313,8 @@ argument COMMAND." (when (symbolp name) (setq name (eask-2str name))) ; ensure to string, accept symbol (when (assoc name package-archives) (eask-error "Multiple definition of source `%s'" name)) - (setq location (or location (cdr (assq (intern name) eask-source-mapping)))) + (setq location (eask-source-url name location)) (unless location (eask-error "Unknown package archive `%s'" name)) - (when (and location - (gnutls-available-p) - (not (eask-network-insecure-p))) - (setq location (eask-s-replace "https://" "http://" location))) (add-to-list 'package-archives (cons name location) t)) (defun eask-f-source-priority (archive-id &optional priority) diff --git a/lisp/core/archives.el b/lisp/core/archives.el index 2aeeda74..6a36dcb5 100644 --- a/lisp/core/archives.el +++ b/lisp/core/archives.el @@ -25,7 +25,7 @@ (priority (assoc name package-archive-priorities)) (priority (cdr priority))) (message (concat " %-" eask--length-name "s %-" eask--length-url "s %-" eask--length-priority "s") - name url (or priority 0)))) + name (eask-2url url) (or priority 0)))) (defun eask--print-archive-alist (alist) "Print the archvie ALIST." diff --git a/lisp/source/add.el b/lisp/source/add.el index 94bf39d0..ea0ddce9 100644 --- a/lisp/source/add.el +++ b/lisp/source/add.el @@ -20,6 +20,10 @@ (locate-dominating-file dir "_prepare.el")) nil t)) +(defun eask--source-from-mapping (name url) + "Return t if NAME and URL matched our database." + (string= (eask-source-url name url) url)) + (defun eask--source-add (name url exists) "Add an archive source by NAME. @@ -29,7 +33,7 @@ Arguments EXISTS is used to print the information." (let* ((style-sym (string-match "([ \t\n\r]*source[ \t\n\r]*[']+" (buffer-string))) (name-str (if style-sym (concat "'" name) (concat "\"" name "\"")))) - (if url + (if (and url (not (eask--source-from-mapping name url))) (insert "(source " name-str " \"" url "\")\n") (insert "(source " name-str ")\n")) (eask-info "(New source `%s' added and points to `%s')" name (or url (cdr exists))))) @@ -45,17 +49,26 @@ The argument EXISTS is use to search for correct position to insert new source." (cond (exists (if (re-search-forward (concat "([ \t\n\r]*source[ \t\n\r]*['\"]+" name) nil t) - (progn - (re-search-forward "[ \t\r\n]*" nil t) ; Forward to non-space characters! + (let ((start (point)) + (built-in (string= url (eask-source-url name url)))) + (when (string= "\"" (string (char-after))) + (cl-incf start)) + (re-search-forward "[ \t\r\n\"]*" nil t) ; Forward to non-space characters! + (forward-char -1) (pcase (string (char-after)) (")" - (insert " \"" url "\"")) + (unless built-in + (insert " \"" url "\""))) ("\"" - (let ((old (thing-at-point 'string)) - (new (concat "\"" url "\""))) - (delete-region (point) (+ (point) (length old))) - (insert new)))) - (eask-info "(Changed archive `%s's location from `%s' to `%s')" + (if built-in + (delete-region start (save-window-excursion + (search-forward ")" nil t) + (1- (point)))) + (let ((old (thing-at-point 'string)) + (new (concat "\"" url "\""))) + (delete-region (point) (+ (point) (length old))) + (insert new))))) + (eask-info "(Changed archive `%s''s location from `%s' to `%s')" name (cdr exists) url)) (goto-char (point-max)) (eask--source-add name url exists))) @@ -72,16 +85,18 @@ The argument EXISTS is use to search for correct position to insert new source." Arguments NAME and URL are main arguments for this command." (if-let ((exists (assoc name package-archives)) (old-url (cdr exists))) - (if (and (not (string= old-url url)) - (yes-or-no-p - (format - (concat - "The archive `%s' is already exists and currently points to `%s'. + (cond ((string= old-url url) + (eask-info "(Nothing has changed due to the URLs are the same)")) + ((yes-or-no-p + (format + (concat + "The archive `%s' is already exists and currently points to `%s'. Do you want to overwrite it? ") - name old-url))) - (eask--source-write name url exists) - (eask-info "(Nothing has changed due to the URLs are the same)")) + name old-url)) + (eask--source-write name url exists)) + (t + (eask-info "(Nothing has changed, aborted)"))) (eask--source-write name url nil))) (eask-start @@ -91,7 +106,10 @@ Do you want to overwrite it? ") (cond (url (eask--source-ask-if-overwrite name url)) (t - (if-let ((archive (assoc (eask-intern name) eask-source-mapping))) + (if-let* ((archive (assoc (eask-intern name) eask-source-mapping)) + (name (car archive)) + (name (eask-2str name)) + (url (eask-source-url name))) ; Use the URL from our database! (eask--source-ask-if-overwrite name url) (eask-info "(Invalid source name, `%s')" name) (eask-help "source/add")))))) diff --git a/test/commands/local/run.sh b/test/commands/local/run.sh index 9fdf3226..a253d2ee 100644 --- a/test/commands/local/run.sh +++ b/test/commands/local/run.sh @@ -71,7 +71,7 @@ eask generate recipe -y #eask generate license gpl-3.0 # XXX: Avoid API rate limit exceeded error eask generate ignore elisp -# Linter +# Linting eask lint checkdoc eask lint declare eask lint elint @@ -86,7 +86,7 @@ eask lint regexps # Testing eask test activate -# Clean up +# Cleaning eask clean .eask eask clean elc eask clean dist @@ -95,6 +95,11 @@ eask clean pkg-file eask clean log-file eask clean all +# Control DSL +eask source add test "https://test.elpa.com" +eask source delete test +eask source list + # Util eask locate eask upgrade-eask From e554001a2e342666e104d7abe66f7ca93c89d85b Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sun, 12 Nov 2023 20:29:41 -0800 Subject: [PATCH 3/4] fix: logic --- lisp/source/add.el | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lisp/source/add.el b/lisp/source/add.el index ea0ddce9..4ac55bdd 100644 --- a/lisp/source/add.el +++ b/lisp/source/add.el @@ -22,7 +22,7 @@ (defun eask--source-from-mapping (name url) "Return t if NAME and URL matched our database." - (string= (eask-source-url name url) url)) + (string= (eask-source-url name) url)) (defun eask--source-add (name url exists) "Add an archive source by NAME. @@ -32,8 +32,9 @@ If argument URL is nil; ignore the insertion. Arguments EXISTS is used to print the information." (let* ((style-sym (string-match "([ \t\n\r]*source[ \t\n\r]*[']+" (buffer-string))) (name-str (if style-sym (concat "'" name) - (concat "\"" name "\"")))) - (if (and url (not (eask--source-from-mapping name url))) + (concat "\"" name "\""))) + (built-in (eask--source-from-mapping name url))) + (if (and url (not built-in)) (insert "(source " name-str " \"" url "\")\n") (insert "(source " name-str ")\n")) (eask-info "(New source `%s' added and points to `%s')" name (or url (cdr exists))))) @@ -50,11 +51,13 @@ The argument EXISTS is use to search for correct position to insert new source." (exists (if (re-search-forward (concat "([ \t\n\r]*source[ \t\n\r]*['\"]+" name) nil t) (let ((start (point)) - (built-in (string= url (eask-source-url name url)))) + (built-in (eask--source-from-mapping name url))) (when (string= "\"" (string (char-after))) (cl-incf start)) - (re-search-forward "[ \t\r\n\"]*" nil t) ; Forward to non-space characters! + (re-search-forward "[ \t\r\n\")]*" nil t) ; Forward to non-space characters! (forward-char -1) + (when (string= "\n" (string (char-after))) + (forward-char -1)) (pcase (string (char-after)) (")" (unless built-in From 500df7ce33f3cd77fb61bbb980b590952e479765 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sun, 12 Nov 2023 20:31:36 -0800 Subject: [PATCH 4/4] update doc --- docs/content/en/Getting-Started/Introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/en/Getting-Started/Introduction.md b/docs/content/en/Getting-Started/Introduction.md index e3d4cee4..6476c7f1 100644 --- a/docs/content/en/Getting-Started/Introduction.md +++ b/docs/content/en/Getting-Started/Introduction.md @@ -118,7 +118,7 @@ list. ### ๐Ÿ” Eask-file commands -- [x] [FEAT] Add `source add` command +- N/A ## ๐Ÿ“‚ Underlying Projects