Commit graph

232 commits

Author SHA1 Message Date
Henrik Lissner
743b740e79
fix(cli): verbose output in debug mode 2022-07-28 18:15:15 +02:00
Henrik Lissner
314463bd49
fix(cli): ignored --{profile,doomdir,emacsdir,debug}
Fixes an edge case where --profile, --doomdir, --emacsdir, and --debug
were ignored if used in a nested bin/doom call. Now possible thanks to
49d3f1e.

Ref: 49d3f1e96c
2022-07-28 18:15:06 +02:00
Henrik Lissner
5af38fb08e
feat: make bin/doom profile aware
- Fixes Doom's former inability to (trivially) juggle multiple profiles
  based on the same EMACSDIR (see #6593).
- Adds '--profile NAME' switch to bin/doom (also recognized
  $DOOMPROFILE).
- Adds new doom-profile* variables. These will eventually replace
  doom-{local,etc,cache}-dir and doom-{autoloads,env}-file.

This is intentionally messy to ensure backwards compatibility for a
little while longer. This will be fixed over the next couple weeks.

Ref: #6593
2022-07-28 12:01:02 +02:00
Henrik Lissner
33c5f3721a
fix(cli): __DOOMPIPE+=0: not found errors
The string append operator is a bashism, and therefore is not POSIX
complaint. It will throw errors when /bin/sh isn't symlinked to bash.
2022-07-09 21:10:40 +02:00
Henrik Lissner
6cb2c6e962
fix(cli): recognize global options for pseudo CLIs
The global options (like --debug and --pager) weren't recognized for
pseudo command like :help and :version (in particular, rendering --pager
ineffective).

Fix: #6526
2022-07-04 02:58:17 +02:00
Henrik Lissner
af4c18e283
fix(cli): recognize command argument for --pager
--pager incorrectly expected a boolean argument, when it should accept
any arbitrary pager command (set to a blank string to disable the
pager).

Ref: #6526
2022-07-04 02:58:17 +02:00
Henrik Lissner
14b2395424
refactor: remove unused core variables
doom-debug-p and doom-interactive-p have always been intentionally
redundant, because changing the variables they replaced had other
side-effects, which made writing tests for them difficult. Since our
new (yet unpublished) tests lean heavily toward integration testing more
than unit testing, this becomes an implementation detail.

And doom-init-p's only use was refactor out at some point in the past,
so it's no longer used.

Also done to reduce Doom's footprint, in general.
2022-06-29 18:14:20 +02:00
Henrik Lissner
4dcfc37199
nit(cli): clarify comments in bin/doomscript 2022-06-22 23:04:59 +02:00
Henrik Lissner
d2fbe6a0c9
fix(cli): restore doom {refresh,re} alias
Amend: 6c0b7e1530
2022-06-22 23:04:58 +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
209092c578
refactor(cli): don't reboot bin/doom on --pager
Also adds comments to explain why we're rebooting (or not) for these
settings.
2022-06-22 11:48:11 +02:00
Henrik Lissner
f0a11da072
tweak(cli): less verbosity on -!/--force
The notice will still be logged, but let's not potentially ruin piped
output with unneeded noise.
2022-06-22 11:42:25 +02:00
Henrik Lissner
3ea9051890
fix(cli): remove set -e from bin/doom{,script}
This killed the script prematurely (without displaying the error) if
Emacs failed to execute. In versions prior to bash 4, set -e would not
terminate the script if a non-zero exit code occurred within a subshell,
but it will in bash 4+.

In any case, we don't need this fallback to begin with. The script
handles its errors sufficiently otherwise.
2022-06-22 01:23:39 +02:00
Henrik Lissner
90a6bdb751
nit(cli): update comments wrt deferring site-lisp and -Q
Ref: 3b3c008b1b (commitcomment-76653206)
2022-06-21 23:31:16 +02:00
Henrik Lissner
5519c030ff
fix(cli): -!/--force being ignored
Forgot to adapt the old code to use doom-cli-context struct!

Fix: #6485
2022-06-21 23:00:00 +02:00
Henrik Lissner
3b3c008b1b
fix(cli): site file loader
I had missed the fact that -Q implies not only
--no-site-file (intended), but --no-site-lisp (unintended). Without the
latter, no site-lisp directory is left in load-path, and any attempt to
load it after-the-fact (which I do in core-cli.el) will fail. Thanks to
@yamanq for noticing this!

Fix: #6473
Fix: #4198
Co-authored-by: Yaman Qalieh <yamanq@users.noreply.github.com>
2022-06-21 22:48:43 +02:00
Henrik Lissner
19ce459138
fix(cli): module cli.el loader
$DOOMDIR/init.el had to be loaded earlier, so we could read the active
module list. This indirectly fixes an issue where users' literate
configs weren't being tangled on 'doom sync'.

Fix: #6479
2022-06-20 23:44:32 +02:00
Henrik Lissner
beef0aef02
fix(cli): split tput call into two separate calls
This fixes an issue where, on some systems, `tput cols lines` does not
produce "N\nM" (where N = number of columns in the terminal and M =
number of lines), and instead produces "N\n", causing parsing errors.
2022-06-19 02:39:22 +02:00
Henrik Lissner
09ddac1d7a
feat(cli): resolve EMACSDIR to doomscript's parent directory
If no EMACSDIR is given, assume ../ is the Emacs config we want to
operate out of, taking after bin/doom.

And use bash. This script was designed for the convenience of other
scripters on unix systems, so it can afford a small hit to portability.
2022-06-19 02:20:34 +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
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
e5b7edcd8d
feat(cli): add bin/doomscript
Meant as a simple elisp interpreter with Doom's CLI framework preloaded.
Can be used as a shebang line:

  #!/usr/bin/env doomscript
  (princ "hello world!")

This isn't used for bin/doom because it requires doomscript be in your
$PATH, and any attempt to resolve its location in bin/doom's shebang
line would reduce its portability. Neither of these should be an issue
for the type of user who'd find this useful.
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
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
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
2f39d3fced fix(cli): "Unknown terminal type" error on bin/org-capture
Fix: #5438
2021-11-24 22:03:21 +01:00
Henrik Lissner
045ea7460d nit: revise and reformat code comments 2021-08-04 01:53:12 -04:00
Henrik Lissner
06392a723f refactor: rename orig-fn arg in advice to fn
A minor tweak to our naming conventions for the first argument of an
:around advice.
2021-08-04 01:53:12 -04:00
Alexandre de Siqueira
44c8d3c8e4
Adding new line on string on how to upgrade Emacs
The current string presented breaks the address on how to upgrade Emacs:

```
❯ doom install
Detected Emacs 26.3 (at emacs).

Doom only supports Emacs 27.1 and newer. A guide to install a newer version
of Emacs can be found at:

  https://doomemacs.org/docs/getting_started.org#on-linuxAborting...
```

Just adding a `\n` at the end of the string would solve it.
2021-07-26 17:45:52 -07:00
Henrik Lissner
044a1a5f2b Drop Emacs 26.x support
Emacs 27.x has been the stable version of Emacs for nearly a year, and
introduces a litany of bugfixes, performance, and quality-of-life
improvements that significantly reduce Doom's maintenance burden (like
XDG support, early-init.el, image manipulation without imagemagick, a
native JSON library, harfbuzz support, pdumper, and others).

With so many big changes on Doom's horizon, I like having one less (big)
thing to worry about.

Also reverts bb677cf7a (#5232) as it is no longer needed.
2021-07-06 02:31:52 -04:00
Henrik Lissner
ef7113d6c4 Fix #5071: don't always emit 128 exit code
Otherwise it always tries to execute /tmp/doom.sh, which won't exist on
certain code paths.
2021-05-20 11:01:28 -04:00
Henrik Lissner
1e9870e13a Refactor bin/doom
So innocuous CLI command return values don't break the post-script
written to /tmp/doom.sh.
2021-05-17 22:29:50 -04:00
Henrik Lissner
528657a426 bin/org-capture: fix hanging
The script's stdin check was too simplistic and would block forever
waiting for input. From now on, to pipe to the script, pass it a dash.
2021-05-15 14:09:08 -04:00
Henrik Lissner
91573dd95f Fix site files not loading in batch session
Should help with loading Snap environment or packages installed via the
system package manager (like mu4e).

Fixes #4198
2021-05-09 20:50:23 -04:00
Henrik Lissner
df10383a26 Use symbol plists instead of internal variables
More in line with Emacs' built-in practice of storing a variable's
standard-value in a symbol property of the same name, with the added
benefit of less global state.
2021-05-06 04:27:33 -04:00
Henrik Lissner
18e1795a98 org-confirm-babel-evaluate = nil while tangling 2021-03-22 21:11:22 -04:00
Henrik Lissner
e9c4c7471c Reorganize CLI libraries 2021-03-12 17:55:41 -05:00
pancho horrillo
3861225f0b Fix 'too many arguments' error on org-capture
org-capture foo bar baz

will fail with:

org/capture: line 33: [: too many arguments

Adding quotes to the expansion of $str will ensure that test -z has
only one argument.
2021-03-08 10:42:06 +01:00
Eric Drechsel
269dab615c org-capture: text from args, else stdin
old behavior was to use stdin in non-interactive
This prevented binding eg in qutebrowser
2021-03-07 00:48:32 -08:00
Henrik Lissner
1274de3d34 Minor reformatting & refactors across the board 2021-02-25 13:59:43 -05:00
Henrik Lissner
3894611a8f Minor comment revision 2021-02-21 14:44:59 -05:00
Henrik Lissner
eea4709354
cli: run post-script indirectly
Fixes cases where /tmp is mounted with noexec.
2020-12-12 15:56:36 -05:00
Henrik Lissner
b5e948054c
Refactor & reformat core.el
Backport a bit of core.el from our CLI rewrite.
2020-12-02 17:58:09 -05:00
Henrik Lissner
b49c40bbb3
Minor refactors & comment revision 2020-11-29 14:37:32 -05:00
Henrik Lissner
03c6a352bf
Ensure site subdirs.el are loaded 2020-11-20 14:10:29 -05:00
Henrik Lissner
4dab595ad3
Minor refactors & comment revision 2020-11-20 14:10:29 -05:00
Henrik Lissner
5940d931f4
Fix "read only variable" errors on doom {sync,upgrade}
Relevant to #3844
2020-09-01 15:32:01 -04:00
Henrik Lissner
e03824bf5e
bin/doom: improve POSIX compliance
+ The bourne shell does not guarantee it'll understand the new $()
  subshell syntax.
+ Can't rely on set -e to short circuit the script. No avoiding the
  roundabout suppression of the postscript error with '&& true'.

Might fix #3844, but doubt it.
2020-08-27 14:42:48 -04:00
Henrik Lissner
a2a5038b97
Fix #3844: bin/doom emits wrong-type-arg error on windows
For some reason __DOOMPOST isn't being exported into emacs' environment
on Windows (powershell and git bash).
2020-08-27 01:10:08 -04:00
Henrik Lissner
a6dc9bf7e5
core-cli: minor refactors 2020-08-27 01:10:08 -04:00