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

CLI now accepts strings as stdin #15

Merged
merged 6 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
🚨 make clippy happy
  • Loading branch information
AucaCoyan committed Jun 1, 2023
commit 75cf37aaee16a97a1c54d9c78759395c2b69340f
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ impl Config {
/// You cannot skip any field yet.
pub fn new(tab_spaces: usize, max_width: usize, margin: usize) -> Self {
Config {
tab_spaces: tab_spaces,
max_width: max_width,
margin: margin,
tab_spaces,
max_width,
margin,
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct Session<'b, T: Write> {
impl<'b, T: Write + 'b> Session<'b, T> {
pub fn new(config: config::Config, out: Option<&'b mut T>) -> Self {
Self {
config: config,
out: out,
config,
out,
has_operational_errors: false,
}
}
Expand Down Expand Up @@ -62,9 +62,9 @@ impl Input {

fn contents(&self) -> Vec<u8> {
match self {
Input::File(path) => std::fs::read(path).expect(
format!("something went wrong reading the file {}", path.display()).as_str(),
),
Input::File(path) => std::fs::read(path).unwrap_or_else(|_| {
panic!("something went wrong reading the file {}", path.display())
}),
Input::Text(string) => string.as_bytes().to_vec(),
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#[allow(unused_import_braces)]
use anyhow::Result;
use clap::Parser;
use env_logger;
use nufmt::config::Config;
use nufmt::{Input, Session};
use std::error::Error;
Expand Down Expand Up @@ -108,9 +107,7 @@ fn execute(files: Vec<PathBuf>, options: Config) -> Result<i32> {
}

fn format_and_emit_report<T: Write>(session: &mut Session<'_, T>, input: Input) {
match session.format(input) {
_ => {} // _ => todo!("Here `nufmt` gives you a FormatReport"),
}
session.format(input);
}

#[cfg(test)]
Expand Down