8000 Print one name per line by default in the list subcommands, so that names with spaces can be told apart by dominion525 · Pull Request #178 · dominion525/jetdb · GitHub
[go: up one dir, main page]

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
6 changes: 3 additions & 3 deletions crates/jetdb-cli/src/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ pub struct FormListArgs {
/// Database file path (.mdb / .accdb)
pub file: PathBuf,

/// Print one name per line
/// Print one name per line (the default; kept for compatibility, does nothing)
#[arg(short = '1', long = "newline", conflicts_with = "delimiter")]
pub newline: bool,

/// Custom delimiter between names
/// Print the names on one line, separated by this string
#[arg(short = 'd', long = "delimiter")]
pub delimiter: Option<String>,

Expand Down Expand Up @@ -205,7 +205,7 @@ fn run_list(args: &FormListArgs, password: Option<&str>) -> Result<(), jetdb::Fi
.collect();
names.sort_unstable();

crate::print_names(&names, args.newline, args.delimiter.as_deref());
crate::print_names(&names, args.delimiter.as_deref());

Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions crates/jetdb-cli/src/macro_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ pub struct MacroListArgs {
/// Database file path (.mdb / .accdb)
pub file: PathBuf,

/// Print one macro name per line
/// Print one macro name per line (the default; kept for compatibility, does nothing)
#[arg(short = '1', long = "newline", conflicts_with = "delimiter")]
pub newline: bool,

/// Delimiter between macro names (default: space)
/// Print the macro names on one line, separated by this string
#[arg(short = 'd', long = "delimiter")]
pub delimiter: Option<String>,
}
Expand Down Expand Up @@ -109,7 +109,7 @@ fn run_list(args: &MacroListArgs, password: Option<&str>) -> Result<(), jetdb::F
.collect();
names.sort_unstable();

crate::print_names(&names, args.newline, args.delimiter.as_deref());
crate::print_names(&names, args.delimiter.as_deref());

Ok(())
}
Expand Down
22 changes: 12 additions & 10 deletions crates/jetdb-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,22 @@ pub(crate) fn exit_code<E: std::fmt::Display>(result: Result<(), E>) -> ExitCode
}
}

/// Print `names` as the list subcommands do: one a line with `newline`, or
/// else on one line joined by `delimiter`, or by a space; nothing when there
/// are none.
pub(crate) fn print_names(names: &[impl AsRef<str>], newline: bool, delimiter: Option<&str>) {
/// Print `names` as the list subcommands do: on one line joined by
/// `delimiter`, or else one a line; nothing when there are none.
pub(crate) fn print_names(names: &[impl AsRef<str>], delimiter: Option<&str>) {
if names.is_empty() {
return;
}
if newline {
for name in names {
println!("{}", name.as_ref());
match delimiter {
Some(delimiter) => {
let names: Vec<&str> = names.iter().map(AsRef::as_ref).collect();
println!("{}", names.join(delimiter));
}
None => {
for name in names {
println!("{}", name.as_ref());
}
}
} else {
let names: Vec<&str> = names.iter().map(AsRef::as_ref).collect();
println!("{}", names.join(delimiter.unwrap_or(" ")));
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/jetdb-cli/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ pub struct QueryListArgs {
/// Database file path (.mdb / .accdb)
pub file: PathBuf,

/// Print one query name per line
/// Print one query name per line (the default; kept for compatibility, does nothing)
#[arg(short = '1', long = "newline", conflicts_with = "delimiter")]
pub newline: bool,

/// Delimiter between query names (default: space)
/// Print the query names on one line, separated by this string
#[arg(short = 'd', long = "delimiter")]
pub delimiter: Option<String>,
}
Expand Down Expand Up @@ -62,7 +62,7 @@ fn run_list(args: &QueryListArgs, password: Option<&str>) -> Result<(), jetdb::F

let mut names: Vec<&str> = queries.iter().map(|q| q.name.as_str()).collect();
names.sort_unstable();
crate::print_names(&names, args.newline, args.delimiter.as_deref());
crate::print_names(&names, args.delimiter.as_deref());

Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions crates/jetdb-cli/src/vba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ pub struct VbaListArgs {
/// Database file path (.mdb / .accdb)
pub file: PathBuf,

/// Print one module name per line
/// Print one module name per line (the default; kept for compatibility, does nothing)
#[arg(short = '1', long = "newline", conflicts_with = "delimiter")]
pub newline: bool,

/// Delimiter between module names (default: space)
/// Print the module names on one line, separated by this string
#[arg(short = 'd', long = "delimiter")]
pub delimiter: Option<String>,
}
Expand Down Expand Up @@ -63,7 +63,7 @@ fn run_list(args: &VbaListArgs, password: Option<&str>) -> Result<(), jetdb::Fil
let mut names: Vec<&str> = project.modules.iter().map(|m| m.name.as_str()).collect();
names.sort_unstable();

crate::print_names(&names, args.newline, args.delimiter.as_deref());
crate::print_names(&names, args.delimiter.as_deref());

Ok(())
}
Expand Down
22 changes: 14 additions & 8 deletions crates/jetdb-cli/tests/cli_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,32 @@ fn form_list() {
String::from_utf8_lossy(&output.stderr)
);
let stdout = String::from_utf8_lossy(&output.stdout);
let trimmed = stdout.trim();
assert!(
trimmed.contains("Form1"),
"should contain Form1, got: {trimmed}"
stdout.lines().any(|l| l == "Form1"),
"should have Form1 on a line, got: {stdout}"
);
}

#[test]
fn form_list_newline() {
let path = skip_if_missing!("vbaV2007.accdb");
let path = skip_if_missing!("formPropTest.accdb");
let output = jetdb_bin()
.args(["form", "list", "-1", path.to_str().unwrap()])
.output()
.expect("failed to run jetdb");
assert!(output.status.success());
let stdout = String::from_utf8_lossy(&output.stdout);
let lines: Vec<&str> = stdout.lines().collect();
let default = jetdb_bin()
.args(["form", "list", path.to_str().unwrap()])
.output()
.expect("failed to run jetdb");
assert_eq!(
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&default.stdout),
"-1 should print what the default prints"
);
assert!(
lines.iter().any(|l| l.trim() == "Form1"),
"should have Form1 in output"
String::from_utf8_lossy(&default.stdout).lines().count() >= 2,
"should have a name a line"
);
}

Expand Down
18 changes: 15 additions & 3 deletions crates/jetdb-cli/tests/cli_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ fn stdout_of(output: &std::process::Output) -> String {
}

// ---------------------------------------------------------------------------
// List macros (default: space-separated, -1, -d)
// List macros (default: one per line, -1, -d)
// ---------------------------------------------------------------------------

#[test]
fn macro_list() {
let path = skip_if_missing!(MACRO_FILE);
let stdout = stdout_of(&run(&["macro", "list", path.to_str().unwrap()]));
let names: Vec<&str> = stdout.trim().split(' ').collect();
let names: Vec<&str> = stdout.lines().collect();
assert!(names.contains(&"mcrStructure"), "got: {stdout}");
let mut sorted = names.clone();
sorted.sort_unstable();
Expand All @@ -39,7 +39,19 @@ fn macro_list() {
fn macro_list_newline() {
let path = skip_if_missing!(MACRO_FILE);
let stdout = stdout_of(&run(&["macro", "list", path.to_str().unwrap(), "-1"]));
assert!(stdout.lines().any(|l| l == "mcrErrors"), "got: {stdout}");
let default = stdout_of(&run(&["macro", "list", path.to_str().unwrap()]));
assert_eq!(stdout, default, "-1 should print what the default prints");
}

#[test]
fn macro_list_names_with_spaces() {
// nwind.mdb has macros whose names have spaces in them.
let path = skip_if_missing!("V1997/nwind.mdb");
let stdout = stdout_of(&run(&["macro", "list", path.to_str().unwrap()]));
assert!(
stdout.lines().any(|l| l == "Customer Labels Dialog"),
"got: {stdout}"
);
}

#[test]
Expand Down
36 changes: 20 additions & 16 deletions crates/jetdb-cli/tests/cli_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod common;
use common::jetdb_bin;

// ---------------------------------------------------------------------------
// List queries (default: space-separated)
// List queries (default: one per line)
// ---------------------------------------------------------------------------

#[test]
Expand All @@ -19,21 +19,24 @@ fn queries_list() {
String::from_utf8_lossy(&output.stderr)
);
let stdout = String::from_utf8_lossy(&output.stdout);
let trimmed = stdout.trim();
assert!(!trimmed.is_empty(), "should have query names in output");
// Should contain known query names
// Should contain known query names, one a line
assert!(
trimmed.contains("SelectQuery"),
"should contain SelectQuery, got: {trimmed}"
stdout.lines().any(|l| l == "SelectQuery"),
"should have SelectQuery on a line, got: {stdout}"
);
assert!(
trimmed.contains("UnionQuery"),
"should contain UnionQuery, got: {trimmed}"
stdout.lines().any(|l| l == "UnionQuery"),
"should have UnionQuery on a line, got: {stdout}"
);
// queryTestV2003.mdb has 9 queries
assert!(
stdout.lines().count() >= 9,
"should have at least 9 query names, got: {stdout}"
);
}

// ---------------------------------------------------------------------------
// List queries with newline delimiter (-1)
// List queries with -1: the same as the default
// ---------------------------------------------------------------------------

#[test]
Expand All @@ -44,13 +47,14 @@ fn queries_list_newline() {
.output()
.expect("failed to run jetdb");
assert!(output.status.success());
let stdout = String::from_utf8_lossy(&output.stdout);
let lines: Vec<&str> = stdout.lines().collect();
// queryTestV2003.mdb has 9 queries
assert!(
lines.len() >= 9,
"should have at least 9 query names, got {}",
lines.len()
let default = jetdb_bin()
.args(["queries", "list", path.to_str().unwrap()])
.output()
.expect("failed to run jetdb");
assert_eq!(
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&default.stdout),
"-1 should print what the default prints"
);
}

Expand Down
38 changes: 16 additions & 22 deletions crates/jetdb-cli/tests/cli_vba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod common;
use common::jetdb_bin;

// ---------------------------------------------------------------------------
// List VBA modules (default: space-separated)
// List VBA modules (default: one per line)
// ---------------------------------------------------------------------------

#[test]
Expand All @@ -19,24 +19,16 @@ fn vba_list() {
String::from_utf8_lossy(&output.stderr)
);
let stdout = String::from_utf8_lossy(&output.stdout);
let trimmed = stdout.trim();
assert!(!trimmed.is_empty(), "should have module names in output");
assert!(
trimmed.contains("Module1"),
"should contain Module1, got: {trimmed}"
);
assert!(
trimmed.contains("Class1"),
"should contain Class1, got: {trimmed}"
);
assert!(
trimmed.contains("Form_Form1"),
"should contain Form_Form1, got: {trimmed}"
);
for name in ["Class1", "Form_Form1", "Module1"] {
assert!(
stdout.lines().any(|l| l == name),
"should have {name} on a line, got: {stdout}"
);
}
}

// ---------------------------------------------------------------------------
// List VBA modules with newline delimiter (-1)
// List VBA modules with -1: the same as the default
// ---------------------------------------------------------------------------

#[test]
Expand All @@ -47,12 +39,14 @@ fn vba_list_newline() {
.output()
.expect("failed to run jetdb");
assert!(output.status.success());
let stdout = String::from_utf8_lossy(&output.stdout);
let lines: Vec<&str> = stdout.lines().collect();
assert!(
lines.len() >= 3,
"should have at least 3 module names, got {}",
lines.len()
let default = jetdb_bin()
.args(["vba", "list", path.to_str().unwrap()])
.output()
.expect("failed to run jetdb");
assert_eq!(
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&default.stdout),
"-1 should print what the default prints"
);
}

Expand Down
Loading
Loading
0