diff --git a/Cargo.lock b/Cargo.lock index 2ce0869ed1..28444f6a29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -160,7 +160,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -435,7 +435,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -505,6 +505,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "coolor" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e93977247fb916abeee1ff8c6594c9b421fd9c26c9b720a3944acb2a7de27b" +dependencies = [ + "crossterm", +] + [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -565,6 +574,32 @@ dependencies = [ "itertools 0.10.5", ] +[[package]] +name = "crokey" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b48209802ec5862bb034cb16719eec24d1c759e62921be7d3c899d0d85f3344b" +dependencies = [ + "crokey-proc_macros", + "crossterm", + "once_cell", + "serde", + "strict", +] + +[[package]] +name = "crokey-proc_macros" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "397d3c009d8df93c4b063ddaa44a81ee7098feb056f99b00896c36e2cee9a9f7" +dependencies = [ + "crossterm", + "proc-macro2", + "quote", + "strict", + "syn 1.0.109", +] + [[package]] name = "crossbeam" version = "0.8.4" @@ -882,7 +917,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -1239,7 +1274,7 @@ checksum = "999ce923619f88194171a67fb3e6d613653b8d4d6078b529b15a765da0edcc17" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -1707,6 +1742,7 @@ dependencies = [ "insta", "itertools 0.12.1", "jj-cli", + "jj-docs", "jj-lib", "libc", "maplit", @@ -1723,6 +1759,7 @@ dependencies = [ "slab", "strsim", "tempfile", + "termimad", "test-case", "testutils", "textwrap", @@ -1804,7 +1841,7 @@ version = "0.18.0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -1835,6 +1872,29 @@ dependencies = [ "rayon", ] +[[package]] +name = "lazy-regex" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d12be4595afdf58bd19e4a9f4e24187da2a66700786ff660a418e9059937a4c" +dependencies = [ + "lazy-regex-proc_macros", + "once_cell", + "regex", +] + +[[package]] +name = "lazy-regex-proc_macros" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44bcd58e6c97a7fcbaffcdc95728b393b8d98933bfadad49ed4097845b57ef0b" +dependencies = [ + "proc-macro2", + "quote", + "regex", + "syn 2.0.66", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1965,6 +2025,15 @@ dependencies = [ "libc", ] +[[package]] +name = "minimad" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c5d708226d186590a7b6d4a9780e2bdda5f689e0d58cd17012a298efd745d2" +dependencies = [ + "once_cell", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2203,7 +2272,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -2335,7 +2404,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" dependencies = [ "proc-macro2", - "syn", + "syn 2.0.66", ] [[package]] @@ -2380,7 +2449,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn", + "syn 2.0.66", "tempfile", ] @@ -2394,7 +2463,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -2522,7 +2591,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -2616,7 +2685,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn", + "syn 2.0.66", "walkdir", ] @@ -2733,7 +2802,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -2856,7 +2925,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ff9eaf853dec4c8802325d8b6d3dffa86cc707fd7a1a4cdbf416e13b061787a" dependencies = [ "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -2865,6 +2934,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strict" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f42444fea5b87a39db4218d9422087e66a85d0e7a0963a439b07bcdf91804006" + [[package]] name = "strsim" version = "0.11.1" @@ -2890,7 +2965,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn", + "syn 2.0.66", ] [[package]] @@ -2899,6 +2974,17 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.66" @@ -2922,6 +3008,22 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "termimad" +version = "0.29.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aab6c8572830b10362f27e242c7c5e749f062ec310b76a0d0b56670eca81f28e" +dependencies = [ + "coolor", + "crokey", + "crossbeam", + "lazy-regex", + "minimad", + "serde", + "thiserror", + "unicode-width", +] + [[package]] name = "terminal_size" version = "0.3.0" @@ -2956,7 +3058,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -2967,7 +3069,7 @@ checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", "test-case-core", ] @@ -3013,7 +3115,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -3117,7 +3219,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -3186,7 +3288,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] @@ -3402,7 +3504,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.66", "wasm-bindgen-shared", ] @@ -3424,7 +3526,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3697,7 +3799,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.66", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3eda96c69c..e132200854 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,6 +100,7 @@ smallvec = { version = "1.13.2", features = [ strsim = "0.11.1" syn = "2.0.66" tempfile = "3.10.1" +termimad = "0.29.1" test-case = "3.3.1" textwrap = "0.16.1" thiserror = "1.0.61" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index fd1085b8b9..da39f29ae6 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -69,6 +69,7 @@ hex = { workspace = true } indexmap = { workspace = true } itertools = { workspace = true } jj-lib = { workspace = true } +jj-docs = { workspace = true } maplit = { workspace = true } minus = { workspace = true } once_cell = { workspace = true } @@ -83,6 +84,7 @@ serde = { workspace = true } slab = { workspace = true } strsim = { workspace = true } tempfile = { workspace = true } +termimad = { workspace = true } textwrap = { workspace = true } thiserror = { workspace = true } timeago = { workspace = true } diff --git a/cli/src/commands/docs.rs b/cli/src/commands/docs.rs new file mode 100644 index 0000000000..25483c6b14 --- /dev/null +++ b/cli/src/commands/docs.rs @@ -0,0 +1,67 @@ +// Copyright 2024 The Jujutsu Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use std::fmt::Debug; +use std::io::Write; + +use jj_docs::DocAssets; + +use crate::cli_util::CommandHelper; +use crate::command_error::{user_error, CommandError}; +use crate::ui::Ui; + +#[derive(clap::Args, Clone, Debug)] +pub(crate) struct DocsArgs { + /// The command to show documentation for + command: Option, +} + +pub fn cmd_docs( + ui: &mut Ui, + _command: &CommandHelper, + args: &DocsArgs, +) -> Result<(), CommandError> { + // just print all the documents in the static map, and the size of the contents + + let cmd = args.command.clone(); + match cmd { + None => { + for name in DocAssets::iter() { + // XXX FIXME (aseipp): show a real document index + let content = DocAssets::get(&name).unwrap(); + writeln!(ui.stdout(), "{}: {} bytes", name, content.len())?; + } + } + Some(command) => { + // print the document for the command, if it exists + if let Some(name) = DocAssets::iter().find(|name| name == &command) { + let skin = termimad::MadSkin::default(); + let content = DocAssets::get(&name).unwrap(); + writeln!( + ui.stdout(), + "{}", + skin.term_text(&String::from_utf8_lossy(&content)) + )?; + return Ok(()); + } else { + return Err(user_error(format!( + "No documentation found for item: {}", + command + ))); + } + } + } + + Ok(()) +} diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index 188147ad59..83cfe51e56 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -26,6 +26,7 @@ mod debug; mod describe; mod diff; mod diffedit; +mod docs; mod duplicate; mod edit; mod files; @@ -90,6 +91,7 @@ enum Command { Describe(describe::DescribeArgs), Diff(diff::DiffArgs), Diffedit(diffedit::DiffeditArgs), + Docs(docs::DocsArgs), Duplicate(duplicate::DuplicateArgs), Edit(edit::EditArgs), Files(files::FilesArgs), @@ -174,6 +176,7 @@ pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), Co Command::Files(sub_args) => files::cmd_files(ui, command_helper, sub_args), Command::Cat(sub_args) => cat::cmd_cat(ui, command_helper, sub_args), Command::Diff(sub_args) => diff::cmd_diff(ui, command_helper, sub_args), + Command::Docs(sub_args) => docs::cmd_docs(ui, command_helper, sub_args), Command::Show(sub_args) => show::cmd_show(ui, command_helper, sub_args), Command::Status(sub_args) => status::cmd_status(ui, command_helper, sub_args), Command::Log(sub_args) => log::cmd_log(ui, command_helper, sub_args), diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index 8b074b21e1..869870e404 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -34,6 +34,7 @@ This document contains the help content for the `jj` command-line program. * [`jj describe`↴](#jj-describe) * [`jj diff`↴](#jj-diff) * [`jj diffedit`↴](#jj-diffedit) +* [`jj docs`↴](#jj-docs) * [`jj duplicate`↴](#jj-duplicate) * [`jj edit`↴](#jj-edit) * [`jj files`↴](#jj-files) @@ -115,6 +116,7 @@ To get started, see the tutorial at https://github.com/martinvonz/jj/blob/main/d * `describe` — Update the change description or other metadata * `diff` — Compare file contents between two revisions * `diffedit` — Touch up the content changes in a revision with a diff editor +* `docs` — * `duplicate` — Create a new change with the same content as an existing one * `edit` — Sets the specified revision as the working-copy revision * `files` — List files in a revision @@ -701,6 +703,16 @@ See `jj restore` if you want to move entire files from one revision to another. +## `jj docs` + +**Usage:** `jj docs [COMMAND]` + +###### **Arguments:** + +* `` — The command to show documentation for + + + ## `jj duplicate` Create a new change with the same content as an existing one