Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.0 development (just a draft PR to view the diff) #787

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a600910
feat(parser)!: Introduction of clap based parser
MartinFillon Nov 11, 2023
2569110
feat: Add Fortran icons
orest58008 Jan 3, 2024
ac97e48
fix: Format the code
orest58008 Jan 4, 2024
17c72af
test: updated tests to fit new features
MartinFillon Dec 14, 2023
9346e7f
refactor: add enum arguments for clap parser
PThorpe92 Jan 14, 2024
12dc4a9
fix: correct test behavior for arg parsing
PThorpe92 Jan 14, 2024
785eebc
fix: merge conflict issues
PThorpe92 Jan 14, 2024
428c991
feat(parser)!: Introduction of clap based parser
MartinFillon Nov 11, 2023
d1a704a
refactor: change ArgAction count to normal flags
tertsdiepraam Feb 5, 2024
aeb605b
refactor: change type of help field of Options to unit
tertsdiepraam Feb 5, 2024
c5013aa
refactor: derive Default on Opts instead custom impl
tertsdiepraam Feb 5, 2024
9287d5c
refactor: remove explicit long arguments when they can be inferred
tertsdiepraam Feb 5, 2024
9c25728
refactor: remove unnecessary types and implementations from parser.rs
tertsdiepraam Feb 5, 2024
d3c6d39
refactor: remove Display for ShowWhen and ColorScaleArgs
tertsdiepraam Feb 5, 2024
c5c7d6f
refactor: cleanup custom ValueEnum implementation
tertsdiepraam Feb 5, 2024
a9df7a8
fix: allow arguments to be passed multiple times
tertsdiepraam Feb 5, 2024
0c0cf5e
refactor: modified args to feat actual args and runned formatter
MartinFillon Feb 14, 2024
a4a3d1e
refactor: linting of the code with clippy
MartinFillon Feb 14, 2024
65dc8d1
fix: fixed custom time-style
MartinFillon Feb 16, 2024
70883df
test: updated tests
MartinFillon Feb 16, 2024
7d6cd61
refactor: fixed clippy lints
MartinFillon Feb 17, 2024
f119992
feat: added absolute flag to he parser
MartinFillon Mar 4, 2024
03eee54
fix: clippy linting
MartinFillon Mar 5, 2024
490cccd
test: redumped powertest
MartinFillon Mar 8, 2024
ee441e2
fix: add clap parser use to be able to compile
MartinFillon Apr 11, 2024
9e6849d
chore: update tests
MartinFillon Jul 4, 2024
54bda48
fix(clippy): clippy lints were broken
MartinFillon Sep 12, 2024
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
40 changes: 34 additions & 6 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ ansi-width = "0.1.0"
serde = { version = "1.0.193", features = ["derive"] }
dirs = "5.0.1"
serde_norway = "0.9"
clap = { version = "4.4.8", features = ["derive"] }

[dependencies.git2]
version = "0.19"
Expand Down
1 change: 0 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,5 @@ gen_test_dir:

find result/dump -type f \( -name "*.stdout" -o -name "*.stderr" \) -exec sh -c 'base=$(basename {}); if [ -e "tests/gen/${base%.*}.toml" ]; then cp {} tests/gen/; elif [ -e "tests/cmd/${base%.*}.toml" ]; then cp {} tests/cmd/; elif [ -e "tests/ptests/${base%.*}.toml" ]; then cp {} tests/ptests/; fi' \;


@itest-gen:
nix build -L ./#trycmd
128 changes: 57 additions & 71 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ use std::io::{self, stdin, ErrorKind, IsTerminal, Read, Write};
use std::path::{Component, PathBuf};
use std::process::exit;

use clap::Parser;
use nu_ansi_term::{AnsiStrings as ANSIStrings, Style};

use crate::fs::feature::git::GitCache;
use crate::fs::filter::{FileFilterFlags::OnlyFiles, GitIgnore};
use crate::fs::{Dir, File};
use crate::options::parser::Opts;
use crate::options::stdin::FilesInput;
use crate::options::{vars, Options, OptionsResult, Vars};
use crate::options::{vars, Options, Vars};
use crate::output::{details, escape, file_name, grid, grid_details, lines, Mode, View};
use crate::theme::Theme;
use log::*;
Expand All @@ -54,85 +56,69 @@ fn main() {
logger::configure(env::var_os(vars::EZA_DEBUG).or_else(|| env::var_os(vars::EXA_DEBUG)));

let stdout_istty = io::stdout().is_terminal();

let mut input = String::new();
let args: Vec<_> = env::args_os().skip(1).collect();
match Options::parse(args.iter().map(std::convert::AsRef::as_ref), &LiveVars) {
OptionsResult::Ok(options, mut input_paths) => {
// List the current directory by default.
// (This has to be done here, otherwise git_options won’t see it.)
if input_paths.is_empty() {
match &options.stdin {
FilesInput::Args => {
input_paths = vec![OsStr::new(".")];
}
FilesInput::Stdin(separator) => {
stdin()
.read_to_string(&mut input)
.expect("Failed to read from stdin");
input_paths.extend(
input
.split(&separator.clone().into_string().unwrap_or("\n".to_string()))
.map(std::ffi::OsStr::new)
.filter(|s| !s.is_empty())
.collect::<Vec<_>>(),
);
}
}
}

let git = git_options(&options, &input_paths);
let writer = io::stdout();
let git_repos = git_repos(&options, &input_paths);

let console_width = options.view.width.actual_terminal_width();
let theme = options.theme.to_theme(stdout_istty);
let exa = Exa {
options,
writer,
input_paths,
theme,
console_width,
git,
git_repos,
};

info!("matching on exa.run");
match exa.run() {
Ok(exit_status) => {
trace!("exa.run: exit Ok(exit_status)");
exit(exit_status);
}

Err(e) if e.kind() == ErrorKind::BrokenPipe => {
warn!("Broken pipe error: {e}");
exit(exits::SUCCESS);
}
let cli = Opts::parse();
let mut input_paths: Vec<&OsStr> = cli.paths.iter().map(OsString::as_os_str).collect();
let options = match Options::deduce(&cli, &LiveVars) {
Ok(c) => c,
Err(error) => {
eprintln!("eza: {error}");
exit(exits::OPTIONS_ERROR);
}
};

Err(e) => {
eprintln!("{e}");
trace!("exa.run: exit RUNTIME_ERROR");
exit(exits::RUNTIME_ERROR);
}
if input_paths.is_empty() {
match &options.stdin {
FilesInput::Args => {
input_paths = vec![OsStr::new(".")];
}
FilesInput::Stdin(separator) => {
stdin()
.read_to_string(&mut input)
.expect("Failed to read from stdin");
input_paths.extend(
input
.split(&separator.clone().into_string().unwrap_or("\n".to_string()))
.map(OsStr::new)
.filter(|s| !s.is_empty())
.collect::<Vec<_>>(),
);
}
}
}

OptionsResult::Help(help_text) => {
print!("{help_text}");
}
let git = git_options(&options, &input_paths);
let git_repos = git_repos(&options, &input_paths);
let writer = io::stdout();

let console_width = options.view.width.actual_terminal_width();
let theme = options.theme.to_theme(stdout_istty);
let exa = Exa {
options,
writer,
input_paths,
theme,
console_width,
git,
git_repos,
};

OptionsResult::Version(version_str) => {
print!("{version_str}");
info!("matching on exa.run");
match exa.run() {
Ok(exit_status) => {
trace!("exa.run: exit Ok(exit_status)");
exit(exit_status);
}

OptionsResult::InvalidOptions(error) => {
eprintln!("eza: {error}");

if let Some(s) = error.suggestion() {
eprintln!("{s}");
}
Err(e) if e.kind() == ErrorKind::BrokenPipe => {
warn!("Broken pipe error: {e}");
exit(exits::SUCCESS);
}

exit(exits::OPTIONS_ERROR);
Err(e) => {
eprintln!("{e}");
trace!("exa.run: exit RUNTIME_ERROR");
exit(exits::RUNTIME_ERROR);
}
}
}
Expand Down
Loading