clap-verbosity-flag-3.0.4/.cargo_vcs_info.json0000644000000001360000000000100147120ustar { "git": { "sha1": "5e051e6c9649352234c5500de6d80118ca56be91" }, "path_in_vcs": "" }clap-verbosity-flag-3.0.4/Cargo.lock0000644000000335560000000000100127010ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "aho-corasick" version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ "memchr", ] [[package]] name = "anstream" version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", "utf8parse", ] [[package]] name = "anstyle" version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" dependencies = [ "windows-sys", ] [[package]] name = "anstyle-wincon" version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" dependencies = [ "anstyle", "windows-sys", ] [[package]] name = "clap" version = "4.5.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "027bb0d98429ae334a8698531da7077bdf906419543a35a55c2cb1b66437d767" dependencies = [ "clap_builder", "clap_derive", ] [[package]] name = "clap-verbosity-flag" version = "3.0.4" dependencies = [ "clap", "env_logger", "log", "serde", "serde_test", "toml", "tracing", "tracing-core", "tracing-subscriber", ] [[package]] name = "clap_builder" version = "4.5.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5589e0cba072e0f3d23791efac0fd8627b49c829c196a492e88168e6a669d863" dependencies = [ "anstyle", "clap_lex", ] [[package]] name = "clap_derive" version = "4.5.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf4ced95c6f4a675af3da73304b9ac4ed991640c36374e4b46795c49e17cf1ed" dependencies = [ "heck", "proc-macro2", "quote", "syn", ] [[package]] name = "clap_lex" version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "colorchoice" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "env_filter" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" dependencies = [ "log", "regex", ] [[package]] name = "env_logger" version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcaee3d8e3cfc3fd92428d477bc97fc29ec8716d180c0d74c643bb26166660e0" dependencies = [ "anstream", "anstyle", "env_filter", "humantime", "log", ] [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "hashbrown" version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" [[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "indexmap" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", "hashbrown", ] [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "log" version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "nu-ansi-term" version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" dependencies = [ "overload", "winapi", ] [[package]] name = "once_cell" version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "overload" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "pin-project-lite" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" [[package]] name = "proc-macro2" version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dd5e8a1f1029c43224ad5898e50140c2aebb1705f19e67c918ebf5b9e797fe1" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22a37c9326af5ed140c86a46655b5278de879853be5573c01df185b6f49a580a" dependencies = [ "proc-macro2", ] [[package]] name = "regex" version = "1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" version = "0.6.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" [[package]] name = "serde" version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "serde_spanned" version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" dependencies = [ "serde", ] [[package]] name = "serde_test" version = "1.0.177" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f901ee573cab6b3060453d2d5f0bae4e6d628c23c0a962ff9b5f1d7c8d4f1ed" dependencies = [ "serde", ] [[package]] name = "sharded-slab" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" dependencies = [ "lazy_static", ] [[package]] name = "smallvec" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" version = "2.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92d27c2c202598d05175a6dd3af46824b7f747f8d8e9b14c623f19fa5069735d" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "thread_local" version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" dependencies = [ "once_cell", ] [[package]] name = "toml" version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" dependencies = [ "serde", "serde_spanned", "toml_datetime", "toml_edit", ] [[package]] name = "toml_datetime" version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ "serde", ] [[package]] name = "toml_edit" version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", "serde", "serde_spanned", "toml_datetime", "winnow", ] [[package]] name = "tracing" version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" dependencies = [ "pin-project-lite", "tracing-attributes", "tracing-core", ] [[package]] name = "tracing-attributes" version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "tracing-core" version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" dependencies = [ "once_cell", "valuable", ] [[package]] name = "tracing-log" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" dependencies = [ "log", "once_cell", "tracing-core", ] [[package]] name = "tracing-subscriber" version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" dependencies = [ "nu-ansi-term", "sharded-slab", "smallvec", "thread_local", "tracing-core", "tracing-log", ] [[package]] name = "unicode-ident" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" [[package]] name = "utf8parse" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "valuable" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" [[package]] name = "windows_aarch64_msvc" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" [[package]] name = "windows_i686_gnu" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" [[package]] name = "windows_i686_msvc" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" [[package]] name = "windows_x86_64_gnu" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" [[package]] name = "windows_x86_64_gnullvm" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" [[package]] name = "windows_x86_64_msvc" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] clap-verbosity-flag-3.0.4/Cargo.toml0000644000000120300000000000100127040ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.74" name = "clap-verbosity-flag" version = "3.0.4" authors = ["Pascal Hertleif "] build = false include = [ "build.rs", "src/**/*", "Cargo.toml", "Cargo.lock", "LICENSE*", "README.md", "examples/**/*", ] autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = "Easily add a `--verbose` flag to CLIs using Clap" readme = "README.md" license = "MIT OR Apache-2.0" repository = "https://github.com/clap-rs/clap-verbosity-flag" [package.metadata.docs.rs] all-features = true rustdoc-args = [ "--cfg", "docsrs", "--generate-link-to-definition", ] [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = "Unreleased" replace = "{{version}}" min = 1 [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = '\.\.\.HEAD' replace = "...{{tag_name}}" exactly = 1 [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = "ReleaseDate" replace = "{{date}}" min = 1 [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = "" replace = """ ## [Unreleased] - ReleaseDate """ exactly = 1 [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = "" replace = """ [Unreleased]: https://github.com/clap-rs/clap-verbosity-flag/compare/{{tag_name}}...HEAD""" exactly = 1 [badges.codecov] repository = "clap-rs/clap-verbosity-flag" [features] default = ["log"] log = ["dep:log"] serde = ["dep:serde"] tracing = ["dep:tracing-core"] [lib] name = "clap_verbosity_flag" path = "src/lib.rs" [[example]] name = "log" path = "examples/log.rs" required-features = ["log"] [[example]] name = "log_level" path = "examples/log_level.rs" required-features = ["log"] [[example]] name = "tracing" path = "examples/tracing.rs" required-features = ["tracing"] [dependencies.clap] version = "4.0.0" features = [ "std", "derive", ] default-features = false [dependencies.log] version = "0.4.1" optional = true [dependencies.serde] version = "1" features = ["derive"] optional = true [dependencies.tracing-core] version = "0.1" optional = true [dev-dependencies.clap] version = "4.5.4" features = [ "help", "usage", ] default-features = false [dev-dependencies.env_logger] version = "0.11.3" [dev-dependencies.serde_test] version = "1.0.177" [dev-dependencies.toml] version = "0.8.19" [dev-dependencies.tracing] version = "0.1" [dev-dependencies.tracing-subscriber] version = "0.3" [lints.clippy] bool_assert_comparison = "allow" branches_sharing_code = "allow" checked_conversions = "warn" collapsible_else_if = "allow" create_dir = "warn" dbg_macro = "warn" debug_assert_with_mut_call = "warn" doc_markdown = "warn" empty_enum = "warn" enum_glob_use = "warn" expl_impl_clone_on_copy = "warn" explicit_deref_methods = "warn" explicit_into_iter_loop = "warn" fallible_impl_from = "warn" filter_map_next = "warn" flat_map_option = "warn" float_cmp_const = "warn" fn_params_excessive_bools = "warn" from_iter_instead_of_collect = "warn" if_same_then_else = "allow" implicit_clone = "warn" imprecise_flops = "warn" inconsistent_struct_constructor = "warn" inefficient_to_string = "warn" infinite_loop = "warn" invalid_upcast_comparisons = "warn" large_digit_groups = "warn" large_stack_arrays = "warn" large_types_passed_by_value = "warn" let_and_return = "allow" linkedlist = "warn" lossy_float_literal = "warn" macro_use_imports = "warn" mem_forget = "warn" mutex_integer = "warn" needless_continue = "allow" needless_for_each = "warn" negative_feature_names = "warn" path_buf_push_overwrite = "warn" ptr_as_ptr = "warn" rc_mutex = "warn" redundant_feature_names = "warn" ref_option_ref = "warn" rest_pat_in_fully_bound_structs = "warn" result_large_err = "allow" same_functions_in_if_condition = "warn" self_named_module_files = "warn" semicolon_if_nothing_returned = "warn" str_to_string = "warn" string_add = "warn" string_add_assign = "warn" string_lit_as_bytes = "warn" string_to_string = "warn" todo = "warn" trait_duplication_in_bounds = "warn" uninlined_format_args = "warn" verbose_file_reads = "warn" wildcard_imports = "warn" zero_sized_map_values = "warn" [lints.rust] unnameable_types = "warn" unreachable_pub = "warn" unsafe_op_in_unsafe_fn = "warn" unused_lifetimes = "warn" unused_macro_rules = "warn" unused_qualifications = "warn" [lints.rust.rust_2018_idioms] level = "warn" priority = -1 [profile.dev] panic = "abort" [profile.release] lto = true codegen-units = 1 panic = "abort" clap-verbosity-flag-3.0.4/Cargo.toml.orig000064400000000000000000000104241046102023000163720ustar 00000000000000[workspace] resolver = "2" [workspace.package] repository = "https://github.com/clap-rs/clap-verbosity-flag" license = "MIT OR Apache-2.0" edition = "2021" rust-version = "1.74" # MSRV include = [ "build.rs", "src/**/*", "Cargo.toml", "Cargo.lock", "LICENSE*", "README.md", "examples/**/*" ] [workspace.lints.rust] rust_2018_idioms = { level = "warn", priority = -1 } unnameable_types = "warn" unreachable_pub = "warn" unsafe_op_in_unsafe_fn = "warn" unused_lifetimes = "warn" unused_macro_rules = "warn" unused_qualifications = "warn" [workspace.lints.clippy] bool_assert_comparison = "allow" branches_sharing_code = "allow" checked_conversions = "warn" collapsible_else_if = "allow" create_dir = "warn" dbg_macro = "warn" debug_assert_with_mut_call = "warn" doc_markdown = "warn" empty_enum = "warn" enum_glob_use = "warn" expl_impl_clone_on_copy = "warn" explicit_deref_methods = "warn" explicit_into_iter_loop = "warn" fallible_impl_from = "warn" filter_map_next = "warn" flat_map_option = "warn" float_cmp_const = "warn" fn_params_excessive_bools = "warn" from_iter_instead_of_collect = "warn" if_same_then_else = "allow" implicit_clone = "warn" imprecise_flops = "warn" inconsistent_struct_constructor = "warn" inefficient_to_string = "warn" infinite_loop = "warn" invalid_upcast_comparisons = "warn" large_digit_groups = "warn" large_stack_arrays = "warn" large_types_passed_by_value = "warn" let_and_return = "allow" # sometimes good to name what you are returning linkedlist = "warn" lossy_float_literal = "warn" macro_use_imports = "warn" mem_forget = "warn" mutex_integer = "warn" needless_continue = "allow" needless_for_each = "warn" negative_feature_names = "warn" path_buf_push_overwrite = "warn" ptr_as_ptr = "warn" rc_mutex = "warn" redundant_feature_names = "warn" ref_option_ref = "warn" rest_pat_in_fully_bound_structs = "warn" result_large_err = "allow" same_functions_in_if_condition = "warn" self_named_module_files = "warn" semicolon_if_nothing_returned = "warn" str_to_string = "warn" string_add = "warn" string_add_assign = "warn" string_lit_as_bytes = "warn" string_to_string = "warn" todo = "warn" trait_duplication_in_bounds = "warn" uninlined_format_args = "warn" verbose_file_reads = "warn" wildcard_imports = "warn" zero_sized_map_values = "warn" [profile.dev] panic = "abort" [profile.release] panic = "abort" codegen-units = 1 lto = true # debug = "line-tables-only" # requires Cargo 1.71 [package] name = "clap-verbosity-flag" version = "3.0.4" description = "Easily add a `--verbose` flag to CLIs using Clap" authors = ["Pascal Hertleif "] readme = "README.md" repository.workspace = true license.workspace = true edition.workspace = true rust-version.workspace = true include.workspace = true [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"] [package.metadata.release] pre-release-replacements = [ {file="CHANGELOG.md", search="Unreleased", replace="{{version}}", min=1}, {file="CHANGELOG.md", search="\\.\\.\\.HEAD", replace="...{{tag_name}}", exactly=1}, {file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}", min=1}, {file="CHANGELOG.md", search="", replace="\n## [Unreleased] - ReleaseDate\n", exactly=1}, {file="CHANGELOG.md", search="", replace="\n[Unreleased]: https://github.com/clap-rs/clap-verbosity-flag/compare/{{tag_name}}...HEAD", exactly=1}, ] [badges] codecov = { repository = "clap-rs/clap-verbosity-flag" } [features] default = ["log"] log = ["dep:log"] tracing = ["dep:tracing-core"] serde = ["dep:serde"] [dependencies] clap = { version = "4.0.0", default-features = false, features = ["std", "derive"] } log = { version = "0.4.1", optional = true } serde = { version = "1", features = ["derive"], optional = true } tracing-core = { version = "0.1", optional = true } [dev-dependencies] clap = { version = "4.5.4", default-features = false, features = ["help", "usage"] } env_logger = "0.11.3" serde_test = { version = "1.0.177" } toml = { version = "0.8.19" } tracing = "0.1" tracing-subscriber = "0.3" [lints] workspace = true [[example]] name = "log" required-features = ["log"] [[example]] name = "log_level" required-features = ["log"] [[example]] name = "tracing" required-features = ["tracing"] clap-verbosity-flag-3.0.4/LICENSE-APACHE000064400000000000000000000261361046102023000154360ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} 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 http://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. clap-verbosity-flag-3.0.4/LICENSE-MIT000064400000000000000000000020461046102023000151400ustar 00000000000000Copyright (c) Individual contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. clap-verbosity-flag-3.0.4/README.md000064400000000000000000000044051046102023000147640ustar 00000000000000# clap-verbosity-flag for `log` / `tracing` [![Documentation](https://img.shields.io/badge/docs-master-blue.svg)][Documentation] ![License](https://img.shields.io/crates/l/clap-verbosity-flag.svg) [![crates.io](https://img.shields.io/crates/v/clap-verbosity-flag.svg)][Crates.io] [Crates.io]: https://crates.io/crates/clap-verbosity-flag [Documentation]: https://docs.rs/clap-verbosity-flag/ Easily add `--verbose` and `--quiet` flags to CLIs using [Clap](http://crates.io/crates/clap). ## Examples ```console $ cargo add clap-verbosity-flag ``` ```rust use clap::Parser; #[derive(Debug, Parser)] struct Cli { #[command(flatten)] verbosity: clap_verbosity_flag::Verbosity, } fn main() { let args = Cli::parse(); env_logger::Builder::new() .filter_level(args.verbosity.into()) .init(); // Your code here } ``` For [`tracing`](https://crates.io/crates/tracing) support, use the `tracing` feature: ```console $ cargo add clap-verbosity-flag --no-default-features --features tracing ``` ```rust use clap::Parser; #[derive(Debug, Parser)] struct Cli { #[command(flatten)] verbosity: clap_verbosity_flag::Verbosity, } fn main() { let args = Cli::parse(); tracing_subscriber::fmt() .with_max_level(args.verbosity) .init(); // Your code here } ``` The default verbosity level will cause `log` / `tracing` to only report errors. The flags can be specified multiple times to increase or decrease the verbosity level. See the [Documentation] for info on how to change the default verbosity level. - silence output: `-q` / `--quiet` - show warnings: `-v` / `--verbose` - show info: `-vv` / `--verbose --verbose` - show debug: `-vvv` / `--verbose --verbose --verbose` - show trace: `-vvvv` / `--verbose --verbose --verbose --verbose` ## License Licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or ) * MIT license ([LICENSE-MIT](LICENSE-MIT) or ) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions. clap-verbosity-flag-3.0.4/examples/log.rs000064400000000000000000000007661046102023000164600ustar 00000000000000use clap::Parser; use clap_verbosity_flag::Verbosity; /// Foo #[derive(Debug, Parser)] struct Cli { #[command(flatten)] verbosity: Verbosity, } fn main() { let cli = Cli::parse(); env_logger::Builder::new() .filter_level(cli.verbosity.into()) .init(); log::error!("Engines exploded"); log::warn!("Engines smoking"); log::info!("Engines exist"); log::debug!("Engine temperature is 200 degrees"); log::trace!("Engine subsection is 300 degrees"); } clap-verbosity-flag-3.0.4/examples/log_level.rs000064400000000000000000000035251046102023000176430ustar 00000000000000//! Demonstrates how to set the default log level for the logger to something other than the default //! (`ErrorLevel`). This is done with multiple subcommands, each with their own verbosity level. use clap::{Parser, Subcommand}; use clap_verbosity_flag::{ DebugLevel, ErrorLevel, InfoLevel, OffLevel, TraceLevel, Verbosity, WarnLevel, }; #[derive(Debug, Parser)] struct Cli { #[command(subcommand)] command: Command, } #[derive(Debug, Subcommand)] enum Command { Off { #[command(flatten)] verbose: Verbosity, }, Error { #[command(flatten)] verbose: Verbosity, }, Warn { #[command(flatten)] verbose: Verbosity, }, Info { #[command(flatten)] verbose: Verbosity, }, Debug { #[command(flatten)] verbose: Verbosity, }, Trace { #[command(flatten)] verbose: Verbosity, }, } impl Command { fn log_level_filter(&self) -> log::LevelFilter { match self { Command::Off { verbose } => verbose.log_level_filter(), Command::Error { verbose } => verbose.log_level_filter(), Command::Warn { verbose } => verbose.log_level_filter(), Command::Info { verbose } => verbose.log_level_filter(), Command::Debug { verbose } => verbose.log_level_filter(), Command::Trace { verbose } => verbose.log_level_filter(), } } } fn main() { let cli = Cli::parse(); env_logger::Builder::new() .filter_level(cli.command.log_level_filter()) .init(); log::error!("Engines exploded"); log::warn!("Engines smoking"); log::info!("Engines exist"); log::debug!("Engine temperature is 200 degrees"); log::trace!("Engine subsection is 300 degrees"); } clap-verbosity-flag-3.0.4/examples/tracing.rs000064400000000000000000000010041046102023000173100ustar 00000000000000use clap::Parser; use clap_verbosity_flag::Verbosity; /// Foo #[derive(Debug, Parser)] struct Cli { #[command(flatten)] verbosity: Verbosity, } fn main() { let cli = Cli::parse(); tracing_subscriber::fmt() .with_max_level(cli.verbosity) .init(); tracing::error!("Engines exploded"); tracing::warn!("Engines smoking"); tracing::info!("Engines exist"); tracing::debug!("Engine temperature is 200 degrees"); tracing::trace!("Engine subsection is 300 degrees"); } clap-verbosity-flag-3.0.4/src/lib.rs000064400000000000000000000432701046102023000154130ustar 00000000000000//! Easily add `--verbose` and `--quiet` flags to CLIs using [Clap](http://crates.io/crates/clap). //! //! # Examples //! //! To get `--quiet` and `--verbose` flags through your entire program, just `flatten` //! [`Verbosity`]: //! //! ```rust,no_run //! use clap::Parser; //! use clap_verbosity_flag::Verbosity; //! //! #[derive(Debug, Parser)] //! struct Cli { //! #[command(flatten)] //! verbosity: Verbosity, //! //! // ... other options //! } //! ``` //! //! You can then use this to configure your logger: //! //! ```rust,no_run //! # use clap::Parser; //! # use clap_verbosity_flag::Verbosity; //! # //! # #[derive(Debug, Parser)] //! # struct Cli { //! # #[command(flatten)] //! # verbosity: Verbosity, //! # } //! let cli = Cli::parse(); //! # #[cfg(feature = "log")] //! env_logger::Builder::new() //! .filter_level(cli.verbosity.log_level_filter()) //! .init(); //! ``` //! //! ## Use with `tracing` //! //! To use with [`tracing`](https://crates.io/crates/tracing), disable the log feature flag and //! enable the `tracing` feature flag: //! //! ```shell //! cargo add clap_verbosity_flag --no-default features --features tracing //! ``` //! //! Then you can use it like this: //! //! ```rust,no_run //! # use clap::Parser; //! # use clap_verbosity_flag::Verbosity; //! # //! # #[derive(Debug, Parser)] //! # struct Cli { //! # #[command(flatten)] //! # verbosity: Verbosity, //! # } //! let cli = Cli::parse(); //! # #[cfg(feature = "tracing")] //! tracing_subscriber::fmt() //! .with_max_level(cli.verbosity) //! .init(); //! ``` //! //! # Using `--verbose` and `--quiet` flags //! //! The default verbosity level will cause `log` / `tracing` to only report errors. The flags can be //! specified multiple times to increase or decrease the verbosity level. //! //! - silence output: `-q` / `--quiet` //! - show warnings: `-v` / `--verbose` //! - show info: `-vv` / `--verbose --verbose` //! - show debug: `-vvv` / `--verbose --verbose --verbose` //! - show trace: `-vvvv` / `--verbose --verbose --verbose --verbose` //! //! # Customizing the default log level //! //! By default, the log level is set to Error. To customize this to a different level, pass a type //! implementing the [`LogLevel`] trait to [`Verbosity`]: //! //! ```rust,no_run //! # use clap::Parser; //! use clap_verbosity_flag::{Verbosity, InfoLevel}; //! //! #[derive(Debug, Parser)] //! struct Cli { //! #[command(flatten)] //! verbose: Verbosity, //! } //! ``` //! //! Or implement our [`LogLevel`] trait to customize the default log level and help output. #![cfg_attr(docsrs, feature(doc_auto_cfg))] #![warn(clippy::print_stderr)] #![warn(clippy::print_stdout)] #[doc = include_str!("../README.md")] #[cfg(all(doctest, feature = "log", feature = "tracing"))] pub struct ReadmeDoctests; use std::fmt; #[cfg(feature = "log")] pub mod log; #[cfg(feature = "tracing")] pub mod tracing; /// Logging flags to `#[command(flatten)]` into your CLI #[derive(clap::Args, Debug, Clone, Copy, Default, PartialEq, Eq)] #[command(about = None, long_about = None)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr( feature = "serde", serde( from = "VerbosityFilter", into = "VerbosityFilter", bound(serialize = "L: Clone") ) )] #[cfg_attr( feature = "serde", doc = r#"This type serializes to a string representation of the log level, e.g. `"Debug"`"# )] pub struct Verbosity { #[arg( long, short = 'v', action = clap::ArgAction::Count, global = true, help = L::verbose_help(), long_help = L::verbose_long_help(), )] verbose: u8, #[arg( long, short = 'q', action = clap::ArgAction::Count, global = true, help = L::quiet_help(), long_help = L::quiet_long_help(), conflicts_with = "verbose", )] quiet: u8, #[arg(skip)] phantom: std::marker::PhantomData, } impl Verbosity { /// Create a new verbosity instance by explicitly setting the values pub fn new(verbose: u8, quiet: u8) -> Self { Verbosity { verbose, quiet, phantom: std::marker::PhantomData, } } /// Whether any verbosity flags (either `--verbose` or `--quiet`) /// are present on the command line. pub fn is_present(&self) -> bool { self.verbose != 0 || self.quiet != 0 } /// If the user requested complete silence (i.e. not just no-logging). pub fn is_silent(&self) -> bool { self.filter() == VerbosityFilter::Off } /// Gets the filter that should be applied to the logger. pub fn filter(&self) -> VerbosityFilter { let offset = self.verbose as i16 - self.quiet as i16; L::default_filter().with_offset(offset) } } #[cfg(feature = "log")] impl Verbosity { /// Get the log level. /// /// `None` means all output is disabled. pub fn log_level(&self) -> Option { self.filter().into() } /// Get the log level filter. pub fn log_level_filter(&self) -> log::LevelFilter { self.filter().into() } } #[cfg(feature = "tracing")] impl Verbosity { /// Get the tracing level. /// /// `None` means all output is disabled. pub fn tracing_level(&self) -> Option { self.filter().into() } /// Get the tracing level filter. pub fn tracing_level_filter(&self) -> tracing_core::LevelFilter { self.filter().into() } } impl fmt::Display for Verbosity { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.filter().fmt(f) } } impl From> for VerbosityFilter { fn from(verbosity: Verbosity) -> Self { verbosity.filter() } } impl From for Verbosity { fn from(filter: VerbosityFilter) -> Self { let default = L::default_filter(); let verbose = filter.value().saturating_sub(default.value()); let quiet = default.value().saturating_sub(filter.value()); Verbosity::new(verbose, quiet) } } /// Customize the default log-level and associated help pub trait LogLevel { /// Baseline level before applying `--verbose` and `--quiet` fn default_filter() -> VerbosityFilter; /// Short-help message for `--verbose` fn verbose_help() -> Option<&'static str> { Some("Increase logging verbosity") } /// Long-help message for `--verbose` fn verbose_long_help() -> Option<&'static str> { None } /// Short-help message for `--quiet` fn quiet_help() -> Option<&'static str> { Some("Decrease logging verbosity") } /// Long-help message for `--quiet` fn quiet_long_help() -> Option<&'static str> { None } } /// A representation of the log level filter. /// /// Used to calculate the log level and filter. #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))] pub enum VerbosityFilter { Off, Error, Warn, Info, Debug, Trace, } impl VerbosityFilter { /// Apply an offset to the filter level. /// /// Negative values will decrease the verbosity, while positive values will increase it. fn with_offset(&self, offset: i16) -> VerbosityFilter { match i16::from(self.value()).saturating_add(offset) { i16::MIN..=0 => Self::Off, 1 => Self::Error, 2 => Self::Warn, 3 => Self::Info, 4 => Self::Debug, 5..=i16::MAX => Self::Trace, } } /// Get the numeric value of the filter. /// /// This is an internal representation of the filter level used only for conversion / offset. fn value(&self) -> u8 { match self { Self::Off => 0, Self::Error => 1, Self::Warn => 2, Self::Info => 3, Self::Debug => 4, Self::Trace => 5, } } } impl fmt::Display for VerbosityFilter { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Off => write!(f, "off"), Self::Error => write!(f, "error"), Self::Warn => write!(f, "warn"), Self::Info => write!(f, "info"), Self::Debug => write!(f, "debug"), Self::Trace => write!(f, "trace"), } } } /// Default to [`VerbosityFilter::Error`] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] pub struct ErrorLevel; impl LogLevel for ErrorLevel { fn default_filter() -> VerbosityFilter { VerbosityFilter::Error } } /// Default to [`VerbosityFilter::Warn`] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] pub struct WarnLevel; impl LogLevel for WarnLevel { fn default_filter() -> VerbosityFilter { VerbosityFilter::Warn } } /// Default to [`VerbosityFilter::Info`] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] pub struct InfoLevel; impl LogLevel for InfoLevel { fn default_filter() -> VerbosityFilter { VerbosityFilter::Info } } /// Default to [`VerbosityFilter::Debug`] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] pub struct DebugLevel; impl LogLevel for DebugLevel { fn default_filter() -> VerbosityFilter { VerbosityFilter::Debug } } /// Default to [`VerbosityFilter::Trace`] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] pub struct TraceLevel; impl LogLevel for TraceLevel { fn default_filter() -> VerbosityFilter { VerbosityFilter::Trace } } /// Default to [`VerbosityFilter::Off`] (no logging) #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] pub struct OffLevel; impl LogLevel for OffLevel { fn default_filter() -> VerbosityFilter { VerbosityFilter::Off } } #[cfg(test)] mod test { use super::*; #[test] fn verify_app() { #[derive(Debug, clap::Parser)] struct Cli { #[command(flatten)] verbose: Verbosity, } use clap::CommandFactory; Cli::command().debug_assert(); } /// Asserts that the filter is correct for the given verbosity and quiet values. #[track_caller] fn assert_filter(verbose: u8, quiet: u8, expected: VerbosityFilter) { assert_eq!( Verbosity::::new(verbose, quiet).filter(), expected, "verbose = {verbose}, quiet = {quiet}" ); } #[test] fn verbosity_off_level() { let tests = [ (0, 0, VerbosityFilter::Off), (1, 0, VerbosityFilter::Error), (2, 0, VerbosityFilter::Warn), (3, 0, VerbosityFilter::Info), (4, 0, VerbosityFilter::Debug), (5, 0, VerbosityFilter::Trace), (6, 0, VerbosityFilter::Trace), (255, 0, VerbosityFilter::Trace), (0, 1, VerbosityFilter::Off), (0, 255, VerbosityFilter::Off), (255, 255, VerbosityFilter::Off), ]; for (verbose, quiet, expected_filter) in tests { assert_filter::(verbose, quiet, expected_filter); } } #[test] fn verbosity_error_level() { let tests = [ (0, 0, VerbosityFilter::Error), (1, 0, VerbosityFilter::Warn), (2, 0, VerbosityFilter::Info), (3, 0, VerbosityFilter::Debug), (4, 0, VerbosityFilter::Trace), (5, 0, VerbosityFilter::Trace), (255, 0, VerbosityFilter::Trace), (0, 1, VerbosityFilter::Off), (0, 2, VerbosityFilter::Off), (0, 255, VerbosityFilter::Off), (255, 255, VerbosityFilter::Error), ]; for (verbose, quiet, expected_filter) in tests { assert_filter::(verbose, quiet, expected_filter); } } #[test] fn verbosity_warn_level() { let tests = [ // verbose, quiet, expected_level, expected_filter (0, 0, VerbosityFilter::Warn), (1, 0, VerbosityFilter::Info), (2, 0, VerbosityFilter::Debug), (3, 0, VerbosityFilter::Trace), (4, 0, VerbosityFilter::Trace), (255, 0, VerbosityFilter::Trace), (0, 1, VerbosityFilter::Error), (0, 2, VerbosityFilter::Off), (0, 3, VerbosityFilter::Off), (0, 255, VerbosityFilter::Off), (255, 255, VerbosityFilter::Warn), ]; for (verbose, quiet, expected_filter) in tests { assert_filter::(verbose, quiet, expected_filter); } } #[test] fn verbosity_info_level() { let tests = [ // verbose, quiet, expected_level, expected_filter (0, 0, VerbosityFilter::Info), (1, 0, VerbosityFilter::Debug), (2, 0, VerbosityFilter::Trace), (3, 0, VerbosityFilter::Trace), (255, 0, VerbosityFilter::Trace), (0, 1, VerbosityFilter::Warn), (0, 2, VerbosityFilter::Error), (0, 3, VerbosityFilter::Off), (0, 4, VerbosityFilter::Off), (0, 255, VerbosityFilter::Off), (255, 255, VerbosityFilter::Info), ]; for (verbose, quiet, expected_filter) in tests { assert_filter::(verbose, quiet, expected_filter); } } #[test] fn verbosity_debug_level() { let tests = [ // verbose, quiet, expected_level, expected_filter (0, 0, VerbosityFilter::Debug), (1, 0, VerbosityFilter::Trace), (2, 0, VerbosityFilter::Trace), (255, 0, VerbosityFilter::Trace), (0, 1, VerbosityFilter::Info), (0, 2, VerbosityFilter::Warn), (0, 3, VerbosityFilter::Error), (0, 4, VerbosityFilter::Off), (0, 5, VerbosityFilter::Off), (0, 255, VerbosityFilter::Off), (255, 255, VerbosityFilter::Debug), ]; for (verbose, quiet, expected_filter) in tests { assert_filter::(verbose, quiet, expected_filter); } } #[test] fn verbosity_trace_level() { let tests = [ // verbose, quiet, expected_level, expected_filter (0, 0, VerbosityFilter::Trace), (1, 0, VerbosityFilter::Trace), (255, 0, VerbosityFilter::Trace), (0, 1, VerbosityFilter::Debug), (0, 2, VerbosityFilter::Info), (0, 3, VerbosityFilter::Warn), (0, 4, VerbosityFilter::Error), (0, 5, VerbosityFilter::Off), (0, 6, VerbosityFilter::Off), (0, 255, VerbosityFilter::Off), (255, 255, VerbosityFilter::Trace), ]; for (verbose, quiet, expected_filter) in tests { assert_filter::(verbose, quiet, expected_filter); } } #[test] fn from_verbosity_filter() { for &filter in &[ VerbosityFilter::Off, VerbosityFilter::Error, VerbosityFilter::Warn, VerbosityFilter::Info, VerbosityFilter::Debug, VerbosityFilter::Trace, ] { assert_eq!(Verbosity::::from(filter).filter(), filter); assert_eq!(Verbosity::::from(filter).filter(), filter); assert_eq!(Verbosity::::from(filter).filter(), filter); assert_eq!(Verbosity::::from(filter).filter(), filter); assert_eq!(Verbosity::::from(filter).filter(), filter); assert_eq!(Verbosity::::from(filter).filter(), filter); } } } #[cfg(feature = "serde")] #[cfg(test)] mod serde_tests { use super::*; use clap::Parser; use serde::{Deserialize, Serialize}; #[derive(Debug, Parser, Serialize, Deserialize)] struct Cli { meaning_of_life: u8, #[command(flatten)] verbosity: Verbosity, } #[test] fn serialize_toml() { let cli = Cli { meaning_of_life: 42, verbosity: Verbosity::new(2, 1), }; let toml = toml::to_string(&cli).unwrap(); assert_eq!(toml, "meaning_of_life = 42\nverbosity = \"debug\"\n"); } #[test] fn deserialize_toml() { let toml = "meaning_of_life = 42\nverbosity = \"debug\"\n"; let cli: Cli = toml::from_str(toml).unwrap(); assert_eq!(cli.meaning_of_life, 42); assert_eq!(cli.verbosity.filter(), VerbosityFilter::Debug); } /// Tests that the `Verbosity` can be serialized and deserialized correctly from an a token. #[test] fn serde_round_trips() { use serde_test::{assert_tokens, Token}; for (filter, variant) in [ (VerbosityFilter::Off, "off"), (VerbosityFilter::Error, "error"), (VerbosityFilter::Warn, "warn"), (VerbosityFilter::Info, "info"), (VerbosityFilter::Debug, "debug"), (VerbosityFilter::Trace, "trace"), ] { let tokens = &[Token::UnitVariant { name: "VerbosityFilter", variant, }]; // `assert_tokens` checks both serialization and deserialization. assert_tokens(&Verbosity::::from(filter), tokens); assert_tokens(&Verbosity::::from(filter), tokens); assert_tokens(&Verbosity::::from(filter), tokens); assert_tokens(&Verbosity::::from(filter), tokens); assert_tokens(&Verbosity::::from(filter), tokens); assert_tokens(&Verbosity::::from(filter), tokens); } } } clap-verbosity-flag-3.0.4/src/log.rs000064400000000000000000000115071046102023000154240ustar 00000000000000// These re-exports of the log crate make it easy to use this crate without having to depend on the // log crate directly. See for more // information. pub use log::{Level, LevelFilter}; use crate::{LogLevel, Verbosity, VerbosityFilter}; impl From for LevelFilter { fn from(filter: VerbosityFilter) -> Self { match filter { VerbosityFilter::Off => LevelFilter::Off, VerbosityFilter::Error => LevelFilter::Error, VerbosityFilter::Warn => LevelFilter::Warn, VerbosityFilter::Info => LevelFilter::Info, VerbosityFilter::Debug => LevelFilter::Debug, VerbosityFilter::Trace => LevelFilter::Trace, } } } impl From for VerbosityFilter { fn from(level: LevelFilter) -> Self { match level { LevelFilter::Off => Self::Off, LevelFilter::Error => Self::Error, LevelFilter::Warn => Self::Warn, LevelFilter::Info => Self::Info, LevelFilter::Debug => Self::Debug, LevelFilter::Trace => Self::Trace, } } } impl From for Option { fn from(filter: VerbosityFilter) -> Self { match filter { VerbosityFilter::Off => None, VerbosityFilter::Error => Some(Level::Error), VerbosityFilter::Warn => Some(Level::Warn), VerbosityFilter::Info => Some(Level::Info), VerbosityFilter::Debug => Some(Level::Debug), VerbosityFilter::Trace => Some(Level::Trace), } } } impl From> for VerbosityFilter { fn from(level: Option) -> Self { match level { None => Self::Off, Some(Level::Error) => Self::Error, Some(Level::Warn) => Self::Warn, Some(Level::Info) => Self::Info, Some(Level::Debug) => Self::Debug, Some(Level::Trace) => Self::Trace, } } } impl From> for LevelFilter { fn from(v: Verbosity) -> Self { v.log_level_filter() } } impl From> for Option { fn from(v: Verbosity) -> Self { v.log_level() } } #[cfg(test)] mod tests { use super::*; use crate::{DebugLevel, ErrorLevel, InfoLevel, OffLevel, TraceLevel, Verbosity, WarnLevel}; #[test] fn log_level() { let v = Verbosity::::default(); assert_eq!(v.log_level(), None); assert_eq!(v.log_level_filter(), LevelFilter::Off); let v = Verbosity::::default(); assert_eq!(v.log_level(), Some(Level::Error)); assert_eq!(v.log_level_filter(), LevelFilter::Error); let v = Verbosity::::default(); assert_eq!(v.log_level(), Some(Level::Warn)); assert_eq!(v.log_level_filter(), LevelFilter::Warn); let v = Verbosity::::default(); assert_eq!(v.log_level(), Some(Level::Info)); assert_eq!(v.log_level_filter(), LevelFilter::Info); let v = Verbosity::::default(); assert_eq!(v.log_level(), Some(Level::Debug)); assert_eq!(v.log_level_filter(), LevelFilter::Debug); let v = Verbosity::::default(); assert_eq!(v.log_level(), Some(Level::Trace)); assert_eq!(v.log_level_filter(), LevelFilter::Trace); } #[test] fn into_opt_level() { let v = Verbosity::::default(); assert_eq!(Option::::from(v), None); let v = Verbosity::::default(); assert_eq!(Option::::from(v), Some(Level::Error)); let v = Verbosity::::default(); assert_eq!(Option::::from(v), Some(Level::Warn)); let v = Verbosity::::default(); assert_eq!(Option::::from(v), Some(Level::Info)); let v = Verbosity::::default(); assert_eq!(Option::::from(v), Some(Level::Debug)); let v = Verbosity::::default(); assert_eq!(Option::::from(v), Some(Level::Trace)); } #[test] fn into_level_filter() { let v = Verbosity::::default(); assert_eq!(LevelFilter::from(v), LevelFilter::Off); let v = Verbosity::::default(); assert_eq!(LevelFilter::from(v), LevelFilter::Error); let v = Verbosity::::default(); assert_eq!(LevelFilter::from(v), LevelFilter::Warn); let v = Verbosity::::default(); assert_eq!(LevelFilter::from(v), LevelFilter::Info); let v = Verbosity::::default(); assert_eq!(LevelFilter::from(v), LevelFilter::Debug); let v = Verbosity::::default(); assert_eq!(LevelFilter::from(v), LevelFilter::Trace); } } clap-verbosity-flag-3.0.4/src/tracing.rs000064400000000000000000000116251046102023000162730ustar 00000000000000// These re-exports of the tracing crate types it easy to use this crate without having to depend on // the tracing crate directly. See for // more information. pub use tracing_core::{Level, LevelFilter}; use crate::{LogLevel, Verbosity, VerbosityFilter}; impl From for LevelFilter { fn from(filter: VerbosityFilter) -> Self { match filter { VerbosityFilter::Off => LevelFilter::OFF, VerbosityFilter::Error => LevelFilter::ERROR, VerbosityFilter::Warn => LevelFilter::WARN, VerbosityFilter::Info => LevelFilter::INFO, VerbosityFilter::Debug => LevelFilter::DEBUG, VerbosityFilter::Trace => LevelFilter::TRACE, } } } impl From for VerbosityFilter { fn from(level: LevelFilter) -> Self { match level { LevelFilter::OFF => Self::Off, LevelFilter::ERROR => Self::Error, LevelFilter::WARN => Self::Warn, LevelFilter::INFO => Self::Info, LevelFilter::DEBUG => Self::Debug, LevelFilter::TRACE => Self::Trace, } } } impl From for Option { fn from(filter: VerbosityFilter) -> Self { match filter { VerbosityFilter::Off => None, VerbosityFilter::Error => Some(Level::ERROR), VerbosityFilter::Warn => Some(Level::WARN), VerbosityFilter::Info => Some(Level::INFO), VerbosityFilter::Debug => Some(Level::DEBUG), VerbosityFilter::Trace => Some(Level::TRACE), } } } impl From> for VerbosityFilter { fn from(level: Option) -> Self { match level { None => Self::Off, Some(Level::ERROR) => Self::Error, Some(Level::WARN) => Self::Warn, Some(Level::INFO) => Self::Info, Some(Level::DEBUG) => Self::Debug, Some(Level::TRACE) => Self::Trace, } } } impl From> for LevelFilter { fn from(v: Verbosity) -> Self { v.tracing_level_filter() } } impl From> for Option { fn from(v: Verbosity) -> Self { v.tracing_level() } } #[cfg(test)] mod tests { use super::*; use crate::{DebugLevel, ErrorLevel, InfoLevel, OffLevel, TraceLevel, Verbosity, WarnLevel}; #[test] fn tracing_level() { let v = Verbosity::::default(); assert_eq!(v.tracing_level(), None); assert_eq!(v.tracing_level_filter(), LevelFilter::OFF); let v = Verbosity::::default(); assert_eq!(v.tracing_level(), Some(Level::ERROR)); assert_eq!(v.tracing_level_filter(), LevelFilter::ERROR); let v = Verbosity::::default(); assert_eq!(v.tracing_level(), Some(Level::WARN)); assert_eq!(v.tracing_level_filter(), LevelFilter::WARN); let v = Verbosity::::default(); assert_eq!(v.tracing_level(), Some(Level::INFO)); assert_eq!(v.tracing_level_filter(), LevelFilter::INFO); let v = Verbosity::::default(); assert_eq!(v.tracing_level(), Some(Level::DEBUG)); assert_eq!(v.tracing_level_filter(), LevelFilter::DEBUG); let v = Verbosity::::default(); assert_eq!(v.tracing_level(), Some(Level::TRACE)); assert_eq!(v.tracing_level_filter(), LevelFilter::TRACE); } #[test] fn into_opt_level() { let v = Verbosity::::default(); assert_eq!(Option::::from(v), None); let v = Verbosity::::default(); assert_eq!(Option::::from(v), Some(Level::ERROR)); let v = Verbosity::::default(); assert_eq!(Option::::from(v), Some(Level::WARN)); let v = Verbosity::::default(); assert_eq!(Option::::from(v), Some(Level::INFO)); let v = Verbosity::::default(); assert_eq!(Option::::from(v), Some(Level::DEBUG)); let v = Verbosity::::default(); assert_eq!(Option::::from(v), Some(Level::TRACE)); } #[test] fn into_level_filter() { let v = Verbosity::::default(); assert_eq!(LevelFilter::from(v), LevelFilter::OFF); let v = Verbosity::::default(); assert_eq!(LevelFilter::from(v), LevelFilter::ERROR); let v = Verbosity::::default(); assert_eq!(LevelFilter::from(v), LevelFilter::WARN); let v = Verbosity::::default(); assert_eq!(LevelFilter::from(v), LevelFilter::INFO); let v = Verbosity::::default(); assert_eq!(LevelFilter::from(v), LevelFilter::DEBUG); let v = Verbosity::::default(); assert_eq!(LevelFilter::from(v), LevelFilter::TRACE); } }