From b8acb7300e515d87d3a1f4f5f269ed9274e4c1fb Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 30 Aug 2024 13:34:21 +0200 Subject: [PATCH 01/11] chore: remove reexports for cli #93 --- members/libpt-cli/src/lib.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/members/libpt-cli/src/lib.rs b/members/libpt-cli/src/lib.rs index 965f94e..fbbde04 100644 --- a/members/libpt-cli/src/lib.rs +++ b/members/libpt-cli/src/lib.rs @@ -4,13 +4,3 @@ pub mod args; pub mod printing; pub mod repl; - -pub use clap; -pub use comfy_table; -pub use console; -pub use dialoguer; -pub use exitcode; -pub use human_panic; -pub use indicatif; -pub use shlex; -pub use strum; From 43944b0e34c98c81395f1311fb9f72af4b20aaa5 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 30 Aug 2024 16:02:11 +0200 Subject: [PATCH 02/11] fix: features in main crate were bad --- Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a7b63d6..ee61571 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,7 @@ default = ["log", "core"] core = [] full = ["default", "core", "log", "bintols"] log = ["dep:libpt-log"] +log-crate = ["libpt-cli/log"] bintols = ["dep:libpt-bintols", "log"] cli = ["dep:libpt-cli", "core", "log"] @@ -58,4 +59,4 @@ crate-type = [ libpt-core = { workspace = true } libpt-bintols = { workspace = true, optional = true } libpt-log = { workspace = true, optional = true } -libpt-cli = { workspace = true, optional = true } +libpt-cli = { workspace = true, optional = true, features = ["log"] } From 7eb7d95f9445df455fd182ca441967ce275ffbb4 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 30 Aug 2024 16:09:14 +0200 Subject: [PATCH 03/11] docs: fix cli example deps --- members/libpt-cli/examples/cli.rs | 2 +- members/libpt-cli/examples/repl.rs | 2 +- members/libpt-cli/src/args.rs | 4 ++-- members/libpt-cli/src/printing.rs | 8 ++++---- members/libpt-cli/src/repl/default.rs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/members/libpt-cli/examples/cli.rs b/members/libpt-cli/examples/cli.rs index 7dc4509..efc977c 100644 --- a/members/libpt-cli/examples/cli.rs +++ b/members/libpt-cli/examples/cli.rs @@ -1,6 +1,6 @@ use clap::Parser; use libpt_cli::args::VerbosityLevel; -use libpt_cli::{clap, printing}; +use libpt_cli::printing; use libpt_log::{debug, Logger}; /// This is the help diff --git a/members/libpt-cli/examples/repl.rs b/members/libpt-cli/examples/repl.rs index 162cd09..db4ae73 100644 --- a/members/libpt-cli/examples/repl.rs +++ b/members/libpt-cli/examples/repl.rs @@ -1,6 +1,6 @@ use console::style; +use libpt_cli::printing; use libpt_cli::repl::{DefaultRepl, Repl}; -use libpt_cli::{clap, printing, strum}; use libpt_log::{debug, Logger}; use clap::Subcommand; diff --git a/members/libpt-cli/src/args.rs b/members/libpt-cli/src/args.rs index 019179e..90e1252 100644 --- a/members/libpt-cli/src/args.rs +++ b/members/libpt-cli/src/args.rs @@ -77,9 +77,9 @@ Author: {author-with-newline} /// Get the loglevel like this: /// /// ```no_run -/// # use libpt_cli::args::VerbosityLevel; +/// use libpt_cli::args::VerbosityLevel; /// use libpt_log::Level; -/// # use clap::Parser; +/// use clap::Parser; /// /// # #[derive(Parser, Debug)] /// # pub struct Opts { diff --git a/members/libpt-cli/src/printing.rs b/members/libpt-cli/src/printing.rs index 6cf3c01..2546fda 100644 --- a/members/libpt-cli/src/printing.rs +++ b/members/libpt-cli/src/printing.rs @@ -42,7 +42,7 @@ use console::{style, Color}; /// # Example /// /// ``` -/// use libpt_cli::console::Color; +/// use console::Color; /// use libpt_cli::printing::blockprint; /// # fn main() { /// blockprint("Hello world!", Color::Blue); @@ -64,7 +64,7 @@ pub fn blockprint(content: impl ToString, color: Color) { /// # Example /// /// ``` -/// use libpt_cli::console::Color; +/// use console::Color; /// use libpt_cli::printing::blockfmt; /// # fn main() { /// let formatted_content = blockfmt("Hello world!", Color::Blue); @@ -93,8 +93,8 @@ pub fn blockfmt(content: impl ToString, color: Color) -> String { /// /// # Example /// ``` -/// use libpt_cli::comfy_table::{presets, CellAlignment, ContentArrangement}; -/// use libpt_cli::console::Color; +/// use comfy_table::{presets, CellAlignment, ContentArrangement}; +/// use console::Color; /// use libpt_cli::printing::blockfmt_advanced; /// # fn main() { /// println!( diff --git a/members/libpt-cli/src/repl/default.rs b/members/libpt-cli/src/repl/default.rs index ad22db9..789ad22 100644 --- a/members/libpt-cli/src/repl/default.rs +++ b/members/libpt-cli/src/repl/default.rs @@ -27,8 +27,8 @@ use libpt_log::trace; /// /// ```no_run /// use libpt_cli::repl::{DefaultRepl, Repl}; -/// use libpt_cli::clap::Subcommand; -/// use libpt_cli::strum::EnumIter; +/// use clap::Subcommand; +/// use strum::EnumIter; /// /// #[derive(Subcommand, Debug, EnumIter, Clone)] /// enum ReplCommand { From 687fd948705301f6f82f5aac5d45efafcba090cb Mon Sep 17 00:00:00 2001 From: cscherrNT Date: Fri, 30 Aug 2024 14:27:56 +0000 Subject: [PATCH 04/11] automatic cargo CI changes --- members/libpt-cli/examples/repl.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/members/libpt-cli/examples/repl.rs b/members/libpt-cli/examples/repl.rs index db4ae73..640849d 100644 --- a/members/libpt-cli/examples/repl.rs +++ b/members/libpt-cli/examples/repl.rs @@ -73,7 +73,7 @@ fn main() -> anyhow::Result<()> { if !fancy { println!("{}", text.join(" ")) } else { - printing::blockprint(&text.join(" "), console::Color::Cyan) + printing::blockprint(text.join(" "), console::Color::Cyan) } } } From 442e17f9a8fa5617eb0f257c29b1e506acbe9377 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 30 Aug 2024 17:39:10 +0200 Subject: [PATCH 05/11] fix: let logger use the crate name of the end-crate #91 --- members/libpt-core/src/lib.rs | 13 +++++++++++++ members/libpt-log/src/lib.rs | 8 +++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/members/libpt-core/src/lib.rs b/members/libpt-core/src/lib.rs index 848cd5c..93e71fd 100644 --- a/members/libpt-core/src/lib.rs +++ b/members/libpt-core/src/lib.rs @@ -8,3 +8,16 @@ /// macros to make things faster in your code pub mod macros; + +/// ## Get the name of the crate that uses your library +/// +/// Let's say you're writing the library `foo` and need the name of the crate that uses `foo`. With +/// this function, you can get the name of the crate that uses `foo`. +/// +/// Will return [None] if [`std::env::current_exe()`] errors or if conversion to [String] from [std::ffi::OsStr] fails. +pub fn get_crate_name() -> Option { + if let Ok(exe) = std::env::current_exe() { + return Some(exe.file_stem()?.to_str()?.to_string()); + } + None +} diff --git a/members/libpt-log/src/lib.rs b/members/libpt-log/src/lib.rs index fa5c697..e5f7f8b 100644 --- a/members/libpt-log/src/lib.rs +++ b/members/libpt-log/src/lib.rs @@ -480,5 +480,11 @@ impl Default for Logger { } fn new_file_appender(log_dir: PathBuf) -> tracing_appender::rolling::RollingFileAppender { - tracing_appender::rolling::daily(log_dir, format!("{}.log", env!("CARGO_CRATE_NAME"))) + tracing_appender::rolling::daily( + log_dir, + format!( + "{}.log", + libpt_core::get_crate_name().unwrap_or_else(|| "logfile".to_string()) + ), + ) } From 3a215390d6381e58a17c462d3c90edd4373727e9 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 30 Aug 2024 17:39:53 +0200 Subject: [PATCH 06/11] chore: bump version and fix deptree of workspace --- Cargo.toml | 8 ++++---- members/libpt-cli/Cargo.toml | 2 +- members/libpt-core/Cargo.toml | 3 +-- members/libpt-log/Cargo.toml | 3 ++- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ee61571..72df723 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ default-members = [".", "members/libpt-core"] [workspace.package] publish = true -version = "0.6.0" +version = "0.7.0" edition = "2021" authors = ["Christoph J. Scherr "] license = "GPL-3.0-or-later" @@ -19,10 +19,10 @@ categories = ["command-line-utilities", "development-tools"] [workspace.dependencies] anyhow = "1.0.79" thiserror = "1.0.56" -libpt-core = { version = "0.4.0", path = "members/libpt-core" } +libpt-core = { version = "0.5.0", path = "members/libpt-core" } libpt-bintols = { version = "0.5.1", path = "members/libpt-bintols" } -libpt-log = { version = "0.5.1", path = "members/libpt-log" } -libpt-cli = { version = "0.1.2", path = "members/libpt-cli" } +libpt-log = { version = "0.6.0", path = "members/libpt-log" } +libpt-cli = { version = "0.2.0", path = "members/libpt-cli" } [package] name = "libpt" diff --git a/members/libpt-cli/Cargo.toml b/members/libpt-cli/Cargo.toml index da25d65..afdde8c 100644 --- a/members/libpt-cli/Cargo.toml +++ b/members/libpt-cli/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libpt-cli" publish.workspace = true -version = "0.1.2" +version = "0.2.0" edition.workspace = true authors.workspace = true license.workspace = true diff --git a/members/libpt-core/Cargo.toml b/members/libpt-core/Cargo.toml index 1e7e90e..fd62331 100644 --- a/members/libpt-core/Cargo.toml +++ b/members/libpt-core/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libpt-core" publish.workspace = true -version = "0.4.0" +version = "0.5.0" edition.workspace = true authors.workspace = true license.workspace = true @@ -14,6 +14,5 @@ categories.workspace = true [dependencies] anyhow = "1.0.79" -libpt-log = { workspace = true } [dev-dependencies] diff --git a/members/libpt-log/Cargo.toml b/members/libpt-log/Cargo.toml index 8a327a0..2c05aaf 100644 --- a/members/libpt-log/Cargo.toml +++ b/members/libpt-log/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libpt-log" publish.workspace = true -version = "0.5.1" +version = "0.6.0" edition.workspace = true authors.workspace = true license.workspace = true @@ -18,6 +18,7 @@ tracing-appender = "0.2.2" tracing-subscriber = "0.3.17" anyhow = { workspace = true } thiserror = { workspace = true } +libpt-core = { workspace = true, optional = false } [dev-dependencies] gag = "1.0.0" From 4ff85b881c6048f5913cae2d35cd7ef6e13de124 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 30 Aug 2024 17:45:36 +0200 Subject: [PATCH 07/11] chore: full feature --- Cargo.toml | 2 +- members/libpt-cli/Cargo.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 72df723..53f72f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ categories.workspace = true [features] default = ["log", "core"] core = [] -full = ["default", "core", "log", "bintols"] +full = ["default", "core", "log", "bintols", "libpt-cli/full"] log = ["dep:libpt-log"] log-crate = ["libpt-cli/log"] bintols = ["dep:libpt-bintols", "log"] diff --git a/members/libpt-cli/Cargo.toml b/members/libpt-cli/Cargo.toml index afdde8c..ad47c02 100644 --- a/members/libpt-cli/Cargo.toml +++ b/members/libpt-cli/Cargo.toml @@ -17,6 +17,7 @@ cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"] [features] default = [] +full = ["log"] log = ["dep:log"] [dependencies] From 17a235c1da63573f7e595371128918473c8b9810 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 30 Aug 2024 17:49:40 +0200 Subject: [PATCH 08/11] chore: add docs.rs metadata #97 --- Cargo.toml | 4 ++++ members/libpt-bintols/Cargo.toml | 4 ++++ members/libpt-cli/Cargo.toml | 7 ++++--- members/libpt-core/Cargo.toml | 4 ++++ members/libpt-log/Cargo.toml | 4 ++++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 53f72f3..c0c5e08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,3 +60,7 @@ libpt-core = { workspace = true } libpt-bintols = { workspace = true, optional = true } libpt-log = { workspace = true, optional = true } libpt-cli = { workspace = true, optional = true, features = ["log"] } + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/members/libpt-bintols/Cargo.toml b/members/libpt-bintols/Cargo.toml index fe9e5af..d1d3d6a 100644 --- a/members/libpt-bintols/Cargo.toml +++ b/members/libpt-bintols/Cargo.toml @@ -20,3 +20,7 @@ libpt-core = { workspace = true } libpt-log = { workspace = true } anyhow = { workspace = true } thiserror = { workspace = true } + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/members/libpt-cli/Cargo.toml b/members/libpt-cli/Cargo.toml index ad47c02..85984a5 100644 --- a/members/libpt-cli/Cargo.toml +++ b/members/libpt-cli/Cargo.toml @@ -12,9 +12,6 @@ repository.workspace = true keywords.workspace = true categories.workspace = true -[package.metadata.docs.rs] -cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"] - [features] default = [] full = ["log"] @@ -35,3 +32,7 @@ log = { version = "0.4.21", optional = true } shlex = "1.3.0" strum = { version = "0.26.3", features = ["derive"] } thiserror.workspace = true + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/members/libpt-core/Cargo.toml b/members/libpt-core/Cargo.toml index fd62331..b4436bb 100644 --- a/members/libpt-core/Cargo.toml +++ b/members/libpt-core/Cargo.toml @@ -16,3 +16,7 @@ categories.workspace = true anyhow = "1.0.79" [dev-dependencies] + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/members/libpt-log/Cargo.toml b/members/libpt-log/Cargo.toml index 2c05aaf..7ca99ad 100644 --- a/members/libpt-log/Cargo.toml +++ b/members/libpt-log/Cargo.toml @@ -22,3 +22,7 @@ libpt-core = { workspace = true, optional = false } [dev-dependencies] gag = "1.0.0" + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] From 29beabdc2906902bc72f9141875d79af13ba270b Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 30 Aug 2024 17:52:58 +0200 Subject: [PATCH 09/11] docs: python not implemented notice #98 --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4f5336f..e96307e 100644 --- a/README.md +++ b/README.md @@ -40,12 +40,19 @@ If you want to use the python variant too, you need to compile with maturing. ## Installing from [pypi](https://pypi.org) -`libpt` has been packaged for [pypi.org](https://pypi.org/project/libpt/). +The Python interface of `libpt` is currently not implemented, but it is planned +to eventually re add it. Meanwhile, you can use a much older version if you +really want. -You can install it with `pip install libpt` +> :warning: **This will install a very old version** +> +> `libpt` has been packaged for [pypi.org](https://pypi.org/project/libpt/). +> +> You can install it with `pip install libpt` ## Installing from [crates.io](https://crates.io) + `libpt` has been packaged for [crates.io](https://crates.io/crates/libpt). You can add the library to your project with `cargo add libpt`. From 235a8bfb850c4fcec34a6d1682d3b53fd37c4668 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 6 Sep 2024 17:33:15 +0200 Subject: [PATCH 10/11] feat(cli): make VerbosityLevel serde compatible --- members/libpt-cli/Cargo.toml | 1 + members/libpt-cli/src/args.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/members/libpt-cli/Cargo.toml b/members/libpt-cli/Cargo.toml index 85984a5..f550cec 100644 --- a/members/libpt-cli/Cargo.toml +++ b/members/libpt-cli/Cargo.toml @@ -29,6 +29,7 @@ human-panic = "2.0.0" indicatif = "0.17.8" libpt-log = { workspace = true, optional = false } log = { version = "0.4.21", optional = true } +serde = { version = "1.0.209", features = ["derive"] } shlex = "1.3.0" strum = { version = "0.26.3", features = ["derive"] } thiserror.workspace = true diff --git a/members/libpt-cli/src/args.rs b/members/libpt-cli/src/args.rs index 90e1252..1d26114 100644 --- a/members/libpt-cli/src/args.rs +++ b/members/libpt-cli/src/args.rs @@ -4,6 +4,7 @@ use clap::Parser; use libpt_log::Level; #[cfg(feature = "log")] use log; +use serde::{Deserialize, Serialize}; /// Custom help template for displaying command-line usage information /// @@ -95,7 +96,7 @@ Author: {author-with-newline} /// let level: Level = opts.verbose.level(); /// } /// ``` -#[derive(Parser, Clone, PartialEq, Eq, Hash)] +#[derive(Parser, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct VerbosityLevel { /// make the output more verbose #[arg( From 056c2d136c789d3f91c7c427c91bf1bcca10d260 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 6 Sep 2024 17:33:57 +0200 Subject: [PATCH 11/11] chore: bump version --- Cargo.toml | 4 ++-- members/libpt-cli/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c0c5e08..4c8e166 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ default-members = [".", "members/libpt-core"] [workspace.package] publish = true -version = "0.7.0" +version = "0.7.1" edition = "2021" authors = ["Christoph J. Scherr "] license = "GPL-3.0-or-later" @@ -22,7 +22,7 @@ thiserror = "1.0.56" libpt-core = { version = "0.5.0", path = "members/libpt-core" } libpt-bintols = { version = "0.5.1", path = "members/libpt-bintols" } libpt-log = { version = "0.6.0", path = "members/libpt-log" } -libpt-cli = { version = "0.2.0", path = "members/libpt-cli" } +libpt-cli = { version = "0.2.1", path = "members/libpt-cli" } [package] name = "libpt" diff --git a/members/libpt-cli/Cargo.toml b/members/libpt-cli/Cargo.toml index f550cec..6c18b36 100644 --- a/members/libpt-cli/Cargo.toml +++ b/members/libpt-cli/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libpt-cli" publish.workspace = true -version = "0.2.0" +version = "0.2.1" edition.workspace = true authors.workspace = true license.workspace = true