Commit graph

491 commits

Author SHA1 Message Date
Henrik Lissner
001065ba42
refactor(cli): minor refactors & allow flychecker in CLIs
- Add comments to doom-cli-context-parse.
- Simplify/inline code here and there.
- Remove sacrifice to appease byte-compiler.

Thanks to a346928 there's no need to appease the byte-compiler with this
eval-when-compile hackery.

Ref: a34692826f18
2022-06-22 23:04:54 +02:00
Henrik Lissner
666cc1fda7
refactor(cli): remove :stub, :obsolete, :deprecated, :since
I've removed these CLI properties because they were either
unused (:deprecated and :since) or poorly implemented (:stub and
:obsolete). And I'd rather have fewer magical properties, and instead
delegate these roles to the defobsolete! and (new) defstub!  macros.
Also, in the future, the help API will ascertain :since dynamically, so
it won't be very useful.

In summary:
- Use defstub! instead of :stub
- Use defobsolete! instead of :obsolete or :deprecated
- This removes the doom-cli-deprecated-error type (it's not really an
  error to begin with).
- Removes :stub, :obsolete, :deprecated, and :since
2022-06-22 23:04:14 +02:00
Henrik Lissner
23feb482e9
refactor!(lib): rename fn!->lambda! & fn!!->fn!
BREAKING CHANGE: This renames the fn! macro to lambda! and fn!! to fn!.
I hadn't put much thought into their names when they were added, but now
that they're seeing more use, I've reconsidered.

The reasoning is (and I'll refer to them by their new names):

- If you're using fn!, you care more about the syntax's brevity, than if
  you were using lambda!, so I wanted fn! to have the (even if slightly)
  shorter name.
- lambda! decorates native lambda (with cl-function). Its old name
  did not suggest that connection like other !-macros in Doom's library
  do.
- Their old names implied the two macros were somehow related or that
  one decorated the other. They aren't and don't.
2022-06-21 21:29:08 +02:00
Henrik Lissner
b0b727824a
feat(cli): allow docs to use %c/%p format specs
And replace magic section SYNOPSIS with EXAMPLES.
2022-06-21 02:08:19 +02:00
Henrik Lissner
fe850934f1
fix(cli): display command list groups in insert order
On 'doom help' or 'doom help --commands'
2022-06-20 23:43:23 +02:00
Henrik Lissner
cfb533043f
fix(cli): add extra package checks
So the doctor doesn't complain about pseudo packages, like revealjs,
which is not actually an Emacs package, we're just using straight.el to
install it for org-re-reveal.
2022-06-20 23:43:23 +02:00
Henrik Lissner
79f1d29722
fix(cli): don't trigger kill hooks on 'doom doctor'
To restrict side-effects in the user's config.
2022-06-20 23:43:23 +02:00
Henrik Lissner
343def0b1e
fix(cli): void-function relpath on 'doom compile' 2022-06-20 02:27:23 +02:00
Henrik Lissner
b81e4af66a
fix(cli): deploy git hooks to repo at $PWD, not $EMACSDIR 2022-06-19 23:05:33 +02:00
Henrik Lissner
12e9b4422f
tweak(cli): show benchmark for doom {build,purge}
These two commands tend to take a while.
2022-06-19 22:51:46 +02:00
Henrik Lissner
50a0c2ef46
fix(cli): ci.el loader
- :before ci will try to load $REPOROOT/ci.el or $DOOMDIR/ci.el. It
  finds $REPOROOT by calling `git`, but doesn't handle errors. Now it
  does.
- Because &rest was in :before ci's argspec, :before ci * subcommands
  would be inaccessible (not that any exist atm, though).
- Let the user know when it finds the project's ci.el.
2022-06-19 22:49:47 +02:00
Henrik Lissner
49ef0fa8dd
tweak(cli): improve message when no similar commands found
Rather than display a blank line, let the user know no similar commands
were found.
2022-06-19 13:07:28 +02:00
Henrik Lissner
6eefd4c1df
fix(cli): wrong-type-arg error on unrecognized command
If you type an unrecognized command, you get an "Error: unrecognized
command X" error, then a list of similar commands, followed by a
recommendation to check out 'doom help Y' or 'doom --help Y', where Y is
the nearest recognized parent command. E.g. 'doom ci blah' is an unknown
command, but 'doom ci' is known, therefore Y = 'doom ci'.

This fix ensures that Y is properly resolved.

Amend: 6c0b7e1530
2022-06-19 13:03:28 +02:00
Henrik Lissner
446e1432bc
fix(cli): show full synopsis for pseudo commands
Before:
  $ doom help help
  Usage:  COMMAND [ARGS...]

  TODO

  TODO

After:
  Usage: doom help [-g|--no-global] [--manpage] [--commands]
                   [--synopsis|--subcommands|--similar|--envvars|--postamble] [--]
                   COMMAND [ARGS...]

  Show documentation for a Doom CLI command.

  OPTIONS:
    -g, --no-global
      Hide global options.

    --manpage
      Generate in manpage format.

    --commands
      List all known commands.

    --synopsis, --subcommands, --similar, --envvars, --postamble
      Show only the specified sections..

Amend: 6c0b7e1530
2022-06-19 12:50:21 +02:00
Henrik Lissner
8d881f44c4
fix(cli): various errors in 'doom help'
- Wrong number of arguments: #<subr max> 0
- Symbol's value as variable is void: localonly?

Amend: 6c0b7e1530
2022-06-19 12:50:21 +02:00
Henrik Lissner
42d84e7e21
fix(cli): possible divide-by-zero when calculating similarity
If given two empty strings (which doesn't happens anywhere in the
codebase atm, but just in case).
2022-06-19 12:50:17 +02:00
Henrik Lissner
979495cf33
fix(cli): void-function doom-clean-byte-compiled-files on 'doom upgrade'
This function was renamed in 6c0b7e1.

Amend: 6c0b7e1530
2022-06-19 12:08:24 +02:00
Henrik Lissner
fb7f4c6cbe
fix(cli): time out if native-comp hangs
Some packages (primarily vterm, evil-collection, and with-editor) end up
hanging their native compilation process. In vterm's case it's because
it invisibly prompts to compile its module then waits forever for user
input that'll never come. I haven't figured out why it happens for the
others though.

In any case, since the workaround is to simply kill these processes and
carry on, I added this timeout mechanism to do it for you (timing out
after 30s of no movement). A more elegant solution will have to wait
until the rewrite of our package manager.

Fix: #5592
2022-06-19 12:01:52 +02:00
Henrik Lissner
f913ff07b3
fix(cli): void-function doom-packages-install error on 'doom install' 2022-06-19 03:00:10 +02:00
Henrik Lissner
8816508d6c
fix(cli): update 'doom upgrade'
To reflect changes made in 6c0b7e1.

Amend: 6c0b7e1530
2022-06-19 02:34:23 +02:00
Henrik Lissner
74f3c1d11c
fix(cli): doom {compile,clean} errors
- An improper autoload was preventing 'doom clean' from being
  recognized.
- 'doom compile' hadn't been updated to reflect changes introduced
  recently in 1402db5.

Amend: 6c0b7e1530
Ref: 1402db5129
2022-06-19 01:39:32 +02:00
Henrik Lissner
498d88ba9b
feat(cli): add -j/--jobs NUM options
To 'doom sync', 'doom upgrade', and 'doom build'. So users can decide
whether they want Doom 100%'ing their CPUs.

After 3.0, many of these commands will be merged, so a little code
duplication is fine for now.
2022-06-19 01:29:40 +02:00
Henrik Lissner
89e02c1c2b
fix(cli): wrong-number-of-args error on 'doom upgrade'
When I added call! to the DSL, I forgot to update doom-cli-call calls.
This should quell these errors when running 'doom upgrade':

  x There was an unexpected runtime error
    Message: Wrong number of arguments
    Details: (((cl-struct-doom-cli-context-tags cl-struct-doom-cli-option-...
    Backtrace:
      (doom-cli-call ("doom" "sync" "-u"))
      (cond (packages\? (doom-cli-call sync-cmd) (doom-print (doom-print-...

Amend: 6c0b7e1530
2022-06-19 01:17:25 +02:00
Henrik Lissner
2e9997a3d5
fix(cli): void-variable doom-repo-* errors on 'doom upgrade'
Amend: 6c0b7e1530
2022-06-19 01:10:54 +02:00
Henrik Lissner
d5db9076af
fix(cli): wrong-number-of-args error on 'doom sync'
Amend: 6c0b7e1530
2022-06-19 01:07:01 +02:00
Henrik Lissner
81a52402b2
fix(cli): void-variable packages-only?
Amend: 6c0b7e1530
2022-06-19 01:05:26 +02:00
Henrik Lissner
daad6bc21d
feat(cli): add 'doom make completions' for zsh
'doom make completions' will generate a rudimentary ZSH completion
script for bin/doom. It can be used from your shell dotfiles, but I
recommend caching the output with a function like:
https://github.com/hlissner/dotfiles/blob/master/config/zsh/.zshenv#L1-L14.

Then add this to your .zshrc:

  _cache doom make completions --zsh && compdef _doom doom

Ref: https://github.com/hlissner/dotfiles/blob/master/config/zsh/.zshenv#L1-L14
2022-06-18 23:53:12 +02:00
Henrik Lissner
6c0b7e1530
refactor!(cli): rewrite CLI framework libraries
BREAKING CHANGE: this changes Doom's CLI framework in subtle ways, which
is listed in greater detail below. If you've never extended Doom's CLI,
then this won't affect you, but otherwise it'd be recommended you read
on below.

This commit focuses on the CLI framework itself and backports some
foundational changes to its DSL and how it resolves command line
arguments to CLIs, validates input, displays documentation, and persists
state across sessions -- and more. This is done in preparation for the
final stretch towarding completing the CLI rewrite (see #4273).

This is also an effort to generalize Doom's CLI (both its framework and
bin/doom), to increase it versatility and make it a viable dev tool for
other Doom projects (on our Github org) and beyond.

However, there is a *lot* to cover so I'll try to be brief:

- Refactor: generalize Doom's CLI framework by moving all bin/doom
  specific configuration/commands out of core-cli into bin/doom. This
  makes it easier to use bin/doom as a project-agnostic development
  tool (or for users to write their own).
- Refactor: change the namespace for CLI variables/functions from
  doom-cli-X to doom-X.
- Fix: subcommands being mistaken as arguments. "doom make index" will
  resolve to (defcli! (doom make index)) if it exists,
  otherwise (defcli! (doom make)) with "index" as an argument. Before
  this, it would resolve to the latter no matter what. &rest can
  override this; with (defcli! (doom make) (&rest args)), (defcli! (doom
  make index)) will never be invoked.
- Refactor!: redesign our output library (was core/autoload/output.el,
  is now core/autoload/print.el), and how our CLI framework buffers and
  logs output, and now merges logs across (exit! ...) restarts.
- Feat: add support for :before and :after pseudo commands. E.g.

    (defcli! (:before doom help) () ...)
    (defcli! (:after doom sync) () ...)

  Caveat: unlike advice, only one of each can be defined per-command.
- Feat: option arguments now have rudimentary type validation (see
  `doom-cli-option-arg-types`). E.g.

    (defcli! (doom foo) ((foo ("--foo" num))) ...)

  If NUM is not a numeric, it will throw a validation error.

  Any type that isn't in `doom-cli-option-arg-types` will be treated as a
  wildcard string type. `num` can also be replaced with a specification,
  e.g. "HOST[:PORT]", and can be formatted by using symbol quotes:
  "`HOST'[:`PORT']".
- Feat: it is no longer required that options *immediately* follow the command
  that defines them (but it must be somewhere after it, not before). E.g.
    With:
      (defcli! (:before doom foo) ((foo ("--foo"))) ...)
      (defcli! (doom foo baz) () ...)
    Before:
      FAIL: doom --foo foo baz
      GOOD: doom foo --foo baz
      FAIL: doom foo baz --foo
    After:
      FAIL: doom --foo foo baz
      GOOD: doom foo --foo baz
      GOOD: doom foo baz --foo
- Refactor: CLI session state is now kept in a doom-cli-context struct (which
  can be bound to a CLI-local variable with &context in the arglist):

    (defcli! (doom sync) (&context context)
      (print! "Command: " (doom-cli-context-command context)))

  These contexts are persisted across sessions (when restarted). This is
  necessary to support seamless script restarting (i.e. execve
  emulation) in post-3.0.
- Feat: Doom's CLI framework now understands "--". Everything after it will be
  treated as regular arguments, instead of sub-commands or options.
- Refactor!: the semantics of &rest for CLIs has changed. It used to be "all
  extra literal, non-option arguments". It now means *all* unprocessed
  arguments, and its use will suppress "unrecognized option" errors, and
  tells the framework not to process any further subcommands. Use &args
  if you just want "all literal arguments following this command".
- Feat: add new auxiliary keywords for CLI arglists: &context, &multiple,
  &flags, &args, &stdin, &whole, and &cli.
  - &context SYM: binds the currently running context to SYM (a
    `doom-cli-context` struct). Helpful for introspection or passing
    along state when calling subcommands by hand (with `call!`).
  - &stdin SYM: SYM will be bound to a string containing any input piped
    into the running script, or nil if none. Use
    `doom-cli-context-pipe-p` to detect whether the script has been
    piped into or out of.
  - &multiple OPTIONS...: allows all following OPTIONS to be repeated. E.g. "foo
    -x a -x b -x c" will pass (list ("-x" . "a") ("-x" . "b") ("-x" .
    "c")) as -x's value.
  - &flags OPTIONS...: All options after "&flags" get an implicit --no-* switch
    and cannot accept arguments. Will be set to :yes or :no depending on which flag is
    provided, and nil if the flag isn't provided. Otherwise, a default
    value can be specified in that options' arglist. E.g.

      (defcli! (doom foo) (&flags (foo ("--foo" :no))) ...)

    When called, this command sets FOO to :yes if --foo, :no if --no-foo, and
    defaults to :no otherwise.
  - &args SYM: this replaces what &rest used to be; it binds to SYM a
    list of all unprocessed (non-option) arguments.
  - &rest SYM: now binds SYM to a list of all unprocessed arguments, including
    options. This also suppresses "unrecognized option" errors, but will render
    any sub-commands inaccessible. E.g.

      (defcli! (doom make) (&rest rest) ...)
      ;; These are now inaccessible!
      (defcli! (doom make foo) (&rest rest) ...)
      (defcli! (doom make bar) (&rest rest) ...)
  - &cli SYM: binds SYM to the currently running `doom-cli` struct. Can also be
    obtained via `(doom-cli-get (doom-cli-context-command context))`. Possibly
    useful for introspection.
- feat: add defobsolete! macro for quickly defining obsolete commands.
- feat: add defalias! macro for quickly defining alias commands.
- feat: add defautoload! macro for defining an autoloaded command (won't
  be loaded until it is called for).
- refactor!: rename defcligroup! to defgroup! for consistency.
- fix: CLIs will now recursively inherit plist properties from parent
  defcli-group!'s (but will stack :prefix).
- refactor!: remove obsolete 'doom update':
- refactor!: further generalize 'doom ci'
  - In an effort to generalize 'doom ci' (so other Doom--or
    non-doom--projects can use it), all its subcommands have been
    changed to operate on the current working directory's repo instead
    of $EMACSDIR.
  - Doom-specific CI configuration was moved to .github/ci.el.
  - All 'doom ci' commands will now preload one of \$CURRENT_REPO_ROOT/ci.el or
    \$DOOMDIR/ci.el before executing.
- refactor!: changed 'doom env'
  - 'doom env {-c,--clear}' is now 'doom env {clear,c}'
  - -r/--reject and -a/--allow may now be specified multiple times
- refactor!: rewrote CLI help framework and error handling to be more
  sophisticated and detailed.
- feat: can now initiate $PAGER on output with (exit! :pager) (or use
  :pager? to only invoke pager is output is longer than the terminal is
  tall).
- refactor!: changed semantics+conventions for global bin/doom options
  - Single-character global options are now uppercased, to distinguish them from
    local options:
    - -d (for debug mode) is now -D
    - -y (to suppress prompts) is now -!
    - -l (to load elisp) is now -L
    - -h (short for --help) is now -?
  - Replace --yes/-y switches with --force/-!
  - -L/--load FILE: now silently ignores file errors.
  - Add --strict-load FILE: does the same as -L/--load, but throws an error if
    FILE does not exist/is unreadable.
  - Add -E/--eval FORM: evaluates arbitrary lisp before commands are processed.
  - -L/--load, --strict-load, and -E/--eval can now be used multiple times in
    one command.
  - Add --pager COMMAND to specify an explicit pager. Will also obey
    $DOOMPAGER envvar. Does not obey $PAGER.
- Fix #3746: which was likely caused by the generated post-script overwriting
  the old mid-execution. By salting the postscript filenames (with both an
  overarching session ID and a step counter).
- Docs: document websites, environment variables, and exit codes in
  'doom --help'
- Feat: add imenu support for def{cli,alias,obsolete}!

Ref: #4273
Fix: #3746
Fix: #3844
2022-06-18 23:53:12 +02:00
Henrik Lissner
f281971206
feat(ci): generalize 'doom ci deploy-hooks'
By default, 'doom ci deploy-hooks' would deploy Doom's git hooks in
$EMACSDIR (~/.emacs.d/.git/hooks). Now it deploys in the local repo its
run in. This is part of an effort to generalize Doom's CI for use
outside this repo.

Ref: 4bae9ffa47
2022-05-05 15:35:33 +02:00
Henrik Lissner
4bae9ffa47
refactor(ci): generalize commit linter api
Continues from 47d1b82 as part of an effort to generalize Doom's CI for
use outside this repo:

- 'doom ci ...' commands now:
  - Run in the context of the local repo where they're run, rather than
    from Doom's install directory ($EMACSDIR).
  - Load the first of $REPO_ROOT/.github/ci.el, $DOOMDIR/cli.el, or
    $DOOMDIR/cli.el, before executing CI commands. This allows for
    per-project configuration, for example:
    - https://github.com/doomemacs/doomemacs/blob/master/.github/ci.el
    - https://github.com/doomemacs/themes/blob/master/.github/ci.el
    (Details may change post-3.0)
- Scopeless commit types are now enforced in `doom-cli-commit-scopes`,
  rather than `doom-cli-commit-rules`. This lets you specify exceptions,
  like 0597466261.
- `doom-cli-commit-scopes` now supports sub-lists, as an easy way to
  permit type-local scopes. E.g. To allow 'install' and 'faq' scopes
  only for 'docs:' commits.

    (add-to-list 'doom-cli-commit-scopes '(docs "install" "faq"))

  These sublists accepts predicates too.
- Fixed the link to git conventions in the linter's failure/warning
  output, to point to our Discourse post.

Ref: https://github.com/doomemacs/doomemacs/blob/master/.github/ci.el
Ref: https://github.com/doomemacs/themes/blob/master/.github/ci.el
Ref: 0597466261
Amend: 47d1b82382
2022-05-05 15:32:35 +02:00
Henrik Lissner
47d1b82382
tweak(ci): generalize commit linter defaults
So Doom can be used for general CI/CD (as part of doomemacs/ci). These
settings can be configured in .github/ci.el by default.

Ref: 0f6a653a13
2022-05-04 22:44:28 +02:00
Henrik Lissner
fbfc635300
fix(cli): GIT_CONFIG* envvars leaking child processes
When launching Doom via 'doom run', the child process inherits
bin/doom's environment. This change restricts this sub-environment to
the intended target: straight and its use of git.

Fix: #6320
2022-04-21 22:36:36 +02:00
Itai Y. Efrat
3a3c66df18 docs: add doctor warning about lack of nativecomp 2022-04-12 02:32:53 +02:00
Itai Y. Efrat
5cef63658d docs: update doctor living on the edge check to 29+ 2022-04-12 02:32:53 +02:00
Henrik Lissner
cf79616202
fix(cli): remove debug error call in 'doom version'
Accidentally snuck into dcae7187b4.

Amend: dcae7187b4
2022-04-01 19:12:35 +02:00
Henrik Lissner
806d9c0116
fix(cli): remove bufler from excluded autoloads
I was discussing issues generating autoloads files from some packages
with someone on Discord, and they mentioned issues with
alphapapa/bufler.el, so I added doom-autoloads-excluded-files in
5d0f781062, and also added bufler to it by default. In hindsight, that
doesn't make much sense as a default when Doom and its modules don't
even install bufler (and even if they did, this shouldn't be done in
core).

Ref: 5d0f781062
2022-03-31 19:25:49 +02:00
Henrik Lissner
da1eb4d107
refactor(cli): minor refactors and comment revision 2022-03-31 19:25:49 +02:00
Henrik Lissner
a9c22b704b
fix(cli): ignore system/user git configs
So they don't interfere with straight in odd, unpredictable ways. If
you *really* know what you're doing, set DOOMGITCONFIG to the path of a
gitconfig file. This envvar may be renamed in the future, however.

Close: #5640
Co-authored-by: M. Yas. Davoodeh <Davoodeh@users.noreply.github.com>
2022-03-31 01:06:07 +02:00
Henrik Lissner
9d1513af46
bump: :core
bbatsov/projectile@0243ad7dc9 -> bbatsov/projectile@f3468e8d20
domtronn/all-the-icons.el@2c963ebb75 -> domtronn/all-the-icons.el@65c496d3d1
jscheid/dtrt-indent@926fc4260c -> jscheid/dtrt-indent@66fc30af02
raxod502/straight.el@653b04a64f -> raxod502/straight.el@e2de88ea0e
2022-03-30 17:49:35 +02:00
Henrik Lissner
dcae7187b4
refactor(lib): doom-info & remove unused commands
- Simplify doom-info and doom/info.
- Remove doom/copy-buffer-contents (may be moved later, but atm not very
  useful).
- Remove doom/am-i-secure (this will later be replaced with CLI
  commands)
2022-03-30 17:32:47 +02:00
Henrik Lissner
615b513a9c dev: add "docs" scope
To refer to documentation "backend" work, as opposed to its contents.
2022-02-02 01:56:04 +01:00
Rafael Varago
1c1ad3a8c8
feat(cli): allow opting-out of deploying git hooks
That's helpful when we need to `doom install` in a non-git directory.

Fix: #5878
Close: #5862
2022-01-27 15:06:45 +01:00
Henrik Lissner
d2da550a14 dev(ci): permit apostrophes in Co-authored-by lines 2022-01-27 03:47:54 +01:00
Henrik Lissner
2132d60062 dev(ci): permit short bump/revert commit messages 2021-12-13 18:48:59 +01:00
Henrik Lissner
9634500a3b fix(cli): update recipe repos (MELPA/ELPA/etc) earlier
If done before we collect our recipe lists, we (hopefully) dodge some
stale-recipe race conditions.
2021-11-22 16:49:43 +01:00
Henrik Lissner
fe2af3c344 fix(cli): don't regraft repo if no repo given
Otherwise you'll regraft $EMACSDIR, which could result in lost data for
contributors.
2021-11-22 16:49:17 +01:00
Henrik Lissner
cc3be7cb44 refactor: simplify native-comp detection
Reduce cases where native-comp procedures were executed in
non-native-comp contexts (somehow).

Also:
- Adds a NATIVECOMP constant for statically detecting the feature.
- Remove native-comp-* -> comp-* aliases (Emacs HEAD has long since
  moved on from these).
- Add 'no-native-compile: t' to autoloads file.
2021-11-22 16:01:02 +01:00
Gerry Agbobada
8d360474ac
docs: add doctor for dev versions of Emacs
The message simply test for the "not-a-version-yet" patch number and
displays an explanation to prepare users for raised error frequency and
having a backup version of Emacs if they do not want to deal with
issues.
2021-11-20 18:32:59 +01:00
Henrik Lissner
bac7ccb970 dev(ci): minor refactor & reformatting 2021-11-04 01:43:50 +01:00
Henrik Lissner
710eab10c7 dev(ci): suppress summary length warnings for bump/revert commits 2021-11-04 01:43:10 +01:00