From ad7a3addb695b7e72d20e75cfbece02f5bcc4114 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Mon, 27 Nov 2023 13:56:43 +0100 Subject: [PATCH] cli: Add `rad config` command Displays the current configuration. Also move to our tree-sitter highlighter for pretty-printing JSON and remove the `json-color` dependency. --- Cargo.lock | 27 ++++++------- radicle-cli/Cargo.toml | 4 +- radicle-cli/examples/rad-config.md | 43 ++++++++++++++++++++ radicle-cli/src/commands.rs | 2 + radicle-cli/src/commands/config.rs | 58 +++++++++++++++++++++++++++ radicle-cli/src/commands/inspect.rs | 31 ++++---------- radicle-cli/src/main.rs | 7 ++++ radicle-cli/src/terminal.rs | 1 + radicle-cli/src/terminal/highlight.rs | 31 ++++++++++---- radicle-cli/src/terminal/json.rs | 15 +++++++ radicle-cli/tests/commands.rs | 15 +++++++ radicle-node/src/test/environment.rs | 1 + radicle-term/src/element.rs | 20 +++++++++ radicle/src/profile.rs | 14 +++---- 14 files changed, 215 insertions(+), 54 deletions(-) create mode 100644 radicle-cli/examples/rad-config.md create mode 100644 radicle-cli/src/commands/config.rs create mode 100644 radicle-cli/src/terminal/json.rs diff --git a/Cargo.lock b/Cargo.lock index 8aa9b9ef..ae9b40e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1668,17 +1668,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "json-color" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6dc8c55175cad7234a98cc3e31ba3009e276800271692ed3ad2c2f1c574b6e8" -dependencies = [ - "colored", - "serde", - "serde_json", -] - [[package]] name = "keccak" version = "0.1.4" @@ -2298,7 +2287,6 @@ dependencies = [ "anyhow", "chrono", "git-ref-format", - "json-color", "lexopt", "localtime", "log", @@ -2326,6 +2314,7 @@ dependencies = [ "tree-sitter-go", "tree-sitter-highlight", "tree-sitter-html", + "tree-sitter-json", "tree-sitter-md", "tree-sitter-python", "tree-sitter-ruby", @@ -3540,6 +3529,16 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-json" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d82d2e33ee675dc71289e2ace4f8f9cf96d36d81400e9dae5ea61edaf5dea6" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-md" version = "0.1.5" @@ -3592,9 +3591,9 @@ dependencies = [ [[package]] name = "tree-sitter-typescript" -version = "0.20.2" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "079c695c32d39ad089101c66393aeaca30e967fba3486a91f573d2f0e12d290a" +checksum = "a75049f0aafabb2aac205d7bb24da162b53dcd0cfb326785f25a2f32efa8071a" dependencies = [ "cc", "tree-sitter", diff --git a/radicle-cli/Cargo.toml b/radicle-cli/Cargo.toml index 7b8bea75..53047743 100644 --- a/radicle-cli/Cargo.toml +++ b/radicle-cli/Cargo.toml @@ -14,7 +14,6 @@ path = "src/main.rs" anyhow = { version = "1" } chrono = { version = "0.4.26", default-features = false, features = ["clock", "std"] } git-ref-format = { version = "0.3.0", features = ["macro"] } -json-color = { version = "0.7" } lexopt = { version = "0.2" } localtime = { version = "1.2.0" } log = { version = "0.4", features = ["std"] } @@ -32,8 +31,9 @@ thiserror = { version = "1" } timeago = { version = "0.3", default-features = false } tree-sitter = { version = "0.20.0" } tree-sitter-highlight = { version = "0.20" } +tree-sitter-json = { version = "0.20.1" } tree-sitter-rust = { version = "0.20" } -tree-sitter-typescript = { version = "0.20" } +tree-sitter-typescript = { version = "0.20.3" } # N.b. This crate has a C++ token scanner that causes problems when building # for the musl target. Hence it is optional for now. tree-sitter-html = { version = "0.19", optional = true } diff --git a/radicle-cli/examples/rad-config.md b/radicle-cli/examples/rad-config.md new file mode 100644 index 00000000..d750a398 --- /dev/null +++ b/radicle-cli/examples/rad-config.md @@ -0,0 +1,43 @@ +The `rad config` command is used to manage the local user configuration. +In its simplest form, `rad config` prints the current configuration. + +``` +$ rad config +{ + "publicExplorer": "https://app.radicle.xyz/nodes/$host/$rid", + "preferredSeeds": [], + "cli": { + "hints": false + }, + "node": { + "alias": "alice", + "listen": [], + "peers": { + "type": "dynamic", + "target": 8 + }, + "connect": [], + "externalAddresses": [], + "network": "main", + "relay": true, + "limits": { + "routingMaxSize": 1000, + "routingMaxAge": 604800, + "gossipMaxAge": 1209600, + "fetchConcurrency": 1, + "rate": { + "inbound": { + "fillRate": 0.2, + "capacity": 32 + }, + "outbound": { + "fillRate": 1.0, + "capacity": 64 + } + } + }, + "policy": "block", + "scope": "trusted" + } +} +``` diff --git a/radicle-cli/src/commands.rs b/radicle-cli/src/commands.rs index 6b9d6021..8e7e574c 100644 --- a/radicle-cli/src/commands.rs +++ b/radicle-cli/src/commands.rs @@ -10,6 +10,8 @@ pub mod rad_clean; pub mod rad_clone; #[path = "commands/cob.rs"] pub mod rad_cob; +#[path = "commands/config.rs"] +pub mod rad_config; #[path = "commands/diff.rs"] pub mod rad_diff; #[path = "commands/fork.rs"] diff --git a/radicle-cli/src/commands/config.rs b/radicle-cli/src/commands/config.rs new file mode 100644 index 00000000..fef7f738 --- /dev/null +++ b/radicle-cli/src/commands/config.rs @@ -0,0 +1,58 @@ +#![allow(clippy::or_fun_call)] +use std::ffi::OsString; + +use anyhow::anyhow; + +use crate::terminal as term; +use crate::terminal::args::{Args, Error, Help}; +use crate::terminal::Element as _; + +pub const HELP: Help = Help { + name: "config", + description: "Manage your local radicle configuration", + version: env!("CARGO_PKG_VERSION"), + usage: r#" +Usage + + rad config [