jj/cli/tests
Ilya Grigoriev 52c415eaf4 docs: store output of jj util markdown-help, render it on the website
I am using a very hacky approach, using `insta` to generate the markdown help.
This is based on a lucky coincidence that `insta` chose to use a header
format for snapshot files that MkDocs interprets as a Markdown header (and
ignores).

I considered several other approaches, but I couldn't resist the facts that:

- This doesn't require new developers to install any extra tools or run any
extra commands.
- There is no need for a new CI check.
- There is no need to compile `jj` in the "Make HTML docs" GitHub action,
  which is currently very fast and cheap.

Downside: I'm not sure how well MkDocs will work on Windows, unless the
developer explicitly enables symbolic links (which IIUC is not trivial).

### Possible alternatives 

My next favorite approaches (which we could switch to later) would be:

#### `xtask`

Set up a CI check and a  [Cargo `xtask`]  so that `cargo xtask cli-help-to-md`
essentially runs `cargo run -- util markdown-help > docs/cli-reference.md` from
the project root.

Every developer would have to know to run `cargo xtask cli-help-to-md` if
they change the help text.

Eventually, we could have `cargo xtask preflight` that runs `cargo +nightly
fmt; cargo xtask cli-help-to-md; cargo nextest run`, or `cargo insta`.

#### Only generate markdown for CLI help when building the website, don't track it in Git.

I think that having the file in the repo will be nice to preview changes to
docs, and it'll allow people to consult the file on GitHub or in their repo.

The (currently) very fast job of building the website would now require
installing Rust and building `jj`. 

#### Same as the `xtask`, but use a shell script instead of an `xtask`

An `xtask` might seem like overkill, since it's Rust instead of a shell script.
However, I don't want this to be a shell script so that new contributors on
Windows can still easily run it ( since this will be necessary for the CI to
pass) without us having to support a batch file.

#### Cargo Alias

My first attempt was to set up a [cargo alias] to run this, but that doesn't
support redirection (so I had to change the `jj util` command to output to a
file) and, worse, is incapable of executing the command *in the project root*
regardless of where in the project the current directory is. Again, this seems
to be too inconvenient for a command that every new PR author would have to run
to pass CI.

Overall, this just seems a bit ugly. I did file
https://github.com/rust-lang/cargo/issues/13348, I'm not really sure that was
worthwhile, though.

**Aside:** For reference, the alias was:
    
```toml
# .cargo/config.toml
alias.gen-cli-reference = "run -p jj-cli -- util markdown-help docs/cli-reference.md"
```

### Non-alternatives 

#### Clap's new feature

`clap` recently obtained a similarly-sounding feature in
https://github.com/clap-rs/clap/pull/5206. However, it only prints short help
for subcommands and can't be triggered by an option AFAICT, so it won't help us
too much.

[Cargo `xtask`]: https://github.com/matklad/cargo-xtask
[cargo alias]: https://doc.rust-lang.org/cargo/reference/config.html#alias
2024-01-30 14:58:32 -08:00
..
common testing: allow testing of commands that expect stdin 2024-01-22 13:58:45 -08:00
cli-reference@.md.snap docs: store output of jj util markdown-help, render it on the website 2024-01-30 14:58:32 -08:00
test_abandon_command.rs test_abandon_command: create another test for bug 2600 2023-12-01 17:03:44 -08:00
test_alias.rs cli: don't panic on empty alias substitution 2023-12-24 23:31:28 +09:00
test_branch_command.rs revset: add count_estimate() to Revset trait 2024-01-22 15:07:00 -08:00
test_builtin_aliases.rs tests: set git_settings.auto_local_branch where it matters 2023-12-17 08:30:24 +09:00
test_cat_command.rs
test_checkout.rs
test_chmod_command.rs cli: print a hint about how to resolve conflicts 2023-12-10 12:44:57 -08:00
test_commit_command.rs clippy: fix new issues spotted by nightly version 2023-11-16 10:20:07 -08:00
test_commit_template.rs cli: include branches and tags in default "show" template 2024-01-11 15:47:09 +09:00
test_concurrent_operations.rs cli: give root operation special treatment in template (like root commit) 2024-01-14 10:15:14 -08:00
test_config_command.rs Support --user and --repo argument for config list command 2024-01-17 11:19:23 -08:00
test_debug_command.rs op_store: add a virtual root operation, similar to root commit 2024-01-14 10:15:14 -08:00
test_describe_command.rs clippy: run cargo clippy --fix --workspace with recent nightly 2023-10-29 20:19:44 -07:00
test_diff_command.rs cli: change R to D for "deleted" in diff summary 2024-01-26 10:01:40 -08:00
test_diffedit_command.rs cli: change R to D for "deleted" in diff summary 2024-01-26 10:01:40 -08:00
test_duplicate_command.rs
test_edit_command.rs git_backend: replace git2::Repository with gix::Repository 2023-11-02 19:33:06 +09:00
test_generate_md_cli_help.rs docs: store output of jj util markdown-help, render it on the website 2024-01-30 14:58:32 -08:00
test_git_clone.rs tests: set git_settings.auto_local_branch where it matters 2023-12-17 08:30:24 +09:00
test_git_colocated.rs cli: reorder import of git head/refs and snapshot 2024-01-27 00:01:59 +09:00
test_git_fetch.rs git: turn git.auto-local-branch off by default 2023-12-17 08:30:24 +09:00
test_git_import_export.rs object_id: make ObjectId constructors non-trait methods 2024-01-05 23:36:57 +09:00
test_git_push.rs tests: set git_settings.auto_local_branch where it matters 2023-12-17 08:30:24 +09:00
test_git_remotes.rs tests: don't create new branch by "jj branch set" 2023-11-11 07:03:31 +09:00
test_git_submodule.rs
test_gitignores.rs
test_global_opts.rs cli: error out early if -R path is invalid 2023-12-24 00:20:38 +09:00
test_immutable_commits.rs immutable commits: remove the hint if trying to edit the root commit 2023-10-29 21:13:39 -07:00
test_init_command.rs cli: on init, import git refs prior to importing HEAD 2024-01-27 00:01:59 +09:00
test_interdiff_command.rs
test_log_command.rs tests: don't create new branch by "jj branch set" 2023-11-11 07:03:31 +09:00
test_move_command.rs
test_new_command.rs cli new: have --no-edit print description of the new commit 2023-11-23 11:15:38 -08:00
test_next_prev_commands.rs next: support prompting for ambiguous commit targets 2024-01-22 13:58:45 -08:00
test_obslog_command.rs
test_operations.rs cli: give root operation special treatment in template (like root commit) 2024-01-14 10:15:14 -08:00
test_rebase_command.rs cli rebase: tests for weird ancestry for -s and -b 2023-11-28 21:36:51 -08:00
test_repo_change_report.rs cli: print a hint about how to resolve conflicts 2023-12-10 12:44:57 -08:00
test_resolve_command.rs cli: display which file's conflicts are being resolved 2024-01-23 08:59:43 -08:00
test_restore_command.rs cli: change R to D for "deleted" in diff summary 2024-01-26 10:01:40 -08:00
test_revset_output.rs
test_root.rs cli: move jj workspace root to `jj root, for discoverability 2024-01-25 16:31:44 -05:00
test_show_command.rs
test_sparse_command.rs
test_split_command.rs test_split_command: check that new commits inherit author dates 2023-12-24 19:25:16 -08:00
test_squash_command.rs
test_status_command.rs
test_tag_command.rs Implement tag command. 2024-01-22 09:23:18 -08:00
test_templater.rs
test_tree_level_conflicts.rs
test_undo.rs cli: remove weird line break from the "jj branch forget" hint 2023-12-16 07:50:15 +09:00
test_unsquash_command.rs
test_untrack_command.rs
test_util_command.rs util gc: allow specifying prune time 2024-01-24 09:29:40 -08:00
test_working_copy.rs
test_workspaces.rs op_store: add a virtual root operation, similar to root commit 2024-01-14 10:15:14 -08:00