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

feat(config): stabilize config command #910

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion crates/pica-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub(crate) struct Args {
pub(crate) enum Command {
Completions(Completions),
Concat(Concat),
#[cfg(feature = "unstable")]
Config(Config),
Convert(Convert),
Count(Count),
Expand Down
2 changes: 0 additions & 2 deletions crates/pica-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub(crate) use completions::Completions;
pub(crate) use concat::Concat;
#[cfg(feature = "unstable")]
pub(crate) use config::Config;
pub(crate) use convert::Convert;
pub(crate) use count::Count;
Expand All @@ -18,7 +17,6 @@ pub(crate) use split::Split;

mod completions;
mod concat;
#[cfg(feature = "unstable")]
mod config;
mod convert;
mod count;
Expand Down
1 change: 0 additions & 1 deletion crates/pica-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ impl Config {
}

/// Saves the config.
#[cfg(feature = "unstable")]
pub(crate) fn save(&self) -> io::Result<()> {
use std::fs::{create_dir_all, File};
use std::io::Write;
Expand Down
2 changes: 0 additions & 2 deletions crates/pica-cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ use thiserror::Error;

pub(crate) type CliResult = Result<ExitCode, CliError>;

#[cfg(feature = "unstable")]
macro_rules! bail {
($($arg:tt)*) => {{
return Err(CliError::Other(format!($($arg)*)));
}};
}

#[cfg(feature = "unstable")]
pub(crate) use bail;

use crate::utils::FilterSetError;
Expand Down
1 change: 0 additions & 1 deletion crates/pica-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ fn run() -> CliResult {
match args.cmd {
Command::Completions(cmd) => cmd.execute(&mut Args::command()),
Command::Concat(cmd) => cmd.execute(&config),
#[cfg(feature = "unstable")]
Command::Config(cmd) => cmd.execute(&mut config),
Command::Convert(cmd) => cmd.execute(&config),
Command::Count(cmd) => cmd.execute(&config),
Expand Down
4 changes: 1 addition & 3 deletions crates/pica-cli/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pub(crate) use crate::config::Config;
#[cfg(feature = "unstable")]
pub(crate) use crate::error::bail;
pub(crate) use crate::error::{CliError, CliResult};
pub(crate) use crate::error::{bail, CliError, CliResult};
pub(crate) use crate::progress::Progress;
pub(crate) use crate::translit::{translit, NormalizationForm};
pub(crate) use crate::utils::{parse_predicates, FilterSet};
71 changes: 33 additions & 38 deletions crates/pica-cli/tests/concat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,47 +207,42 @@ fn skip_invalid() -> TestResult {
.code(2)
.stdout(predicates::str::is_empty())
.stderr(predicates::str::contains(
"parse erorr: invalid record on line 1",
"parse error: invalid record on line 1",
));

// config
#[cfg(feature = "unstable")]
{
let mut cmd = Command::cargo_bin("pica")?;
let temp_dir = TempDir::new().unwrap();
let config = temp_dir.child("pica.toml");
let filename = config.to_str().unwrap();

let assert = cmd
.args(["--config", filename])
.arg("config")
.args(["skip-invalid", "true"])
.assert();

assert
.success()
.code(0)
.stdout(predicates::str::is_empty())
.stderr(predicates::str::is_empty());

let mut cmd = Command::cargo_bin("pica")?;
let assert = cmd
.args(["-c", config.to_str().unwrap()])
.arg("concat")
.arg(data_dir().join("invalid.dat"))
.arg(data_dir().join("ada.dat"))
.assert();

assert
.success()
.code(0)
.stdout(predicates::path::eq_file(
data_dir().join("ada.dat"),
))
.stderr(predicates::str::is_empty());

temp_dir.close().unwrap();
}
let mut cmd = Command::cargo_bin("pica")?;
let temp_dir = TempDir::new().unwrap();
let config = temp_dir.child("pica.toml");
let filename = config.to_str().unwrap();

let assert = cmd
.args(["--config", filename])
.arg("config")
.args(["skip-invalid", "true"])
.assert();

assert
.success()
.code(0)
.stdout(predicates::str::is_empty())
.stderr(predicates::str::is_empty());

let mut cmd = Command::cargo_bin("pica")?;
let assert = cmd
.args(["-c", config.to_str().unwrap()])
.arg("concat")
.arg(data_dir().join("invalid.dat"))
.arg(data_dir().join("ada.dat"))
.assert();

assert
.success()
.code(0)
.stdout(predicates::path::eq_file(data_dir().join("ada.dat")))
.stderr(predicates::str::is_empty());

temp_dir.close().unwrap();
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/pica-cli/tests/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn convert_skip_invalid() -> TestResult {
.code(2)
.stdout(predicates::str::is_empty().not())
.stderr(predicates::str::contains(
"parse erorr: invalid record on line 1",
"parse error: invalid record on line 1",
));

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/pica-cli/tests/count/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ fn count_skip_invalid() -> TestResult {
.code(2)
.stdout(predicates::str::is_empty())
.stderr(predicates::str::starts_with(
"error: parse erorr: invalid record on line 1",
"error: parse error: invalid record on line 1",
));

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/pica-cli/tests/explode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ fn explode_skip_invalid() -> TestResult {
.code(2)
.stdout(predicates::str::is_empty())
.stderr(predicates::str::contains(
"parse erorr: invalid record on line 1",
"parse error: invalid record on line 1",
));

let mut cmd = Command::cargo_bin("pica")?;
Expand Down
2 changes: 1 addition & 1 deletion crates/pica-cli/tests/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn filter_skip_invalid() -> TestResult {
.code(2)
.stdout(predicates::str::is_empty().not())
.stderr(predicates::str::contains(
"parse erorr: invalid record on line 12",
"parse error: invalid record on line 12",
));

let mut cmd = Command::cargo_bin("pica")?;
Expand Down
2 changes: 1 addition & 1 deletion crates/pica-cli/tests/frequency/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn frequency_skip_invalid() -> TestResult {
.code(2)
.stdout(predicates::str::is_empty())
.stderr(predicates::str::contains(
"parse erorr: invalid record on line 1",
"parse error: invalid record on line 1",
));

let mut cmd = Command::cargo_bin("pica")?;
Expand Down
2 changes: 1 addition & 1 deletion crates/pica-cli/tests/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn hash_skip_invalid() -> TestResult {
.code(2)
.stdout(predicates::ord::eq("ppn,hash\n"))
.stderr(predicates::str::contains(
"parse erorr: invalid record on line 1",
"parse error: invalid record on line 1",
));

Ok(())
Expand Down
1 change: 0 additions & 1 deletion crates/pica-cli/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub(crate) mod prelude;

mod completions;
mod concat;
#[cfg(feature = "unstable")]
mod config;
mod convert;
mod count;
Expand Down
2 changes: 1 addition & 1 deletion crates/pica-cli/tests/partition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn partition_skip_invalid() -> TestResult {
.code(2)
.stdout(predicates::str::is_empty())
.stderr(predicates::str::contains(
"parse erorr: invalid record on line 1",
"parse error: invalid record on line 1",
));

outdir.close().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/pica-cli/tests/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn print_skip_invalid() -> TestResult {
.code(2)
.stdout(predicates::str::is_empty())
.stderr(predicates::str::contains(
"parse erorr: invalid record on line 1",
"parse error: invalid record on line 1",
));

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/pica-cli/tests/sample/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn sample_skip_invalid() -> TestResult {
.code(2)
.stdout(predicates::str::is_empty())
.stderr(predicates::str::contains(
"parse erorr: invalid record on line 1",
"parse error: invalid record on line 1",
));

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/pica-cli/tests/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn select_skip_invalid() -> TestResult {
.code(2)
.stdout(predicates::str::is_empty())
.stderr(predicates::str::contains(
"parse erorr: invalid record on line 1",
"parse error: invalid record on line 1",
));

let mut cmd = Command::cargo_bin("pica")?;
Expand Down
2 changes: 1 addition & 1 deletion crates/pica-cli/tests/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ fn slice_skip_invalid() -> TestResult {
.code(2)
.stdout(predicates::str::is_empty())
.stderr(predicates::str::contains(
"parse erorr: invalid record on line 1",
"parse error: invalid record on line 1",
));

outdir.close().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/pica-cli/tests/split/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn split_skip_invalid() -> TestResult {
.code(2)
.stdout(predicates::str::is_empty())
.stderr(predicates::str::contains(
"parse erorr: invalid record on line 1",
"parse error: invalid record on line 1",
));

outdir.close().unwrap();
Expand Down
17 changes: 6 additions & 11 deletions docs/book/commands/config.qmd
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# config {.unnumbered}

::: {.callout-warning}
Das Kommando `config` ist eine `unstable`-Funktion, die noch nicht in den
Releases enthalten ist und explizit aktiviert werden muss.
:::

Mithilfe des `config`-Kommandos lassen sich bestimmte Optionen setzen und das
Laufzeitverhalten von `pica` beeinflussen. Falls noch keine Konfigurationsdatei
existiert, wird diese automatisch angelegt und je nach Betriebssystem in den
Expand All @@ -20,9 +15,9 @@ dafür vorgesehenen Pfaden gespeichert:

Kann eine Zeile in der Eingabe nicht als Datensatz (normalisiertes PICA+)
dekodiert werden, brechen die meisten Kommandos die Verarbeitung mit einer
Fehlermeldung ab. Dieses Verhalten kann mit der Option `--skip-invalid`
geändert werden, sodass diese ungültigen Datensätze übersprungen werden. Dieses
Verhalten kann auch in der Konfigurationsdatei hinterlegt werden:
Fehlermeldung ab. Dieses Verhalten kann mit der Option `--skip-invalid` geändert
werden, sodass diese ungültigen Datensätze übersprungen werden. Dieses Verhalten
kann auch in der Konfigurationsdatei hinterlegt werden:

```{.bash}
$ pica config skip-invalid true
Expand All @@ -35,9 +30,9 @@ entfallen. Die Einstellung lässt sich mit `--unset` rückgängig machen:
$ pica config --unset skip-invalid
```

### Ändern der Unicode Normalform
### Ändern der Unicode-Normalform

Liegen die PICA-Daten in einer anderen [Unicode Normalform] vor, lassen sich
Liegen die PICA-Daten in einer anderen [Unicode-Normalform] vor, lassen sich
Filterausdrücke mit der Option `normalization` an die Normalform der Daten
angleichen:

Expand All @@ -54,4 +49,4 @@ $ pica config --unset normalization
```


[Unicode Normalform]: https://de.wikipedia.org/wiki/Normalisierung_(Unicode)
[Unicode-Normalform]: https://de.wikipedia.org/wiki/Normalisierung_(Unicode)
2 changes: 1 addition & 1 deletion src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{ByteRecord, StringRecord};
/// An error that can occur when reading records.
#[derive(thiserror::Error, Debug)]
pub enum ReadPicaError {
#[error("parse erorr: {msg}")]
#[error("parse error: {msg}")]
Parse { msg: String, err: ParsePicaError },
#[error("parse erorr: {msg}")]
Utf8 { msg: String, err: Utf8Error },
Expand Down
Loading