From 47660359fd771b6e3c40b183e3f2b8bd5b9133eb Mon Sep 17 00:00:00 2001 From: Paul Loyd Date: Thu, 30 May 2024 14:42:55 +0400 Subject: [PATCH] feat!: remove default output limit --- CHANGELOG.md | 1 + README.md | 4 ++-- src/options.rs | 16 ++++++++-------- src/transformer.rs | 12 +++++++----- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b6e7a5..b54cc68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - The `-h` parameter now filters also types, not only fields. +- Remove a default value for `-l`, now output is unlimited by default. ### Fixed - Support nightly after 2024-03-22 ([#4]). diff --git a/README.md b/README.md index 52182ab..9ba7e17 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,8 @@ OPTIONS: -e, --exclude ... Excludes types that match these patterns -p, --expand ... Shows only types that match these patterns and their children, heuristically -f, --filter ... Shows only types that match these patterns - -h, --hide-less Hides types and fields with size less than this value [default: 0] - -l, --limit Shows only this number of top types [default: 100] + -h, --hide-less Hides types and fields with size less than this value + -l, --limit Shows only this number of top types ``` ## Examples diff --git a/src/options.rs b/src/options.rs index 7c88827..24f07b7 100644 --- a/src/options.rs +++ b/src/options.rs @@ -4,25 +4,25 @@ use structopt::StructOpt; #[derive(Debug, Clone, StructOpt)] pub struct Options { /// Shows only this number of top types. - #[structopt(short, long, default_value = "100")] - pub limit: usize, + #[structopt(short = "l", long)] + pub limit: Option, /// Prints top `limit` types in ascending order. - #[structopt(short, long)] + #[structopt(short = "r", long)] pub reverse: bool, /// Removes wrappers like `MaybeUninit`. #[structopt(short = "w", long)] pub remove_wrappers: bool, /// Hides types and fields with size less than this value. - #[structopt(short, long, default_value = "0")] - pub hide_less: usize, + #[structopt(short = "h", long)] + pub hide_less: Option, /// Sorts fields by size and removes paddings. - #[structopt(short, long)] + #[structopt(short = "s", long)] pub sort_fields: bool, /// Shows only types that match these patterns. - #[structopt(short, long)] + #[structopt(short = "f", long)] pub filter: Vec, /// Excludes types that match these patterns. - #[structopt(short, long)] + #[structopt(short = "e", long)] pub exclude: Vec, /// Shows only types that match these patterns and their children, /// heuristically. diff --git a/src/transformer.rs b/src/transformer.rs index 4d303f8..32da08c 100644 --- a/src/transformer.rs +++ b/src/transformer.rs @@ -15,7 +15,7 @@ use crate::{options::Options, schema::*}; fn filter_types(types: &mut Vec, options: &Options) { // Skip filtering if no options are provided. if !options.remove_wrappers - && options.hide_less == 0 + && options.hide_less.is_none() && options.filter.is_empty() && options.exclude.is_empty() { @@ -24,7 +24,7 @@ fn filter_types(types: &mut Vec, options: &Options) { types.retain(|type_| { // Remove by size. - if type_.size < options.hide_less { + if type_.size < options.hide_less.unwrap_or(0) { return false; } @@ -190,11 +190,13 @@ pub fn transform(mut types: Vec, options: &Options) -> Vec { expand(&mut types, &options.expand); - types.truncate(options.limit); + if let Some(limit) = options.limit { + types.truncate(limit); + } for type_ in &mut types { - if options.hide_less > 0 { - remove_small_fields(type_, options.hide_less); + if let Some(threshold) = options.hide_less { + remove_small_fields(type_, threshold); } if options.sort_fields {