Skip to content

Commit

Permalink
Merge pull request #4 from petros/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
petros authored Aug 2, 2024
2 parents fe8bee4 + ff18fbf commit 0b52e89
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Install cargo-audit
run: cargo install cargo-audit
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Clippy
run: cargo clippy --verbose -- -D warnings
- name: Audit
run: cargo audit
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A command line utility written in Rust to help manage DragonRuby projects. This
### General help

```
$ drew --help
$ drem --help
Usage: drem [COMMAND]
Commands:
Expand All @@ -25,14 +25,14 @@ Options:
It will create a local copy of DRGTK and initialize a new game under it in a way that will make it easy to push to GitHub or elsewhere.

```
$ drew new --help
$ drem new --help
Create a new game
Usage: drem new --name <name> --drgtk <drgtk>
Options:
-n, --name <name> Name of the new game
-g, --drgtk <drgtk> Path to DRGTK zip to use
-d, --drgtk <drgtk> Path to DRGTK zip to use
-h, --help Print help
```

Expand Down
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ fn perform_new_command(drgtk: &PathBuf, name: String) -> Result<(), String> {
};
let outpath = file.mangled_name();

if (&*file.name()).starts_with("dragonruby-macos") {
if (*file.name()).starts_with("dragonruby-macos") {
let new_path =
Path::new(&directory).join(outpath.strip_prefix("dragonruby-macos").unwrap());

if (&*file.name()).ends_with('/') {
if (*file.name()).ends_with('/') {
std::fs::create_dir_all(&new_path).unwrap();
if new_path.ends_with("mygame/data")
|| new_path.ends_with("mygame/fonts")
Expand All @@ -80,10 +80,10 @@ fn perform_new_command(drgtk: &PathBuf, name: String) -> Result<(), String> {
} else {
if let Some(p) = new_path.parent() {
if !p.exists() {
std::fs::create_dir_all(&p).unwrap();
std::fs::create_dir_all(p).unwrap();
}
}
let mut outfile = std::fs::File::create(&new_path).unwrap();
let mut outfile = File::create(&new_path).unwrap();
std::io::copy(&mut file, &mut outfile).unwrap();
}
}
Expand All @@ -97,14 +97,14 @@ fn git_init(path: &Path) -> Result<(), git2::Error> {
Ok(())
}

fn build_new() -> Command {
fn build_new_subcommand() -> Command {
let name = Arg::new("name")
.short('n')
.long("name")
.required(true)
.help("Name of the new game");
let drgtk = Arg::new("drgtk")
.short('g')
.short('d')
.long("drgtk")
.required(true)
.value_parser(clap::value_parser!(PathBuf))
Expand All @@ -116,7 +116,7 @@ fn build_new() -> Command {
}

fn build_command() -> Command {
Command::new("drem").subcommand(build_new())
Command::new("drem").subcommand(build_new_subcommand())
}

fn main() {
Expand Down

0 comments on commit 0b52e89

Please sign in to comment.