Skip to content

Commit

Permalink
load and parse example config
Browse files Browse the repository at this point in the history
  • Loading branch information
solidiquis committed Feb 11, 2024
1 parent c5f66c0 commit d915132
Show file tree
Hide file tree
Showing 13 changed files with 513 additions and 22 deletions.
95 changes: 92 additions & 3 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ keywords = ["tree", "find", "ls", "du", "commandline"]
exclude = ["assets/*", "scripts/*", "example/*"]
readme = "README.md"
license = "MIT"
rust-version = "1.74.0"
rust-version = "1.76.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down Expand Up @@ -50,6 +50,7 @@ once_cell = "1.17.0"
regex = "1.7.3"
terminal_size = "0.2.6"
thiserror = "1.0.40"
toml = "0.8.8"

[target.'cfg(unix)'.dependencies]
libc = "0.2.141"
Expand Down
16 changes: 7 additions & 9 deletions example/.erdtree.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
# Please becareful modifying this file as some tests may assume
# this file to look a certain way.

icons = true
human = true

# Compute file sizes like `du`
[du]
disk_usage = "block"
metric = "block"
icons = true
layout = "flat"
no-ignore = true
no-git = true
hidden = true
level = 1

# Do as `ls -l`
[ls]
icons = true
human = true
level = 1
suppress-size = true
long = true
no-ignore = true
hidden = true
gitignore = true
no_hidden = true

# How many lines of Rust are in this code base?
[rs]
disk-usage = "line"
metric = "line"
level = 1
pattern = "\\.rs$"
4 changes: 2 additions & 2 deletions src/disk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
/// Binary and SI prefixes.
pub mod prefix;

/// https://doc.rust-lang.org/std/os/unix/fs/trait.MetadataExt.html#tymethod.blocks
/// <https://doc.rust-lang.org/std/os/unix/fs/trait.MetadataExt.html#tymethod.blocks>
#[cfg(unix)]
const BLOCK_SIZE: u64 = 512;

Expand Down Expand Up @@ -93,7 +93,7 @@ impl Usage {
}

/// Gets the apparent file size rather than disk usage. Refer to `--apparent-size` in the man
/// pages of `du`: https://man7.org/linux/man-pages/man1/du.1.html
/// pages of `du`: <https://man7.org/linux/man-pages/man1/du.1.html>
pub fn init_logical(metadata: &Metadata, presentation: BytePresentation) -> Self {
let value = metadata.is_dir().then_some(0).unwrap_or(metadata.len());

Expand Down
4 changes: 2 additions & 2 deletions src/disk/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
fmt::{self, Display},
};

/// https://en.wikipedia.org/wiki/Binary_prefix
/// <https://en.wikipedia.org/wiki/Binary_prefix>
#[derive(Debug, PartialEq)]
pub enum Binary {
Base,
Expand All @@ -14,7 +14,7 @@ pub enum Binary {
Pebi,
}

/// https://en.wikipedia.org/wiki/International_System_of_Units
/// <https://en.wikipedia.org/wiki/International_System_of_Units>
#[derive(Debug, PartialEq)]
pub enum Si {
Base,
Expand Down
2 changes: 1 addition & 1 deletion src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl File {
Metric::Line => disk::Usage::init_line_count(&data, &metadata, *follow)?,

#[cfg(unix)]
Metric::Blocks => disk::Usage::init_blocks(&metadata),
Metric::Block => disk::Usage::init_blocks(&metadata),
};

#[cfg(unix)]
Expand Down
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(windows, feature(windows_by_handle))]
use clap::CommandFactory;
use log::Log;
use std::{
io::{stdout, Write},
Expand All @@ -7,6 +8,7 @@ use std::{

/// Defines the command-line interface and the context used throughout Erdtree.
mod user;
use user::Context;

/// Concerned with disk usage calculation and presentation.
mod disk;
Expand All @@ -27,6 +29,8 @@ mod logging;
/// Concerned with rendering the program output.
mod render;

const BIN_NAME: &str = "erd";

fn main() -> ExitCode {
if let Err(e) = run() {
eprintln!("{e}");
Expand All @@ -38,6 +42,11 @@ fn main() -> ExitCode {
fn run() -> Result<()> {
let mut ctx = user::Context::init()?;

if let Some(shell) = ctx.completions {
clap_complete::generate(shell, &mut Context::command(), BIN_NAME, &mut stdout());
return Ok(());
}

let logger = ctx
.verbose
.then_some(logging::LoggityLog::init())
Expand Down
2 changes: 1 addition & 1 deletion src/user/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum Metric {

/// Total amount of blocks allocated to store a file on disk
#[cfg(unix)]
Blocks,
Block,
}

/// Whether to report byte size using SI or binary prefixes or no prefix.
Expand Down
25 changes: 25 additions & 0 deletions src/user/config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const ERDTREE_CONFIG_TOML: &str = ".erdtree.toml";

Check warning on line 1 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `ERDTREE_CONFIG_TOML` is never used

Check warning on line 1 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `ERDTREE_CONFIG_TOML` is never used
const ERDTREE_TOML_PATH: &str = "ERDTREE_TOML_PATH";

Check warning on line 2 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `ERDTREE_TOML_PATH` is never used

Check warning on line 2 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `ERDTREE_TOML_PATH` is never used

Check warning on line 2 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

constant `ERDTREE_TOML_PATH` is never used

Check warning on line 2 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

constant `ERDTREE_TOML_PATH` is never used

const ERDTREE_CONFIG_NAME: &str = ".erdtreerc";

Check warning on line 4 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `ERDTREE_CONFIG_NAME` is never used

Check warning on line 4 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `ERDTREE_CONFIG_NAME` is never used

Check warning on line 4 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

constant `ERDTREE_CONFIG_NAME` is never used

Check warning on line 4 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

constant `ERDTREE_CONFIG_NAME` is never used
const ERDTREE_CONFIG_PATH: &str = "ERDTREE_CONFIG_PATH";

Check warning on line 5 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `ERDTREE_CONFIG_PATH` is never used

Check warning on line 5 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `ERDTREE_CONFIG_PATH` is never used

Check warning on line 5 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

constant `ERDTREE_CONFIG_PATH` is never used

Check warning on line 5 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

constant `ERDTREE_CONFIG_PATH` is never used

const ERDTREE_DIR: &str = "erdtree";

Check warning on line 7 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `ERDTREE_DIR` is never used

Check warning on line 7 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `ERDTREE_DIR` is never used

Check warning on line 7 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

constant `ERDTREE_DIR` is never used

Check warning on line 7 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

constant `ERDTREE_DIR` is never used

#[cfg(unix)]
const CONFIG_DIR: &str = ".config";

Check warning on line 10 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `CONFIG_DIR` is never used

Check warning on line 10 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `CONFIG_DIR` is never used

Check warning on line 10 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

constant `CONFIG_DIR` is never used

Check warning on line 10 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

constant `CONFIG_DIR` is never used

#[cfg(unix)]
const HOME: &str = "HOME";

Check warning on line 13 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `HOME` is never used

Check warning on line 13 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `HOME` is never used

Check warning on line 13 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

constant `HOME` is never used

Check warning on line 13 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

constant `HOME` is never used

#[cfg(unix)]
const XDG_CONFIG_HOME: &str = "XDG_CONFIG_HOME";

Check warning on line 16 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `XDG_CONFIG_HOME` is never used

Check warning on line 16 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Check

constant `XDG_CONFIG_HOME` is never used

Check warning on line 16 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

constant `XDG_CONFIG_HOME` is never used

Check warning on line 16 in src/user/config/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

constant `XDG_CONFIG_HOME` is never used

/// Concerned with loading `.erdtree.toml`.
pub mod toml;

/// Concerned with parsing the result of [`toml::load`] into args.
pub mod parse;

#[cfg(test)]
mod test;
Loading

0 comments on commit d915132

Please sign in to comment.