Skip to content

Commit

Permalink
feat!: remove default output limit
Browse files Browse the repository at this point in the history
  • Loading branch information
loyd committed May 30, 2024
1 parent c55646a commit 4766035
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ OPTIONS:
-e, --exclude <exclude>... Excludes types that match these patterns
-p, --expand <expand>... Shows only types that match these patterns and their children, heuristically
-f, --filter <filter>... Shows only types that match these patterns
-h, --hide-less <hide-less> Hides types and fields with size less than this value [default: 0]
-l, --limit <limit> Shows only this number of top types [default: 100]
-h, --hide-less <hide-less> Hides types and fields with size less than this value
-l, --limit <limit> Shows only this number of top types
```

## Examples
Expand Down
16 changes: 8 additions & 8 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>,
/// 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<usize>,
/// 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<Regex>,
/// Excludes types that match these patterns.
#[structopt(short, long)]
#[structopt(short = "e", long)]
pub exclude: Vec<Regex>,
/// Shows only types that match these patterns and their children,
/// heuristically.
Expand Down
12 changes: 7 additions & 5 deletions src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{options::Options, schema::*};
fn filter_types(types: &mut Vec<Type>, 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()
{
Expand All @@ -24,7 +24,7 @@ fn filter_types(types: &mut Vec<Type>, 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;
}

Expand Down Expand Up @@ -190,11 +190,13 @@ pub fn transform(mut types: Vec<Type>, options: &Options) -> Vec<Type> {

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 {
Expand Down

0 comments on commit 4766035

Please sign in to comment.