summaryrefslogtreecommitdiffstats
path: root/src/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/mod.rs17
-rw-r--r--src/cmd/recommend.rs53
-rw-r--r--src/cmd/sql.rs9
-rw-r--r--src/cmd/sync.rs7
4 files changed, 51 insertions, 35 deletions
diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs
index 021bc48..68ae2fb 100644
--- a/src/cmd/mod.rs
+++ b/src/cmd/mod.rs
@@ -1,6 +1,6 @@
+mod recommend;
mod sql;
mod sync;
-mod recommend;
const _DUMMY_DEPENDENCY: &'static str = include_str!("../../Cargo.toml");
@@ -18,16 +18,19 @@ fn get_command() -> failure::Fallible<Box<Command>> {
sql::subcommand(),
recommend::subcommand(),
];
- let mut app = app_from_crate!()
- .subcommands(subcommands.into_iter().map(|s| {
- s.setting(clap::AppSettings::DisableVersion)
- }));
+ let mut app = app_from_crate!().subcommands(
+ subcommands
+ .into_iter()
+ .map(|s| s.setting(clap::AppSettings::DisableVersion)),
+ );
let matches = app.clone().get_matches();
let command: Box<Command> = match matches.subcommand() {
("sync", Some(matches)) => Box::new(sync::Command::new(matches)),
("sql", Some(matches)) => Box::new(sql::Command::new(matches)),
- ("recommend", Some(matches)) => Box::new(recommend::Command::new(matches)?),
+ ("recommend", Some(matches)) => {
+ Box::new(recommend::Command::new(matches)?)
+ }
(name, Some(_)) => bail!("unknown subcommand: {}", name),
(_, None) => {
@@ -35,7 +38,7 @@ fn get_command() -> failure::Fallible<Box<Command>> {
app.write_long_help(&mut stderr)?;
eprintln!("");
bail!("no subcommand given")
- },
+ }
};
Ok(command)
diff --git a/src/cmd/recommend.rs b/src/cmd/recommend.rs
index 2f613fa..1d8eecc 100644
--- a/src/cmd/recommend.rs
+++ b/src/cmd/recommend.rs
@@ -19,40 +19,48 @@ pub fn subcommand<'a, 'b>() -> clap::App<'a, 'b> {
.arg(
clap::Arg::with_name("count")
.default_value("20")
- .help("number of results to return")
+ .help("number of results to return"),
)
.arg(
clap::Arg::with_name("random")
.long("random")
- .help("picks randomly instead of by weight")
+ .help("picks randomly instead of by weight"),
)
.arg(
clap::Arg::with_name("album")
.long("album")
- .help("also choose a random album by the chosen artists")
+ .help("also choose a random album by the chosen artists"),
)
.arg(
clap::Arg::with_name("include")
.long("include")
.default_value("yearly")
- .possible_values(&["all", "yearly", "monthly", "weekly"])
+ .possible_values(&["all", "yearly", "monthly", "weekly"]),
)
.arg(
clap::Arg::with_name("exclude")
.long("exclude")
.default_value("weekly")
- .possible_values(&["all", "yearly", "monthly", "weekly", "none"])
+ .possible_values(&[
+ "all", "yearly", "monthly", "weekly", "none",
+ ]),
)
}
impl Command {
- pub fn new<'a>(matches: &clap::ArgMatches<'a>) -> failure::Fallible<Command> {
+ pub fn new<'a>(
+ matches: &clap::ArgMatches<'a>,
+ ) -> failure::Fallible<Command> {
Ok(Command {
count: matches.value_of("count").unwrap().parse()?,
random: matches.is_present("random"),
album: matches.is_present("album"),
- include: db::parse_timewindow(matches.value_of("include").unwrap()),
- exclude: db::parse_timewindow(matches.value_of("exclude").unwrap()),
+ include: db::parse_timewindow(
+ matches.value_of("include").unwrap(),
+ ),
+ exclude: db::parse_timewindow(
+ matches.value_of("exclude").unwrap(),
+ ),
db: db::DB::new(&util::db_path()?)?,
})
@@ -65,21 +73,24 @@ impl super::Command for Command {
self.count,
self.random,
self.include,
- self.exclude
+ self.exclude,
)?;
if self.album {
- artists = artists.iter().map(|artist| {
- Ok(format!(
- "{} - {}",
- artist,
- self.db.recommend_album(
- &artist,
- self.random,
- self.include,
- self.exclude
- )?
- ))
- }).collect::<failure::Fallible<Vec<String>>>()?;
+ artists = artists
+ .iter()
+ .map(|artist| {
+ Ok(format!(
+ "{} - {}",
+ artist,
+ self.db.recommend_album(
+ &artist,
+ self.random,
+ self.include,
+ self.exclude
+ )?
+ ))
+ })
+ .collect::<failure::Fallible<Vec<String>>>()?;
}
for line in artists {
println!("{}", line);
diff --git a/src/cmd/sql.rs b/src/cmd/sql.rs
index 81fdaef..404c97e 100644
--- a/src/cmd/sql.rs
+++ b/src/cmd/sql.rs
@@ -14,12 +14,12 @@ pub fn subcommand<'a, 'b>() -> clap::App<'a, 'b> {
.arg(
clap::Arg::with_name("query")
.required(true)
- .help("query to run")
+ .help("query to run"),
)
.arg(
clap::Arg::with_name("tsv")
.long("tsv")
- .help("format output as tsv")
+ .help("format output as tsv"),
)
}
@@ -47,8 +47,7 @@ impl super::Command for Command {
if self.tsv {
print_tsv(&rows);
- }
- else {
+ } else {
print_table(&cols, &rows);
}
@@ -100,7 +99,7 @@ fn print_row(widths: &[usize], row: &[String]) {
let fixed_width_row: Vec<String> = row
.iter()
.zip(widths.iter())
- .map(|(s, width)| format!("{:width$}", s, width=width))
+ .map(|(s, width)| format!("{:width$}", s, width = width))
.collect();
println!("{}", &fixed_width_row.join(" | "));
}
diff --git a/src/cmd/sync.rs b/src/cmd/sync.rs
index 99e39f7..b6019c4 100644
--- a/src/cmd/sync.rs
+++ b/src/cmd/sync.rs
@@ -14,7 +14,7 @@ pub fn subcommand<'a, 'b>() -> clap::App<'a, 'b> {
.arg(
clap::Arg::with_name("username")
.required(true)
- .help("last.fm username to fetch tracks for")
+ .help("last.fm username to fetch tracks for"),
)
}
@@ -39,7 +39,10 @@ impl super::Command for Command {
bar.set_style(
indicatif::ProgressStyle::default_bar()
.progress_chars("=> ")
- .template("Downloading {pos}/{len} tracks...\n{percent:>3}% [{wide_bar}] {eta:5}")
+ .template(
+ "Downloading {pos}/{len} tracks...\n\
+ {percent:>3}% [{wide_bar}] {eta:5}",
+ ),
);
db.insert_tracks(bar.wrap_iter(lastfm.tracks(from)))?;