diff --git a/Cargo.toml b/Cargo.toml index a7b63d6..4c8e166 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.1" 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.1", path = "members/libpt-cli" } [package] name = "libpt" @@ -41,8 +41,9 @@ 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"] cli = ["dep:libpt-cli", "core", "log"] @@ -58,4 +59,8 @@ 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"] } + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] 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`. 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 da25d65..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.1.2" +version = "0.2.1" edition.workspace = true authors.workspace = true license.workspace = true @@ -12,11 +12,9 @@ repository.workspace = true keywords.workspace = true categories.workspace = true -[package.metadata.docs.rs] -cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"] - [features] default = [] +full = ["log"] log = ["dep:log"] [dependencies] @@ -31,6 +29,11 @@ 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 + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] 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..640849d 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; @@ -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) } } } diff --git a/members/libpt-cli/src/args.rs b/members/libpt-cli/src/args.rs index 019179e..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 /// @@ -77,9 +78,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 { @@ -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( 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; 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 { diff --git a/members/libpt-core/Cargo.toml b/members/libpt-core/Cargo.toml index 1e7e90e..b4436bb 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,9 @@ categories.workspace = true [dependencies] anyhow = "1.0.79" -libpt-log = { workspace = true } [dev-dependencies] + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] 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/Cargo.toml b/members/libpt-log/Cargo.toml index 8a327a0..7ca99ad 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,11 @@ 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" + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] 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()) + ), + ) }