Skip to content

Commit

Permalink
Fix clippy warnings (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Pruitt authored Jan 18, 2022
1 parent 46c6ab8 commit f9069d9
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 85 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased
# Version 0.4.0

* Add support for DragonRuby versions > 3
* Display identifier in `smaug dragonruby list` for easier uninstall

# Version 0.3.2

Expand Down
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ scoop install smaug
# Usage

```
smaug 0.3.2
smaug 0.4.0
Matt Pruitt <matt@guitsaru.com>
Create games and share packages with the DragonRuby community
Expand Down
8 changes: 4 additions & 4 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "smaug-cli"
version = "0.3.2"
version = "0.4.0"
authors = ["Matt Pruitt <matt@guitsaru.com>"]
edition = "2018"

Expand All @@ -12,16 +12,16 @@ path = "src/main.rs"


[dependencies]
smaug = { path="../smaug" }
smaug = { path = "../smaug" }

clap = "3.0.0-beta.2"
derive_more = "0.99.11"
log = "0.4"
open = "1.7.0"
question = "0.2.2"
reqwest = { version="0.11", features=["blocking", "json"] }
reqwest = { version = "0.11", features = ["blocking", "json"] }
rm_rf = "0.6.1"
serde = { version="1.0", features=["derive"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
stderrlog = "0.5"
tinytemplate = "1.1"
Expand Down
8 changes: 4 additions & 4 deletions cli/src/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ pub enum Error {
#[display(fmt = "{} has already been added to this project.", "name")]
AlreadyAdded { name: String },
#[display(fmt = "Could not fetch from registry.")]
RegistryError,
Registry,
#[display(fmt = "Could not install packages.")]
InstallError,
Install,
}

#[derive(Debug, Display, Serialize)]
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Command for Add {
let package_name = matches.value_of("PACKAGE").expect("No package given");
let latest_version = match fetch_from_registry(package_name.to_string()) {
Ok(version) => version,
Err(..) => return Err(Box::new(Error::RegistryError)),
Err(..) => return Err(Box::new(Error::Registry)),
};

trace!("Latest version: {}", latest_version);
Expand All @@ -93,7 +93,7 @@ impl Command for Add {
.expect("Couldn't write config file.");

if Install.run(matches).is_err() {
return Err(Box::new(Error::InstallError));
return Err(Box::new(Error::Install));
}

Ok(Box::new(AddResult {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum Error {
#[display(fmt = "The bind command is only available for DragonRuby pro.")]
DragonRubyNotPro,
#[display(fmt = "Couldn't load Smaug configuration.")]
ConfigError { path: PathBuf },
Config { path: PathBuf },
#[display(fmt = "Could not find file at {}", "path.display()")]
FileNotFound { path: PathBuf },
}
Expand Down Expand Up @@ -59,7 +59,7 @@ impl Command for Bind {

let config = match smaug::config::load(&config_path) {
Ok(config) => config,
Err(..) => return Err(Box::new(Error::ConfigError { path: config_path })),
Err(..) => return Err(Box::new(Error::Config { path: config_path })),
};

debug!("Smaug config: {:?}", config);
Expand Down
28 changes: 18 additions & 10 deletions cli/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ pub enum Error {
)]
ConfiguredDragonRubyNotFound,
#[display(fmt = "Couldn't load Smaug configuration.")]
ConfigError { path: PathBuf },
Config { path: PathBuf },
#[display(fmt = "Could not find file at {}", "path.display()")]
FileNotFound { path: PathBuf },
#[display(fmt = "Building {} failed", "project_name")]
BuildError { project_name: String },
Build { project_name: String },
}

impl Command for Build {
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Command for Build {

let config = match smaug::config::load(&config_path) {
Ok(conf) => conf,
Err(..) => return Err(Box::new(Error::ConfigError { path: config_path })),
Err(..) => return Err(Box::new(Error::Config { path: config_path })),
};
debug!("Smaug config: {:?}", config);

Expand All @@ -78,9 +78,16 @@ impl Command for Build {
Some(dragonruby) => {
let bin_dir = dragonruby.install_dir();
let build_dir = bin_dir.join(path.file_name().unwrap());
let builds_directory = &bin_dir.join("builds");

copy_directory(&path, &build_dir).expect("Could not copy to build directory.");
debug!("Build Directory: {:?}", build_dir);
trace!("Cleaning build directory");
rm_rf::ensure_removed(&build_dir).expect("couldn't clean build directory");
trace!("Cleaning builds directory");
rm_rf::ensure_removed(&builds_directory).expect("couldn't clean build directory");

copy_directory(&path, build_dir.clone())
.expect("Could not copy to build directory.");

let log_dir = build_dir.join("logs");
let exception_dir = build_dir.join("exceptions");
Expand Down Expand Up @@ -118,25 +125,26 @@ impl Command for Build {
.wait()
.unwrap();

copy_directory(&bin_dir.join("builds"), &path.join("builds"))
let local_builds_dir = path.join("builds");
copy_directory(&builds_directory, &local_builds_dir)
.expect("Could not copy builds.");

rm_rf::ensure_removed(build_dir).expect("Could not clean up build dir");

let local_log_dir = &path.join("logs");
let local_log_dir = path.join("logs");
rm_rf::ensure_removed(&local_log_dir).expect("Couldn't remove local logs");

let local_exception_dir = &path.join("exceptions");
let local_exception_dir = path.join("exceptions");
rm_rf::ensure_removed(&local_exception_dir)
.expect("Couldn't remove local exceptions");

if log_dir.is_dir() {
smaug::util::dir::copy_directory(&log_dir, &local_log_dir)
smaug::util::dir::copy_directory(&log_dir, local_log_dir)
.expect("couldn't copy logs");
}

if exception_dir.is_dir() {
smaug::util::dir::copy_directory(&exception_dir, &local_exception_dir)
smaug::util::dir::copy_directory(&exception_dir, local_exception_dir)
.expect("couldn't copy exceptions");
}

Expand All @@ -145,7 +153,7 @@ impl Command for Build {
project_name: config.project.unwrap().name,
}))
} else {
Err(Box::new(Error::BuildError {
Err(Box::new(Error::Build {
project_name: config.project.unwrap().name,
}))
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::path::PathBuf;
pub struct Config;

#[derive(Debug, Serialize, Display)]
#[display(fmt = "{}", "print_config(&config)")]
#[display(fmt = "{}", "print_config(config)")]
pub struct ConfigResult {
config: toml::Value,
}
Expand Down
6 changes: 3 additions & 3 deletions cli/src/commands/dragonruby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ impl Command for DragonRuby {
.unwrap();

match matches.subcommand_name() {
Some("install") => Install.run(&subcommand_matches),
Some("list") => List.run(&subcommand_matches),
Some("uninstall") => Uninstall.run(&subcommand_matches),
Some("install") => Install.run(subcommand_matches),
Some("list") => List.run(subcommand_matches),
Some("uninstall") => Uninstall.run(subcommand_matches),
_ => unreachable!(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/dragonruby/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn install(dr: &DragonRuby) -> io::Result<DragonRuby> {
destination.display()
);

copy_directory(&source, &destination)?;
copy_directory(&source, destination.clone())?;

let dr = dragonruby::new(&destination).expect("Could not find DragonRuby");

Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn install_files(resolver: &Resolver) -> std::io::Result<()> {
let source = install.from.as_path();
let destination = install.to.as_path();

if can_install_file(&source, &destination) {
if can_install_file(source, destination) {
trace!(
"Copying file from {} to {}",
source.display(),
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Command for New {
let path = Path::new(directory);

let source = latest.install_dir().join("mygame");
smaug::util::dir::copy_directory(&source, &path.to_path_buf())
smaug::util::dir::copy_directory(&source, path.to_path_buf())
.expect("Installed DragonRuby doesn't have mygame directory.");

let gitignore = include_str!("../../templates/gitignore.template");
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Command for Package {
let subcommand_matches = matches.subcommand_matches(matches.subcommand_name().unwrap());

match matches.subcommand_name() {
Some("init") => init::Init.run(&subcommand_matches.unwrap()),
Some("init") => init::Init.run(subcommand_matches.unwrap()),
_ => unreachable!(),
}
}
Expand Down
21 changes: 11 additions & 10 deletions cli/src/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ pub enum Error {
)]
ConfiguredDragonRubyNotFound,
#[display(fmt = "Couldn't load Smaug configuration.")]
ConfigError { path: PathBuf },
Config { path: PathBuf },
#[display(fmt = "Publishing {} failed", "project_name")]
PublishError { project_name: String },
Publish { project_name: String },
}

impl Command for Publish {
Expand All @@ -54,7 +54,7 @@ impl Command for Publish {

let config = match smaug::config::load(&config_path) {
Ok(config) => config,
Err(..) => return Err(Box::new(Error::ConfigError { path: config_path })),
Err(..) => return Err(Box::new(Error::Config { path: config_path })),
};

debug!("Smaug config: {:?}", config);
Expand All @@ -73,7 +73,8 @@ impl Command for Publish {
let bin_dir = dragonruby.install_dir();
let build_dir = bin_dir.join(path.file_name().unwrap());

copy_directory(&path, &build_dir).expect("Could not copy to build directory.");
copy_directory(&path, build_dir.clone())
.expect("Could not copy to build directory.");

let log_dir = build_dir.join("logs");
let exception_dir = build_dir.join("exceptions");
Expand Down Expand Up @@ -108,23 +109,23 @@ impl Command for Publish {
.wait()
.unwrap();

copy_directory(&bin_dir.join("builds"), &path.join("builds"))
copy_directory(&bin_dir.join("builds"), path.join("builds"))
.expect("Could not copy builds.");

let local_log_dir = &path.join("logs");
let local_log_dir = path.join("logs");
rm_rf::ensure_removed(&local_log_dir).expect("Couldn't remove local logs");

let local_exception_dir = &path.join("exceptions");
let local_exception_dir = path.join("exceptions");
rm_rf::ensure_removed(&local_exception_dir)
.expect("Couldn't remove local exceptions");

if log_dir.is_dir() {
smaug::util::dir::copy_directory(&log_dir, &local_log_dir)
smaug::util::dir::copy_directory(&log_dir, local_log_dir)
.expect("couldn't copy logs");
}

if exception_dir.is_dir() {
smaug::util::dir::copy_directory(&exception_dir, &local_exception_dir)
smaug::util::dir::copy_directory(&exception_dir, local_exception_dir)
.expect("couldn't copy exceptions");
}

Expand All @@ -135,7 +136,7 @@ impl Command for Publish {
project_name: config.project.unwrap().name,
}))
} else {
Err(Box::new(Error::PublishError {
Err(Box::new(Error::Publish {
project_name: config.project.unwrap().name,
}))
}
Expand Down
16 changes: 8 additions & 8 deletions cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ pub enum Error {
)]
ConfiguredDragonRubyNotFound,
#[display(fmt = "Couldn't load Smaug configuration.")]
ConfigError { path: PathBuf },
Config { path: PathBuf },
#[display(
fmt = "{} crashed look at the logs for more information",
"project_name"
)]
RunError { project_name: String },
Run { project_name: String },
}

impl Command for Run {
Expand All @@ -58,7 +58,7 @@ impl Command for Run {

let config = match smaug::config::load(&config_path) {
Ok(config) => config,
Err(..) => return Err(Box::new(Error::ConfigError { path: config_path })),
Err(..) => return Err(Box::new(Error::Config { path: config_path })),
};
debug!("Smaug config: {:?}", config);

Expand Down Expand Up @@ -116,20 +116,20 @@ impl Command for Run {
.wait()
.unwrap();

let local_log_dir = &path.join("logs");
let local_log_dir = path.join("logs");
rm_rf::ensure_removed(&local_log_dir).expect("Couldn't remove local logs");

let local_exception_dir = &path.join("exceptions");
let local_exception_dir = path.join("exceptions");
rm_rf::ensure_removed(&local_exception_dir)
.expect("Couldn't remove local exceptions");

if log_dir.is_dir() {
smaug::util::dir::copy_directory(&log_dir, &local_log_dir)
smaug::util::dir::copy_directory(&log_dir, local_log_dir)
.expect("couldn't copy logs");
}

if exception_dir.is_dir() {
smaug::util::dir::copy_directory(&exception_dir, &local_exception_dir)
smaug::util::dir::copy_directory(&exception_dir, local_exception_dir)
.expect("couldn't copy exceptions");
}

Expand All @@ -138,7 +138,7 @@ impl Command for Run {
project_name: config.project.unwrap().name,
}))
} else {
Err(Box::new(Error::RunError {
Err(Box::new(Error::Run {
project_name: config.project.unwrap().name,
}))
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/game_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn from_config(config: &Config) -> GameMetadata {
.clone()
.expect("Smaug.toml is not a project configuration");
GameMetadata {
devid: devid(&config),
devid: devid(config),
devtitle: project.authors.join(" "),
gameid: project.name,
gametitle: project.title,
Expand Down
Loading

0 comments on commit f9069d9

Please sign in to comment.