Skip to content

Commit

Permalink
Add option --all
Browse files Browse the repository at this point in the history
Closes #21
  • Loading branch information
noeddl committed Mar 22, 2021
1 parent be14f32 commit 80c5af1
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ struct Ukebox {
enum Subcommand {
/// Chord chart lookup
Chart {
/// Print out all voicings of <chord> that fulfill the given conditions
#[structopt(short, long)]
all: bool,
/// Minimal fret (= minimal position) from which to play <chord>
#[structopt(short = "f", long, default_value = "0")]
min_fret: FretID,
Expand All @@ -36,6 +39,7 @@ fn main() {

match args.cmd {
Subcommand::Chart {
all,
min_fret,
transpose,
chord,
Expand All @@ -47,12 +51,19 @@ fn main() {
// Add semitones (e.g. 1, +1).
_ => chord + transpose as u8,
};
let voicings = chord.get_voicings(min_fret, tuning);
let voicing = voicings[0];
let chart = ChordChart::new(voicing, 4);

println!("{}", format!("[{}]\n", chord));
println!("{}", chart);

let voicings = chord.get_voicings(min_fret, tuning);

for voicing in voicings {
let chart = ChordChart::new(voicing, 4);
println!("{}", chart);

if !all {
break;
}
}
}
Subcommand::Name { fret_pattern } => {
let voicing = Voicing::new(fret_pattern, tuning);
Expand Down
108 changes: 108 additions & 0 deletions tests/ukebox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,114 @@ fn test_transpose(
Ok(())
}

#[rstest(
chord,
min_fret,
chart,
case(
"C#",
None,
indoc!("
[C# - C# major]
A ||---|---|---|-o-|- C#
E ||-o-|---|---|---|- F
C ||-o-|---|---|---|- C#
G ||-o-|---|---|---|- G#
A -|-o-|---|---|---|- C#
E -|-o-|---|---|---|- G#
C -|---|-o-|---|---|- F
G -|---|---|-o-|---|- C#
4
A -|---|---|-o-|---|- F
E -|---|---|---|-o-|- C#
C -|---|---|-o-|---|- G#
G -|-o-|---|---|---|- C#
6
A -|-o-|---|---|---|- F
E -|---|-o-|---|---|- C#
C -|-o-|---|---|---|- G#
G -|---|---|-o-|---|- F
8
A -|---|---|---|-o-|- G#
E -|---|-o-|---|---|- C#
C -|-o-|---|---|---|- G#
G -|---|---|-o-|---|- F
8
A -|---|-o-|---|---|- G#
E -|---|---|---|-o-|- F
C -|---|---|---|-o-|- C#
G -|-o-|---|---|---|- F
10
A -|-o-|---|---|---|- G#
E -|---|---|-o-|---|- F
C -|---|---|-o-|---|- C#
G -|---|---|-o-|---|- G#
11
")
),
case(
"C#",
Some("5"),
indoc!("
[C# - C# major]
A -|---|---|-o-|---|- F
E -|---|---|---|-o-|- C#
C -|---|---|-o-|---|- G#
G -|-o-|---|---|---|- C#
6
A -|-o-|---|---|---|- F
E -|---|-o-|---|---|- C#
C -|-o-|---|---|---|- G#
G -|---|---|-o-|---|- F
8
A -|---|---|---|-o-|- G#
E -|---|-o-|---|---|- C#
C -|-o-|---|---|---|- G#
G -|---|---|-o-|---|- F
8
A -|---|-o-|---|---|- G#
E -|---|---|---|-o-|- F
C -|---|---|---|-o-|- C#
G -|-o-|---|---|---|- F
10
A -|-o-|---|---|---|- G#
E -|---|---|-o-|---|- F
C -|---|---|-o-|---|- C#
G -|---|---|-o-|---|- G#
11
")
),
)]
fn test_all(
chord: &str,
min_fret: Option<&str>,
chart: &'static str,
) -> Result<(), Box<dyn std::error::Error + 'static>> {
let mut cmd = Command::cargo_bin("ukebox")?;
cmd.arg("chart").arg("--all");

if let Some(fret) = min_fret {
cmd.arg("--min-fret").arg(fret);
}

cmd.arg(chord);
cmd.assert().success().stdout(format!("{}\n", chart));

Ok(())
}

#[rstest(
chart,
names,
Expand Down

0 comments on commit 80c5af1

Please sign in to comment.