Skip to content

Commit

Permalink
Clean up main a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebraham committed Oct 31, 2024
1 parent 7e63302 commit 8c51061
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{
env,
error::Error,
fs,
path::{Path, PathBuf},
process,
process::{self, Command},
};

use clap::Parser;
Expand Down Expand Up @@ -33,6 +34,7 @@ pub enum GeneratorOptionItem {
Category(GeneratorOptionCategory),
Option(GeneratorOption),
}

impl GeneratorOptionItem {
fn title(&self) -> String {
match self {
Expand Down Expand Up @@ -185,7 +187,7 @@ struct Args {
output_path: Option<PathBuf>,
}

fn main() {
fn main() -> Result<(), Box<dyn Error>> {
Builder::from_env(Env::default().default_filter_or(log::LevelFilter::Info.as_str()))
.format_target(false)
.init();
Expand Down Expand Up @@ -214,12 +216,12 @@ fn main() {
let repository = tui::Repository::new(args.chip, OPTIONS, &args.option);

// TUI stuff ahead
let terminal = tui::init_terminal().unwrap();
let terminal = tui::init_terminal()?;

// create app and run it
let selected = tui::App::new(repository).run(terminal).unwrap();
let selected = tui::App::new(repository).run(terminal)?;

tui::restore_terminal().unwrap();
tui::restore_terminal()?;
// done with the TUI

if let Some(selected) = selected {
Expand Down Expand Up @@ -266,28 +268,30 @@ fn main() {
}
}

// Run cargo fmt
process::Command::new("cargo")
.arg("fmt")
.arg("--")
.arg("--config")
.arg("group_imports=StdExternalCrate")
.arg("--config")
.arg("imports_granularity=Module")
.current_dir(&dir)
.output()
.unwrap();

if should_initialize_git_repo(&dir) {
// Run git init
process::Command::new("git")
// Run cargo fmt:
Command::new("cargo")
.args([
"fmt",
"--",
"--config",
"group_imports=StdExternalCrate",
"--config",
"imports_granularity=Module",
])
.current_dir(&project_dir)
.output()?;

if should_initialize_git_repo(&project_dir) {
// Run git init:
Command::new("git")
.arg("init")
.current_dir(&dir)
.output()
.unwrap();
.current_dir(&project_dir)
.output()?;
} else {
log::warn!("Current directory is already in a git repository, skipping git initialization");
}

Ok(())
}

fn process_file(
Expand Down

0 comments on commit 8c51061

Please sign in to comment.