Skip to content

Commit

Permalink
run cargo fmt and fix most clippy warnings
Browse files Browse the repository at this point in the history
the code before had a horrible mix of spaces and tabs everywhere, even
on the same line!!!! so now use tabs for everything since that seemed to
be the dominant indentation style

also change some of the code as suggested by clippy
  • Loading branch information
matcool committed Oct 16, 2022
1 parent 3de365e commit 2980a3f
Show file tree
Hide file tree
Showing 18 changed files with 845 additions and 659 deletions.
2 changes: 1 addition & 1 deletion 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "geode"
version = "1.0.6"
version = "1.0.7"
authors = ["HJfod <[email protected]>", "Camila314 <[email protected]>"]
edition = "2021"
build = "build.rs"
Expand Down
15 changes: 9 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#[cfg(windows)] extern crate winres;
#[cfg(windows)]
extern crate winres;

fn main() {
#[cfg(windows)] {
let mut res = winres::WindowsResource::new();
res.set_icon("geode.ico");
res.compile().unwrap();
}
#[cfg(windows)]
{
let mut res = winres::WindowsResource::new();
res.set_icon("geode.ico");
res.compile().unwrap();
}
}
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hard_tabs = true
78 changes: 38 additions & 40 deletions src/info.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::cell::RefCell;
use std::io::BufRead;
/**
* geode info
*/
use std::path::{PathBuf};
use crate::config::Config;
use crate::util::config::Profile;
use crate::{fail, done, info};
use crate::NiceUnwrap;
use colored::Colorize;
use crate::{done, fail, info};
use clap::Subcommand;
use colored::Colorize;
use std::cell::RefCell;
use std::io::BufRead;
/**
* geode info
*/
use std::path::PathBuf;

#[derive(Subcommand, Debug)]
pub enum Info {
Expand All @@ -19,7 +19,7 @@ pub enum Info {
field: String,

/// New value
value: String
value: String,
},

/// Get value
Expand All @@ -29,21 +29,17 @@ pub enum Info {

/// Output raw value
#[clap(long)]
raw: bool
raw: bool,
},

/// List possible values
List,

/// Setup config (if you have manually installed Geode)
Setup {},
}

const CONFIGURABLES: [&str; 3] = [
"default-developer",
"sdk-path",
"sdk-nightly"
];
const CONFIGURABLES: [&str; 3] = ["default-developer", "sdk-path", "sdk-nightly"];

fn get_bool(value: &str) -> Option<bool> {
let lower = value.to_ascii_lowercase();
Expand All @@ -65,15 +61,15 @@ pub fn subcommand(config: &mut Config, cmd: Info) {
if field == "default-developer" {
config.default_developer = Some(value);
} else if field == "sdk-nightly" {
config.sdk_nightly = get_bool(&value)
.nice_unwrap(format!("'{}' cannot be parsed as a bool", value));
config.sdk_nightly =
get_bool(&value).nice_unwrap(format!("'{}' cannot be parsed as a bool", value));
} else {
fail!("Unknown field {}", field);
return;
}

done!("{}", done_str);
},
}

Info::Get { field, raw } => {
let sdk_path;
Expand All @@ -89,42 +85,40 @@ pub fn subcommand(config: &mut Config, cmd: Info) {
} else {
"false"
}
} else if raw {
std::process::exit(1);
} else {
if raw {
std::process::exit(1);
} else {
fail!("Unknown field {}", field);
return;
}
fail!("Unknown field {}", field);
return;
};

if raw {
print!("{}", out);
} else {
println!("{} = {}", field.bright_cyan(), out.bright_green());
}
},
}

Info::List => {
for i in CONFIGURABLES {
println!("{}", i);
}
},
}

Info::Setup {} => {
if config.profiles.is_empty() {
info!("Please enter the path to the Geometry Dash folder:");

let path = loop {
let mut buf = String::new();
match std::io::stdin().lock().read_line(&mut buf) {
Ok(_) => {},
Ok(_) => {}
Err(e) => {
fail!("Unable to read input: {}", e);
continue;
}
};

// Verify path is valid
let path = PathBuf::from(buf.trim());
if !path.is_dir() {
Expand All @@ -134,11 +128,15 @@ pub fn subcommand(config: &mut Config, cmd: Info) {
);
continue;
}
if path.read_dir().map(|mut files| files.next().is_none()).unwrap_or(false) {
if path
.read_dir()
.map(|mut files| files.next().is_none())
.unwrap_or(false)
{
fail!("Given path appears to be empty");
continue;
}
// todo: maybe do some checksum verification
// todo: maybe do some checksum verification
// to make sure GD 2.113 is in the folder
break path;
};
Expand All @@ -148,20 +146,20 @@ pub fn subcommand(config: &mut Config, cmd: Info) {
let mut buf = String::new();
match std::io::stdin().lock().read_line(&mut buf) {
Ok(_) => break buf,
Err(e) => fail!("Unable to read input: {}", e)
Err(e) => fail!("Unable to read input: {}", e),
};
};
config.profiles.push(RefCell::new(
Profile::new(name.trim().into(), path)
));

config
.profiles
.push(RefCell::new(Profile::new(name.trim().into(), path)));
config.current_profile = Some(name.trim().into());
done!("Profile added");
}

config.sdk_nightly = Config::sdk_path().join("bin/nightly").exists();

done!("Config setup finished");
},
}
}
}
}
117 changes: 58 additions & 59 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use clap::{Parser, Subcommand};
/**
* geode new: Create new geode project from template
* geode info: Subcommand for listing information about the current state
Expand All @@ -7,88 +8,86 @@
* geode install: alias of `geode package install`
*/
use std::path::PathBuf;
use clap::{Parser, Subcommand};

mod util;
mod template;
mod info;
mod package;
mod profile;
mod info;
mod sdk;
mod template;
mod util;

use util::*;

/// Command-line interface for Geode
#[derive(Parser, Debug)]
#[clap(version)]
struct Args {
#[clap(subcommand)]
command: GeodeCommands
#[clap(subcommand)]
command: GeodeCommands,
}

#[derive(Subcommand, Debug)]
enum GeodeCommands {
/// Create template mod project
New {
/// Mod project directory
#[clap(short, long)]
path: Option<PathBuf>,

/// Mod name
#[clap(short, long)]
name: Option<String>
},

/// Install a .geode package to current profile, alias of `geode package install`
Install {
/// Location of the .geode package to install
path: PathBuf
},

/// Subcommand for managing profiles
Profile {
#[clap(subcommand)]
commands: crate::profile::Profile
},

/// Subcommand for managing configurable data
Config {
#[clap(subcommand)]
commands: crate::info::Info
},

/// Subcommand for managing the Geode SDK
Sdk {
#[clap(subcommand)]
commands: crate::sdk::Sdk
},

/// Subcommand for managing Geode packages
Package {
#[clap(subcommand)]
commands: crate::package::Package
}
/// Create template mod project
New {
/// Mod project directory
#[clap(short, long)]
path: Option<PathBuf>,

/// Mod name
#[clap(short, long)]
name: Option<String>,
},

/// Install a .geode package to current profile, alias of `geode package install`
Install {
/// Location of the .geode package to install
path: PathBuf,
},

/// Subcommand for managing profiles
Profile {
#[clap(subcommand)]
commands: crate::profile::Profile,
},

/// Subcommand for managing configurable data
Config {
#[clap(subcommand)]
commands: crate::info::Info,
},

/// Subcommand for managing the Geode SDK
Sdk {
#[clap(subcommand)]
commands: crate::sdk::Sdk,
},

/// Subcommand for managing Geode packages
Package {
#[clap(subcommand)]
commands: crate::package::Package,
},
}


fn main() {
let args = Args::parse();
let args = Args::parse();

let mut config = config::Config::new();

let mut config = config::Config::new();
match args.command {
GeodeCommands::New { name, path } => template::build_template(&mut config, name, path),

match args.command {
GeodeCommands::New { name, path} => template::build_template(&mut config, name, path),

GeodeCommands::Install { path } => package::install(&mut config, &path),
GeodeCommands::Install { path } => package::install(&mut config, &path),

GeodeCommands::Profile { commands } => profile::subcommand(&mut config, commands),
GeodeCommands::Profile { commands } => profile::subcommand(&mut config, commands),

GeodeCommands::Config { commands } => info::subcommand(&mut config, commands),
GeodeCommands::Config { commands } => info::subcommand(&mut config, commands),

GeodeCommands::Sdk { commands } => sdk::subcommand(&mut config, commands),
GeodeCommands::Sdk { commands } => sdk::subcommand(&mut config, commands),

GeodeCommands::Package { commands } => package::subcommand(&mut config, commands),
}
GeodeCommands::Package { commands } => package::subcommand(&mut config, commands),
}

config.save();
config.save();
}
Loading

0 comments on commit 2980a3f

Please sign in to comment.