Skip to content

Commit

Permalink
feat: impl build command
Browse files Browse the repository at this point in the history
  • Loading branch information
SyedAhkam committed Aug 10, 2023
1 parent da92c6f commit 0c242a9
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ path = "src/main.rs"
clap = { version = "3.2.23", features = ["default", "derive"] }
guidon = "0.4.1"
env_logger = "0.10.0"
dialoguer = "0.10.4"
dialoguer = "0.10.4"
which = "4.4.0"
37 changes: 37 additions & 0 deletions src/commands/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::process::Command;

use clap::{
Parser,
ArgAction
};

use crate::utils::find_gradle;

#[derive(Parser, Debug)]
pub struct Build {
/// Should build in release mode
#[clap(short, long, default_value="false", action = ArgAction::SetTrue)]
release: bool
}

pub fn handle(args: Build) {
let gradle_path = find_gradle().expect("ERROR: Gradle not found on system");

// Decide gradle subcommand to use
let cmd = match args.release {
true => "assembleRelease",
false => "assembleDebug"
};

// Invoke gradle as child process
println!("Invoking Gradle: {}", gradle_path);
let status = Command::new(gradle_path)
.arg(cmd)
.status()
.unwrap();

match status.success() {
true => println!("Success!"),
false => println!("Failed while executing Gradle.")
}
}
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod create;
pub mod build;
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct Cli {
#[derive(Subcommand, Debug)]
enum SubCommand {
Create(commands::create::Create),
Build(commands::build::Build)
}

fn main() {
Expand All @@ -26,5 +27,6 @@ fn main() {

match args.command {
SubCommand::Create(args) => commands::create::handle(args),
SubCommand::Build(args) => commands::build::handle(args)
}
}
14 changes: 14 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
use which::which;

pub fn prompt_for_input(prompt: &str) -> String {
dialoguer::Input::<String>::with_theme(&dialoguer::theme::ColorfulTheme::default())
.with_prompt(prompt)
.interact_text()
.unwrap()
}

pub fn find_gradle() -> Option<String> {
if std::path::Path::new("./gradlew").exists() {
return Some("./gradlew".to_owned());
}

if which("gradle").is_ok() {
return Some("gradle".to_owned());
}

None
}

0 comments on commit 0c242a9

Please sign in to comment.