Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@ All notable changes to this project will be documented in this file.

## Unreleased changes

### Breaking Changes

* Moved config, data, and cache paths to follow XDG base directory specification
* Config file default is now `$XDG_CONFIG_HOME/monocle/monocle.toml` (fallback: `~/.config/monocle/monocle.toml`)
* Data directory default is now `$XDG_DATA_HOME/monocle` (fallback: `~/.local/share/monocle`)
* Cache directory default is now `$XDG_CACHE_HOME/monocle` (fallback: `~/.cache/monocle`)
* Existing SQLite data under `~/.monocle` is no longer used by default and will be rebuilt in the new data location
* Legacy config migration: when the new config directory is empty, monocle copies `~/.monocle/monocle.toml` to the new config path
* Old database file will not be copied over. Once the updated monocle has been executed at least once, old `~/.monocle` can be safely deleted
* Added `--use-cache` flag to `monocle search` to use the default XDG cache path (`$XDG_CACHE_HOME/monocle`)
* Value set by `--cache-dir` overrides `--use-cache` when both are provided

### Dependencies

* Switched directory resolution library from `dirs` to `etcetera`

### New Features

* Added BGP community filtering support to `monocle parse` and `monocle search`
Expand All @@ -35,9 +19,34 @@ All notable changes to this project will be documented in this file.
* `--ts-start` is now accepted as an alias for `--start-ts`
* `--ts-end` is now accepted as an alias for `--end-ts`

### Bug Fixes

* Fixed panic when truncating names containing non-ASCII UTF-8 characters
* Used character-based truncation instead of byte-based slicing
* Affects RPKI ASPA display and inspect lens name truncation

### Directory Changes

* Changed config, data, and cache paths to follow XDG base directory specification
* Config file default is now `$XDG_CONFIG_HOME/monocle/monocle.toml` (fallback: `~/.config/monocle/monocle.toml`)
* Data directory default is now `$XDG_DATA_HOME/monocle` (fallback: `~/.local/share/monocle`)
* Cache directory default is now `$XDG_CACHE_HOME/monocle` (fallback: `~/.cache/monocle`)
* Existing SQLite data under `~/.monocle` is no longer used by default and will be rebuilt in the new data location
* Legacy config migration: when the new config directory is empty, monocle copies `~/.monocle/monocle.toml` to the new config path
* Old database file will not be copied over. Once the updated monocle has been executed at least once, old `~/.monocle` can be safely deleted
* Added `--use-cache` flag to `monocle search` to use the default XDG cache path (`$XDG_CACHE_HOME/monocle`)
* Value set by `--cache-dir` overrides `--use-cache` when both are provided

### Code Improvements

* Updated README command help examples to match current CLI help output from the release binary
* Moved `utils` module from `lens::utils` to crate-level `utils`
* Eliminates misleading module structure since utilities are used throughout the codebase
* Updated all imports from `crate::lens::utils` and `monocle::lens::utils` to `crate::utils` and `monocle::utils`

### Dependencies

* Switched directory resolution library from `dirs` to `etcetera`

## v1.1.0 - 2025-02-10

Expand Down
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ dateparser = { version = "0.2", optional = true }
humantime = { version = "2.1", optional = true }
bgpkit-broker = { version = "0.10.1", optional = true }
bgpkit-parser = { version = "0.15.0", features = ["serde"], optional = true }
bgpkit-commons = { version = "0.10.1", features = ["asinfo", "rpki", "countries"], optional = true }
bgpkit-commons = { version = "0.10.2", features = ["asinfo", "rpki", "countries"], optional = true }
itertools = { version = "0.14", optional = true }
radar-rs = { version = "0.1.0", optional = true }
rayon = { version = "1.8", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion src/bin/commands/as2rel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::Args;
use monocle::database::MonocleDatabase;
use monocle::lens::as2rel::{As2relLens, As2relSearchArgs};
use monocle::lens::utils::{truncate_name, OutputFormat, DEFAULT_NAME_MAX_LEN};
use monocle::utils::{truncate_name, OutputFormat, DEFAULT_NAME_MAX_LEN};
use monocle::MonocleConfig;
use serde::Serialize;
use serde_json::json;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use monocle::config::{
};
use monocle::database::{MonocleDatabase, Pfx2asDbRecord};
use monocle::lens::rpki::RpkiLens;
use monocle::lens::utils::OutputFormat;
use monocle::server::ServerConfig;
use monocle::utils::OutputFormat;
use monocle::MonocleConfig;
use serde::Serialize;
use std::path::Path;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/commands/country.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Args;
use monocle::lens::country::{CountryEntry, CountryLens, CountryLookupArgs};
use monocle::lens::utils::OutputFormat;
use monocle::utils::OutputFormat;
use tabled::settings::Style;
use tabled::Table;

Expand Down
2 changes: 1 addition & 1 deletion src/bin/commands/elem_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! multiple output format support.

use bgpkit_parser::BgpElem;
use monocle::lens::utils::{OrderByField, OrderDirection, OutputFormat, TimestampFormat};
use monocle::utils::{OrderByField, OrderDirection, OutputFormat, TimestampFormat};
use serde_json::json;
use tabled::builder::Builder;
use tabled::settings::Style;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/commands/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use monocle::lens::inspect::{
InspectDataSection, InspectDisplayConfig, InspectLens, InspectQueryOptions, InspectQueryType,
InspectResult,
};
use monocle::lens::utils::OutputFormat;
use monocle::utils::OutputFormat;
use monocle::MonocleConfig;
use std::collections::HashSet;

Expand Down
2 changes: 1 addition & 1 deletion src/bin/commands/ip.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Args;
use monocle::lens::ip::{IpInfo, IpLens, IpLookupArgs};
use monocle::lens::utils::OutputFormat;
use monocle::utils::OutputFormat;
use serde_json::json;
use std::net::IpAddr;
use tabled::settings::Style;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/commands/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bgpkit_parser::BgpElem;
use clap::Args;

use monocle::lens::parse::{ParseFilters, ParseLens};
use monocle::lens::utils::{OrderByField, OrderDirection, OutputFormat, TimestampFormat};
use monocle::utils::{OrderByField, OrderDirection, OutputFormat, TimestampFormat};

use super::elem_format::{
available_fields_help, format_elem, format_elems_table, get_header, parse_fields, sort_elems,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/commands/pfx2as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use clap::Args;
use monocle::database::MonocleDatabase;
use monocle::lens::pfx2as::{Pfx2asLens, Pfx2asSearchArgs};
use monocle::lens::rpki::RpkiLens;
use monocle::lens::utils::OutputFormat;
use monocle::utils::OutputFormat;
use monocle::MonocleConfig;

/// Arguments for the Pfx2as command
Expand Down
2 changes: 1 addition & 1 deletion src/bin/commands/rpki.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use monocle::lens::rpki::{
RpkiAspaLookupArgs, RpkiAspaTableEntry, RpkiDataSource, RpkiLens, RpkiRoaEntry,
RpkiRoaLookupArgs, RpkiViewsCollectorOption,
};
use monocle::lens::utils::OutputFormat;
use monocle::utils::OutputFormat;
use monocle::MonocleConfig;
use std::collections::HashSet;
use tabled::settings::object::Columns;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/commands/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bgpkit_parser::BgpElem;
use clap::Args;
use monocle::database::MsgStore;
use monocle::lens::search::SearchFilters;
use monocle::lens::utils::{OrderByField, OrderDirection, OutputFormat, TimestampFormat};
use monocle::utils::{OrderByField, OrderDirection, OutputFormat, TimestampFormat};
use monocle::MonocleConfig;
use rayon::prelude::*;
use tracing::{info, warn};
Expand Down
2 changes: 1 addition & 1 deletion src/bin/commands/time.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Args;
use monocle::lens::time::{TimeBgpTime, TimeLens, TimeParseArgs};
use monocle::lens::utils::OutputFormat;
use monocle::utils::OutputFormat;
use tabled::settings::Style;
use tabled::Table;

Expand Down
2 changes: 1 addition & 1 deletion src/bin/monocle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![deny(clippy::expect_used)]

use clap::{Args, Parser, Subcommand};
use monocle::lens::utils::OutputFormat;
use monocle::utils::OutputFormat;
use monocle::*;
use tracing::Level;

Expand Down
6 changes: 3 additions & 3 deletions src/lens/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ These lenses do not require a persistent database reference:

```rust,ignore
use monocle::lens::time::{TimeLens, TimeParseArgs};
use monocle::lens::utils::OutputFormat;
use monocle::utils::OutputFormat;

let lens = TimeLens::new();
let args = TimeParseArgs::new(vec![
Expand All @@ -195,7 +195,7 @@ println!("{}", out);
```rust,ignore
use monocle::database::MonocleDatabase;
use monocle::lens::inspect::{InspectLens, InspectQueryOptions};
use monocle::lens::utils::OutputFormat;
use monocle::utils::OutputFormat;

let db = MonocleDatabase::open_in_dir("~/.local/share/monocle")?;
let lens = InspectLens::new(&db);
Expand All @@ -221,7 +221,7 @@ for r in results {
```rust,ignore
use monocle::database::MonocleDatabase;
use monocle::lens::as2rel::{As2relLens, As2relSearchArgs};
use monocle::lens::utils::OutputFormat;
use monocle::utils::OutputFormat;

let db = MonocleDatabase::open_in_dir("~/.local/share/monocle")?;
let lens = As2relLens::new(&db);
Expand Down
2 changes: 1 addition & 1 deletion src/lens/as2rel/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use serde::{Deserialize, Serialize};

use super::types::{As2relOutputFormat, As2relSortOrder};
use crate::lens::utils::{bool_from_str, u32_or_vec};
use crate::utils::{bool_from_str, u32_or_vec};

/// Filter for relationship type perspective
///
Expand Down
6 changes: 3 additions & 3 deletions src/lens/as2rel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub use types::{
};

// Re-export common utilities for convenience
pub use crate::lens::utils::{truncate_name, DEFAULT_NAME_MAX_LEN};
pub use crate::utils::{truncate_name, DEFAULT_NAME_MAX_LEN};

use crate::database::{MonocleDatabase, BGPKIT_AS2REL_URL};
use anyhow::Result;
Expand Down Expand Up @@ -63,8 +63,8 @@ impl<'a> As2relLens<'a> {
/// Check why the data needs update, if at all
///
/// Returns `Some(RefreshReason)` if update is needed, `None` if data is current.
pub fn update_reason(&self) -> Option<crate::lens::utils::RefreshReason> {
use crate::lens::utils::RefreshReason;
pub fn update_reason(&self) -> Option<crate::utils::RefreshReason> {
use crate::utils::RefreshReason;

let as2rel = self.db.as2rel();

Expand Down
2 changes: 1 addition & 1 deletion src/lens/as2rel/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This module defines the types used by the AS2Rel lens for relationship
//! queries and result formatting.

use crate::lens::utils::{truncate_name, DEFAULT_NAME_MAX_LEN};
use crate::utils::{truncate_name, DEFAULT_NAME_MAX_LEN};
use serde::{Deserialize, Serialize};

/// Sort order for search results
Expand Down
4 changes: 2 additions & 2 deletions src/lens/inspect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2294,10 +2294,10 @@ impl<'a> InspectLens<'a> {

/// Truncate a name based on display config
fn truncate_name(&self, name: &str, config: &InspectDisplayConfig) -> String {
if !config.truncate_names || name.len() <= config.name_max_width {
if !config.truncate_names {
name.to_string()
} else {
format!("{}...", &name[..config.name_max_width.saturating_sub(3)])
crate::utils::truncate_name(name, config.name_max_width)
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/lens/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@
//! use monocle::lens::inspect::{InspectLens, InspectQueryOptions};
//! ```

// =============================================================================
// Utility module (always available when lib feature is enabled)
// =============================================================================
pub mod utils;

// =============================================================================
// All lenses (require lib feature)
// =============================================================================
Expand Down
6 changes: 3 additions & 3 deletions src/lens/pfx2as/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

use crate::database::MonocleDatabase;
use crate::lens::rpki::RpkiLens;
use crate::lens::utils::{truncate_name, OutputFormat, DEFAULT_NAME_MAX_LEN};
use crate::utils::{truncate_name, OutputFormat, DEFAULT_NAME_MAX_LEN};
use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -381,8 +381,8 @@ impl<'a> Pfx2asLens<'a> {
pub fn refresh_reason(
&self,
ttl: std::time::Duration,
) -> Result<Option<crate::lens::utils::RefreshReason>> {
use crate::lens::utils::RefreshReason;
) -> Result<Option<crate::utils::RefreshReason>> {
use crate::utils::RefreshReason;

let pfx2as = self.db.pfx2as();

Expand Down
12 changes: 1 addition & 11 deletions src/lens/rpki/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! from bgpkit-commons, supporting both current (Cloudflare) and historical
//! (RIPE NCC, RPKIviews) data sources.

use crate::utils::truncate_name;
use anyhow::{anyhow, Result};
use bgpkit_commons::rpki::{HistoricalRpkiSource, RpkiTrie, RpkiViewsCollector};
use chrono::NaiveDate;
Expand Down Expand Up @@ -53,17 +54,6 @@ pub struct RpkiAspaTableEntry {
/// Default max width for customer name in table display
const DEFAULT_NAME_MAX_WIDTH: usize = 20;

/// Truncate a name to fit within max_width, adding "..." if truncated
fn truncate_name(name: &str, max_width: usize) -> String {
if name.len() <= max_width {
name.to_string()
} else if max_width <= 3 {
"...".to_string()
} else {
format!("{}...", &name[..max_width - 3])
}
}

impl From<&RpkiAspaEntry> for RpkiAspaTableEntry {
fn from(entry: &RpkiAspaEntry) -> Self {
RpkiAspaTableEntry {
Expand Down
6 changes: 3 additions & 3 deletions src/lens/rpki/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub use commons::{RpkiAspaEntry, RpkiAspaProvider, RpkiAspaTableEntry, RpkiRoaEn
pub use rtr::RtrClient;

use crate::database::MonocleDatabase;
use crate::lens::utils::option_u32_from_str;
use crate::utils::option_u32_from_str;
use anyhow::Result;
use bgpkit_commons::rpki::RpkiTrie;
use chrono::NaiveDate;
Expand Down Expand Up @@ -396,8 +396,8 @@ impl<'a> RpkiLens<'a> {
pub fn refresh_reason(
&self,
ttl: std::time::Duration,
) -> Result<Option<crate::lens::utils::RefreshReason>> {
use crate::lens::utils::RefreshReason;
) -> Result<Option<crate::utils::RefreshReason>> {
use crate::utils::RefreshReason;

let rpki = self.db.rpki();

Expand Down
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,18 @@ pub use config::{
pub use database::*;

// =============================================================================
// Lens Module - Feature-gated exports
// Utility Module
// =============================================================================

pub mod utils;

// Output format utilities (lib feature)
#[cfg(feature = "lib")]
pub use lens::utils::OutputFormat;
pub use utils::OutputFormat;

// =============================================================================
// Lens Module - Feature-gated exports
// =============================================================================

// =============================================================================
// Server Module (WebSocket API) - requires "server" feature
Expand Down
Loading