generated from PlexSheep/baserepo
Compare commits
31 Commits
Author | SHA1 | Date |
---|---|---|
Christoph J. Scherr | 11a2d7908e | |
Christoph J. Scherr | 90e3442b50 | |
Christoph J. Scherr | 30168c5523 | |
Christoph J. Scherr | a7d0c18f52 | |
Christoph J. Scherr | 54a694645f | |
Christoph J. Scherr | 492e655d29 | |
Christoph J. Scherr | a9fbcf9518 | |
Christoph J. Scherr | 51e2c3029e | |
Christoph J. Scherr | 6197532bc7 | |
Christoph J. Scherr | 3063f77798 | |
Christoph J. Scherr | 05910ae3be | |
PlexSheep | 895b156e02 | |
Christoph J. Scherr | 35ab3d9b28 | |
Christoph J. Scherr | 917a68c8ab | |
Christoph J. Scherr | 5b0c82cf2b | |
Christoph J. Scherr | 3bf60f86b1 | |
Christoph J. Scherr | 056c2d136c | |
Christoph J. Scherr | 235a8bfb85 | |
Christoph J. Scherr | 29beabdc29 | |
Christoph J. Scherr | 17a235c1da | |
Christoph J. Scherr | 4ff85b881c | |
Christoph J. Scherr | 3a215390d6 | |
Christoph J. Scherr | 442e17f9a8 | |
cscherrNT | 687fd94870 | |
Christoph J. Scherr | 7eb7d95f94 | |
Christoph J. Scherr | 43944b0e34 | |
Christoph J. Scherr | b8acb7300e | |
cscherrNT | d48b87dcfe | |
Christoph J. Scherr | 6116d639b2 | |
Christoph J. Scherr | 5c6e5b242e | |
PlexSheep | ca3cabf6ca |
|
@ -21,8 +21,6 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
rustup component add rustfmt
|
rustup component add rustfmt
|
||||||
rustup component add clippy
|
rustup component add clippy
|
||||||
- name: install python
|
|
||||||
run: apt update && apt install libpython3-dev -y
|
|
||||||
- name: config custom registry
|
- name: config custom registry
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.cargo/
|
mkdir -p ~/.cargo/
|
||||||
|
@ -45,4 +43,4 @@ jobs:
|
||||||
with:
|
with:
|
||||||
# Optional. Commit message for the created commit.
|
# Optional. Commit message for the created commit.
|
||||||
# Defaults to "Apply automatic changes"
|
# Defaults to "Apply automatic changes"
|
||||||
commit_message: automatic cargo CI changes
|
commit_message: "ci: automatic cargo CI changes"
|
|
@ -0,0 +1,7 @@
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
# Check for updates every Monday
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
|
@ -1,10 +1,16 @@
|
||||||
name: cargo devel CI
|
name: Rust CI
|
||||||
on:
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- '**'
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- '**'
|
- '**'
|
||||||
# - '!master'
|
# - '!master'
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
CI:
|
CI:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -42,10 +48,10 @@ jobs:
|
||||||
- name: cargo fmt
|
- name: cargo fmt
|
||||||
run: cargo fmt --all
|
run: cargo fmt --all
|
||||||
- name: cargo test
|
- name: cargo test
|
||||||
run: cargo test --all-features --all-targets --workspace && cargo test --all-features --workspace --doc
|
run: cargo test --all-features --all-targets --workspace
|
||||||
- name: commit back to repository
|
- name: commit back to repository
|
||||||
uses: stefanzweifel/git-auto-commit-action@v5
|
uses: stefanzweifel/git-auto-commit-action@v5
|
||||||
with:
|
with:
|
||||||
# Optional. Commit message for the created commit.
|
# Optional. Commit message for the created commit.
|
||||||
# Defaults to "Apply automatic changes"
|
# Defaults to "Apply automatic changes"
|
||||||
commit_message: automatic cargo CI changes
|
commit_message: "ci: automatic Rust CI changes"
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
name: Release-plz
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
# Release unpublished packages.
|
||||||
|
release-plz-release:
|
||||||
|
name: Release-plz release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Run release-plz
|
||||||
|
uses: MarcoIeni/release-plz-action@v0.5
|
||||||
|
with:
|
||||||
|
command: release
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
# Create a PR with the new versions and changelog, preparing the next release.
|
||||||
|
release-plz-pr:
|
||||||
|
name: Release-plz PR
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
concurrency:
|
||||||
|
group: release-plz-${{ github.ref }}
|
||||||
|
cancel-in-progress: false
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Run release-plz
|
||||||
|
uses: MarcoIeni/release-plz-action@v0.5
|
||||||
|
with:
|
||||||
|
command: release-pr
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
17
Cargo.toml
17
Cargo.toml
|
@ -5,7 +5,7 @@ default-members = [".", "members/libpt-core"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
publish = true
|
publish = true
|
||||||
version = "0.6.0"
|
version = "0.7.3-alpha.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Christoph J. Scherr <software@cscherr.de>"]
|
authors = ["Christoph J. Scherr <software@cscherr.de>"]
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
|
@ -19,10 +19,10 @@ categories = ["command-line-utilities", "development-tools"]
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
anyhow = "1.0.79"
|
anyhow = "1.0.79"
|
||||||
thiserror = "1.0.56"
|
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-bintols = { version = "0.5.1", path = "members/libpt-bintols" }
|
||||||
libpt-log = { version = "0.5.1", path = "members/libpt-log" }
|
libpt-log = { version = "0.6.2-alpha.1", path = "members/libpt-log" }
|
||||||
libpt-cli = { version = "0.1.2", path = "members/libpt-cli" }
|
libpt-cli = { version = "0.2.2-alpha.1", path = "members/libpt-cli" }
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "libpt"
|
name = "libpt"
|
||||||
|
@ -41,8 +41,9 @@ categories.workspace = true
|
||||||
[features]
|
[features]
|
||||||
default = ["log", "core"]
|
default = ["log", "core"]
|
||||||
core = []
|
core = []
|
||||||
full = ["default", "core", "log", "bintols"]
|
full = ["default", "core", "log", "bintols", "libpt-cli/full"]
|
||||||
log = ["dep:libpt-log"]
|
log = ["dep:libpt-log"]
|
||||||
|
log-crate = ["libpt-cli/log"]
|
||||||
bintols = ["dep:libpt-bintols", "log"]
|
bintols = ["dep:libpt-bintols", "log"]
|
||||||
cli = ["dep:libpt-cli", "core", "log"]
|
cli = ["dep:libpt-cli", "core", "log"]
|
||||||
|
|
||||||
|
@ -58,4 +59,8 @@ crate-type = [
|
||||||
libpt-core = { workspace = true }
|
libpt-core = { workspace = true }
|
||||||
libpt-bintols = { workspace = true, optional = true }
|
libpt-bintols = { workspace = true, optional = true }
|
||||||
libpt-log = { 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"]
|
||||||
|
|
11
README.md
11
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)
|
## 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)
|
## Installing from [crates.io](https://crates.io)
|
||||||
|
|
||||||
|
|
||||||
`libpt` has been packaged for [crates.io](https://crates.io/crates/libpt).
|
`libpt` has been packaged for [crates.io](https://crates.io/crates/libpt).
|
||||||
|
|
||||||
You can add the library to your project with `cargo add libpt`.
|
You can add the library to your project with `cargo add libpt`.
|
||||||
|
|
|
@ -20,3 +20,7 @@ libpt-core = { workspace = true }
|
||||||
libpt-log = { workspace = true }
|
libpt-log = { workspace = true }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
all-features = true
|
||||||
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "libpt-cli"
|
name = "libpt-cli"
|
||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
version = "0.1.2"
|
version = "0.2.2-alpha.2"
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
|
@ -12,11 +12,9 @@ repository.workspace = true
|
||||||
keywords.workspace = true
|
keywords.workspace = true
|
||||||
categories.workspace = true
|
categories.workspace = true
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
|
||||||
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
full = ["log"]
|
||||||
log = ["dep:log"]
|
log = ["dep:log"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -26,11 +24,14 @@ comfy-table = "7.1.1"
|
||||||
console = "0.15.8"
|
console = "0.15.8"
|
||||||
dialoguer = { version = "0.11.0", features = ["completion", "history"] }
|
dialoguer = { version = "0.11.0", features = ["completion", "history"] }
|
||||||
embed-doc-image = "0.1.4"
|
embed-doc-image = "0.1.4"
|
||||||
exitcode = "1.1.2"
|
|
||||||
human-panic = "2.0.0"
|
|
||||||
indicatif = "0.17.8"
|
indicatif = "0.17.8"
|
||||||
libpt-log = { workspace = true, optional = false }
|
libpt-log = { workspace = true, optional = false }
|
||||||
log = { version = "0.4.21", optional = true }
|
log = { version = "0.4.21", optional = true }
|
||||||
|
serde = { version = "1.0.209", features = ["derive"] }
|
||||||
shlex = "1.3.0"
|
shlex = "1.3.0"
|
||||||
strum = { version = "0.26.3", features = ["derive"] }
|
strum = { version = "0.26.3", features = ["derive"] }
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
all-features = true
|
||||||
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use libpt_cli::args::VerbosityLevel;
|
use libpt_cli::args::VerbosityLevel;
|
||||||
use libpt_cli::{clap, printing};
|
use libpt_cli::printing;
|
||||||
use libpt_log::{debug, Logger};
|
use libpt_log::{debug, Logger};
|
||||||
|
|
||||||
/// This is the help
|
/// This is the help
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use console::style;
|
use console::style;
|
||||||
|
use libpt_cli::printing;
|
||||||
use libpt_cli::repl::{DefaultRepl, Repl};
|
use libpt_cli::repl::{DefaultRepl, Repl};
|
||||||
use libpt_cli::{clap, printing, strum};
|
use libpt_log::{debug, Logger};
|
||||||
use libpt_log::{debug, Level, Logger};
|
|
||||||
|
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use strum::EnumIter;
|
use strum::EnumIter;
|
||||||
|
@ -73,7 +73,7 @@ fn main() -> anyhow::Result<()> {
|
||||||
if !fancy {
|
if !fancy {
|
||||||
println!("{}", text.join(" "))
|
println!("{}", text.join(" "))
|
||||||
} else {
|
} else {
|
||||||
printing::blockprint(&text.join(" "), console::Color::Cyan)
|
printing::blockprint(text.join(" "), console::Color::Cyan)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ use clap::Parser;
|
||||||
use libpt_log::Level;
|
use libpt_log::Level;
|
||||||
#[cfg(feature = "log")]
|
#[cfg(feature = "log")]
|
||||||
use log;
|
use log;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// Custom help template for displaying command-line usage information
|
/// Custom help template for displaying command-line usage information
|
||||||
///
|
///
|
||||||
|
@ -18,7 +19,7 @@ use log;
|
||||||
/// # use libpt_cli::args::HELP_TEMPLATE;
|
/// # use libpt_cli::args::HELP_TEMPLATE;
|
||||||
/// use clap::Parser;
|
/// use clap::Parser;
|
||||||
/// #[derive(Parser, Debug, Clone, PartialEq, Eq, Hash)]
|
/// #[derive(Parser, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
/// #[command(help_template = HELP_TEMPLATE)]
|
/// #[command(help_template = HELP_TEMPLATE, author, version)]
|
||||||
/// pub struct MyArgs {
|
/// pub struct MyArgs {
|
||||||
/// /// show more details
|
/// /// show more details
|
||||||
/// #[arg(short, long)]
|
/// #[arg(short, long)]
|
||||||
|
@ -77,9 +78,9 @@ Author: {author-with-newline}
|
||||||
/// Get the loglevel like this:
|
/// Get the loglevel like this:
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # use libpt_cli::args::VerbosityLevel;
|
/// use libpt_cli::args::VerbosityLevel;
|
||||||
/// use libpt_log::Level;
|
/// use libpt_log::Level;
|
||||||
/// # use clap::Parser;
|
/// use clap::Parser;
|
||||||
///
|
///
|
||||||
/// # #[derive(Parser, Debug)]
|
/// # #[derive(Parser, Debug)]
|
||||||
/// # pub struct Opts {
|
/// # pub struct Opts {
|
||||||
|
@ -95,7 +96,7 @@ Author: {author-with-newline}
|
||||||
/// let level: Level = opts.verbose.level();
|
/// let level: Level = opts.verbose.level();
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Parser, Clone, PartialEq, Eq, Hash)]
|
#[derive(Parser, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
|
||||||
pub struct VerbosityLevel {
|
pub struct VerbosityLevel {
|
||||||
/// make the output more verbose
|
/// make the output more verbose
|
||||||
#[arg(
|
#[arg(
|
||||||
|
|
|
@ -4,13 +4,3 @@
|
||||||
pub mod args;
|
pub mod args;
|
||||||
pub mod printing;
|
pub mod printing;
|
||||||
pub mod repl;
|
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;
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ use console::{style, Color};
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use libpt_cli::console::Color;
|
/// use console::Color;
|
||||||
/// use libpt_cli::printing::blockprint;
|
/// use libpt_cli::printing::blockprint;
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
/// blockprint("Hello world!", Color::Blue);
|
/// blockprint("Hello world!", Color::Blue);
|
||||||
|
@ -64,7 +64,7 @@ pub fn blockprint(content: impl ToString, color: Color) {
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use libpt_cli::console::Color;
|
/// use console::Color;
|
||||||
/// use libpt_cli::printing::blockfmt;
|
/// use libpt_cli::printing::blockfmt;
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
/// let formatted_content = blockfmt("Hello world!", Color::Blue);
|
/// let formatted_content = blockfmt("Hello world!", Color::Blue);
|
||||||
|
@ -93,8 +93,8 @@ pub fn blockfmt(content: impl ToString, color: Color) -> String {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// use libpt_cli::comfy_table::{presets, CellAlignment, ContentArrangement};
|
/// use comfy_table::{presets, CellAlignment, ContentArrangement};
|
||||||
/// use libpt_cli::console::Color;
|
/// use console::Color;
|
||||||
/// use libpt_cli::printing::blockfmt_advanced;
|
/// use libpt_cli::printing::blockfmt_advanced;
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
/// println!(
|
/// println!(
|
||||||
|
|
|
@ -27,8 +27,8 @@ use libpt_log::trace;
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// use libpt_cli::repl::{DefaultRepl, Repl};
|
/// use libpt_cli::repl::{DefaultRepl, Repl};
|
||||||
/// use libpt_cli::clap::Subcommand;
|
/// use clap::Subcommand;
|
||||||
/// use libpt_cli::strum::EnumIter;
|
/// use strum::EnumIter;
|
||||||
///
|
///
|
||||||
/// #[derive(Subcommand, Debug, EnumIter, Clone)]
|
/// #[derive(Subcommand, Debug, EnumIter, Clone)]
|
||||||
/// enum ReplCommand {
|
/// enum ReplCommand {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "libpt-core"
|
name = "libpt-core"
|
||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
|
@ -14,6 +14,9 @@ categories.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.79"
|
anyhow = "1.0.79"
|
||||||
libpt-log = { workspace = true }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
all-features = true
|
||||||
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
|
@ -8,3 +8,16 @@
|
||||||
|
|
||||||
/// macros to make things faster in your code
|
/// macros to make things faster in your code
|
||||||
pub mod macros;
|
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<String> {
|
||||||
|
if let Ok(exe) = std::env::current_exe() {
|
||||||
|
return Some(exe.file_stem()?.to_str()?.to_string());
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "libpt-log"
|
name = "libpt-log"
|
||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
version = "0.5.1"
|
version = "0.6.2-alpha.2"
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
|
@ -13,11 +13,17 @@ keywords.workspace = true
|
||||||
categories.workspace = true
|
categories.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tracing = "0.1.37"
|
tracing = "0.1.40"
|
||||||
tracing-appender = "0.2.2"
|
tracing-appender = "0.2.3"
|
||||||
tracing-subscriber = "0.3.17"
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
|
libpt-core = { workspace = true, optional = false }
|
||||||
|
chrono = "0.4.38"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
gag = "1.0.0"
|
gag = "1.0.0"
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
all-features = true
|
||||||
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
|
@ -17,7 +17,9 @@ pub enum Error {
|
||||||
/// Could not assign logger as the global default
|
/// Could not assign logger as the global default
|
||||||
#[error("Could not assign logger as global default")]
|
#[error("Could not assign logger as global default")]
|
||||||
SetGlobalDefaultFail(#[from] SetGlobalDefaultError),
|
SetGlobalDefaultFail(#[from] SetGlobalDefaultError),
|
||||||
/// any other error type, wrapped in [anyhow::Error](anyhow::Error)
|
/// any other error type, wrapped in [`anyhow::Error`]
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Other(#[from] anyhow::Error),
|
Other(#[from] anyhow::Error),
|
||||||
|
#[error("Tried to open the logfile, but logging to file was not requested")]
|
||||||
|
LogfileButNoFilelog,
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#![warn(clippy::pedantic, clippy::style, clippy::nursery)]
|
#![warn(clippy::pedantic, clippy::style, clippy::nursery)]
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt,
|
fmt::{self, Debug},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::atomic::{AtomicBool, Ordering},
|
sync::atomic::{AtomicBool, Ordering},
|
||||||
};
|
};
|
||||||
|
@ -31,8 +31,9 @@ use error::Error;
|
||||||
/// I'm just repackaging it a little to make it more ergonomic
|
/// I'm just repackaging it a little to make it more ergonomic
|
||||||
pub use tracing;
|
pub use tracing;
|
||||||
pub use tracing::{debug, error, info, trace, warn, Level};
|
pub use tracing::{debug, error, info, trace, warn, Level};
|
||||||
use tracing_appender::{self};
|
use tracing_subscriber::{
|
||||||
use tracing_subscriber::fmt::{format::FmtSpan, time};
|
fmt::format::FmtSpan, layer::SubscriberExt as _, util::SubscriberInitExt, Layer,
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
/// The log level used when none is specified
|
/// The log level used when none is specified
|
||||||
|
@ -61,7 +62,7 @@ static INITIALIZED: AtomicBool = AtomicBool::new(false);
|
||||||
/// # }
|
/// # }
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||||
#[allow(clippy::struct_excessive_bools)] // it's just true/false values, not states, and I don't
|
#[allow(clippy::struct_excessive_bools)] // it's just true/false values, not states, and I don't
|
||||||
// need to reinvent the wheel
|
// need to reinvent the wheel
|
||||||
pub struct LoggerBuilder {
|
pub struct LoggerBuilder {
|
||||||
|
@ -94,6 +95,8 @@ pub struct LoggerBuilder {
|
||||||
show_time: bool,
|
show_time: bool,
|
||||||
/// show timestamps as uptime (duration since the logger was initialized)
|
/// show timestamps as uptime (duration since the logger was initialized)
|
||||||
uptime: bool,
|
uptime: bool,
|
||||||
|
/// log when span things happen
|
||||||
|
span_events: FmtSpan,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LoggerBuilder {
|
impl LoggerBuilder {
|
||||||
|
@ -128,100 +131,72 @@ impl LoggerBuilder {
|
||||||
/// This function will return an error if a global Logger was aready initialized. This module
|
/// This function will return an error if a global Logger was aready initialized. This module
|
||||||
/// uses the [tracing] crate for logging, so if a [tracing] logger is initialized elsewhere,
|
/// uses the [tracing] crate for logging, so if a [tracing] logger is initialized elsewhere,
|
||||||
/// this method will error.
|
/// this method will error.
|
||||||
|
#[allow(clippy::missing_panics_doc)]
|
||||||
pub fn build(self) -> Result<Logger> {
|
pub fn build(self) -> Result<Logger> {
|
||||||
// only init if no init has been performed yet
|
// only init if no init has been performed yet
|
||||||
if INITIALIZED.load(Ordering::Relaxed) {
|
if INITIALIZED.load(Ordering::Relaxed) {
|
||||||
warn!("trying to reinitialize the logger, ignoring");
|
warn!("trying to reinitialize the logger, ignoring");
|
||||||
bail!(Error::Usage("logging is already initialized".to_string()));
|
bail!(Error::Usage("logging is already initialized".to_string()));
|
||||||
}
|
}
|
||||||
let subscriber = tracing_subscriber::fmt::Subscriber::builder()
|
let layer = tracing_subscriber::fmt::layer()
|
||||||
.with_level(self.display_level)
|
|
||||||
.with_max_level(self.max_level)
|
|
||||||
.with_ansi(self.ansi)
|
.with_ansi(self.ansi)
|
||||||
.with_target(self.display_target)
|
.with_target(self.display_target)
|
||||||
.with_file(self.display_filename)
|
.with_file(self.display_filename)
|
||||||
.with_thread_ids(self.display_thread_ids)
|
.with_thread_ids(self.display_thread_ids)
|
||||||
.with_line_number(self.display_line_number)
|
.with_line_number(self.display_line_number)
|
||||||
.with_thread_names(self.display_thread_names)
|
.with_thread_names(self.display_thread_names)
|
||||||
.with_span_events(FmtSpan::FULL);
|
.with_span_events(self.span_events.clone())
|
||||||
// HACK: somehow find a better solution for this
|
.with_filter(tracing::level_filters::LevelFilter::from_level(
|
||||||
// I know this is hacky, but I couldn't get it any other way. I couldn't even find a
|
self.max_level,
|
||||||
// project that could do it any other way. You can't apply one after another, because the
|
));
|
||||||
// type is changed every time. When using `Box<dyn Whatever>`, some methods complain about
|
if self.log_to_file {
|
||||||
// not being in trait bounds.
|
tracing_subscriber::registry()
|
||||||
match (self.log_to_file, self.show_time, self.pretty, self.uptime) {
|
.with(layer.and_then({
|
||||||
(true, true, true, true) => {
|
tracing_subscriber::fmt::layer()
|
||||||
let subscriber = subscriber
|
.with_writer(
|
||||||
.with_writer(new_file_appender(self.log_dir))
|
self.logfile()?
|
||||||
.with_timer(time::uptime())
|
.expect("logging to file is requested but logfile returned None"),
|
||||||
.pretty()
|
)
|
||||||
.finish();
|
.with_ansi(self.ansi)
|
||||||
tracing::subscriber::set_global_default(subscriber)?;
|
.with_target(self.display_target)
|
||||||
}
|
.with_file(self.display_filename)
|
||||||
(true, true, true, false) => {
|
.with_thread_ids(self.display_thread_ids)
|
||||||
let subscriber = subscriber
|
.with_line_number(self.display_line_number)
|
||||||
.with_writer(new_file_appender(self.log_dir))
|
.with_thread_names(self.display_thread_names)
|
||||||
.pretty()
|
.with_span_events(self.span_events.clone())
|
||||||
.finish();
|
.with_filter(tracing::level_filters::LevelFilter::from_level(
|
||||||
tracing::subscriber::set_global_default(subscriber)?;
|
self.max_level,
|
||||||
}
|
))
|
||||||
(true, false, true, _) => {
|
}))
|
||||||
let subscriber = subscriber
|
.init();
|
||||||
.with_writer(new_file_appender(self.log_dir))
|
} else {
|
||||||
.without_time()
|
tracing_subscriber::registry().with(layer).init();
|
||||||
.pretty()
|
|
||||||
.finish();
|
|
||||||
tracing::subscriber::set_global_default(subscriber)?;
|
|
||||||
}
|
|
||||||
(true, true, false, true) => {
|
|
||||||
let subscriber = subscriber
|
|
||||||
.with_writer(new_file_appender(self.log_dir))
|
|
||||||
.with_timer(time::uptime())
|
|
||||||
.finish();
|
|
||||||
tracing::subscriber::set_global_default(subscriber)?;
|
|
||||||
}
|
|
||||||
(true, true, false, false) => {
|
|
||||||
let subscriber = subscriber
|
|
||||||
.with_writer(new_file_appender(self.log_dir))
|
|
||||||
.finish();
|
|
||||||
tracing::subscriber::set_global_default(subscriber)?;
|
|
||||||
}
|
|
||||||
(true, false, false, _) => {
|
|
||||||
let subscriber = subscriber
|
|
||||||
.with_writer(new_file_appender(self.log_dir))
|
|
||||||
.without_time()
|
|
||||||
.finish();
|
|
||||||
tracing::subscriber::set_global_default(subscriber)?;
|
|
||||||
}
|
|
||||||
(false, true, true, true) => {
|
|
||||||
let subscriber = subscriber.pretty().with_timer(time::uptime()).finish();
|
|
||||||
tracing::subscriber::set_global_default(subscriber)?;
|
|
||||||
}
|
|
||||||
(false, true, true, false) => {
|
|
||||||
let subscriber = subscriber.pretty().with_timer(time::uptime()).finish();
|
|
||||||
tracing::subscriber::set_global_default(subscriber)?;
|
|
||||||
}
|
|
||||||
(false, false, true, _) => {
|
|
||||||
let subscriber = subscriber.without_time().pretty().finish();
|
|
||||||
tracing::subscriber::set_global_default(subscriber)?;
|
|
||||||
}
|
|
||||||
(false, true, false, true) => {
|
|
||||||
let subscriber = subscriber.with_timer(time::uptime()).finish();
|
|
||||||
tracing::subscriber::set_global_default(subscriber)?;
|
|
||||||
}
|
|
||||||
(false, true, false, false) => {
|
|
||||||
let subscriber = subscriber.finish();
|
|
||||||
tracing::subscriber::set_global_default(subscriber)?;
|
|
||||||
}
|
|
||||||
(false, false, false, _) => {
|
|
||||||
let subscriber = subscriber.without_time().finish();
|
|
||||||
tracing::subscriber::set_global_default(subscriber)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
INITIALIZED.store(true, Ordering::Relaxed);
|
INITIALIZED.store(true, Ordering::Relaxed);
|
||||||
Ok(Logger {})
|
Ok(Logger {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Opens a new file for logging to.
|
||||||
|
///
|
||||||
|
/// Format: `{log_dir}/{consumer_name}_2024-09-01.log`
|
||||||
|
///
|
||||||
|
/// Will be none if [`Self::log_to_file`] is [false].
|
||||||
|
fn logfile(&self) -> Result<Option<std::fs::File>> {
|
||||||
|
if !self.log_to_file {
|
||||||
|
return Err(Error::LogfileButNoFilelog.into());
|
||||||
|
}
|
||||||
|
let mut path = self.log_dir.clone();
|
||||||
|
std::fs::create_dir_all(&path)?;
|
||||||
|
path.push(format!(
|
||||||
|
"{}_{}.log",
|
||||||
|
libpt_core::get_crate_name().unwrap_or_else(|| "logfile".to_string()),
|
||||||
|
chrono::Local::now().date_naive()
|
||||||
|
));
|
||||||
|
let file = std::fs::File::create(path)?;
|
||||||
|
Ok(Some(file))
|
||||||
|
}
|
||||||
|
|
||||||
/// enable or disable logging to and creating of logfiles
|
/// enable or disable logging to and creating of logfiles
|
||||||
///
|
///
|
||||||
/// If you want to log to a file, don't forget to set [`Self::log_dir`]!
|
/// If you want to log to a file, don't forget to set [`Self::log_dir`]!
|
||||||
|
@ -347,6 +322,15 @@ impl LoggerBuilder {
|
||||||
self.max_level = max_level;
|
self.max_level = max_level;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// set how span events are handled
|
||||||
|
///
|
||||||
|
/// Default: [`FmtSpan::NONE`]
|
||||||
|
#[must_use]
|
||||||
|
pub const fn span_events(mut self, span_events: FmtSpan) -> Self {
|
||||||
|
self.span_events = span_events;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for LoggerBuilder {
|
impl Default for LoggerBuilder {
|
||||||
|
@ -365,11 +349,12 @@ impl Default for LoggerBuilder {
|
||||||
pretty: false,
|
pretty: false,
|
||||||
show_time: true,
|
show_time: true,
|
||||||
uptime: false,
|
uptime: false,
|
||||||
|
span_events: FmtSpan::NONE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ## Logger for [`pt`](libpt)
|
/// ## Logger for `libpt`
|
||||||
///
|
///
|
||||||
/// A logger is generally a functionality that let's you write information from your library or
|
/// A logger is generally a functionality that let's you write information from your library or
|
||||||
/// application in a more structured manner than if you just wrote all information to `stdout` or
|
/// application in a more structured manner than if you just wrote all information to `stdout` or
|
||||||
|
@ -478,7 +463,3 @@ impl Default for Logger {
|
||||||
.expect("building a Logger failed")
|
.expect("building a Logger failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_file_appender(log_dir: PathBuf) -> tracing_appender::rolling::RollingFileAppender {
|
|
||||||
tracing_appender::rolling::daily(log_dir, format!("{}.log", env!("CARGO_CRATE_NAME")))
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
cargo check --all-features
|
cargo check --all-features --workspace
|
||||||
echo ">>>>>>>> SELECT A NEW VERSION"
|
echo ">>>>>>>> SELECT A NEW VERSION"
|
||||||
cargo ws version
|
cargo ws version
|
||||||
NEW_VERSION=$(cat Cargo.toml | rg '^\s*version\s*=\s*"([^"]*)"\s*$' -or '$1')
|
NEW_VERSION=$(cat Cargo.toml | rg '^\s*version\s*=\s*"([^"]*)"\s*$' -or '$1')
|
||||||
|
|
Reference in New Issue