Skip to content

Commit

Permalink
added possibility to download idf from master (#8)
Browse files Browse the repository at this point in the history
Co-authored-by: Petr Gadorek <[email protected]>
  • Loading branch information
Hahihula and Petr Gadorek authored Jul 10, 2024
1 parent 37c8840 commit 4267ad9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 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: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ please refer to the --help for information about cli usage

Download the executable for the suitable architecture.

it is recomanded to first run the `--help` command

Run it and proceed according to instruction in the terminal and you will have IDF installed.

for chinese run it with flag `-l=cn`
4 changes: 2 additions & 2 deletions src/cli_args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct Cli {

#[arg(
long,
help = "url for dowenload mirror to use instead of github.com for downloading esp-idf"
help = "url for download mirror to use instead of github.com for downloading esp-idf"
)]
idf_mirror: Option<String>,

Expand All @@ -79,7 +79,7 @@ pub struct Cli {
)]
verbose: u8,

#[arg(short, long, help = "Set the language for the wizard")]
#[arg(short, long, help = "Set the language for the wizard (en, cn)")]
locale: Option<String>,
}

Expand Down
24 changes: 18 additions & 6 deletions src/wizard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ async fn select_target(theme: &ColorfulTheme) -> Result<String, String> {
}

async fn select_idf_version(target: &str, theme: &ColorfulTheme) -> Result<String, String> {
let avalible_versions =
let mut avalible_versions =
idf_im_lib::idf_versions::get_idf_name_by_target(&target.to_string().to_lowercase()).await;

avalible_versions.push("master".to_string());
let selected_version = Select::with_theme(theme)
.with_prompt(t!("wizard.select_idf_version.prompt"))
.items(&avalible_versions)
Expand All @@ -99,7 +99,7 @@ async fn select_idf_version(target: &str, theme: &ColorfulTheme) -> Result<Strin
// println!("Selected IDF version {:?}", selected_target.to_string());
}

fn download_idf(path: &str, tag: &str, mirror: Option<&str>) -> Result<String, String> {
fn download_idf(path: &str, tag: Option<&str>, mirror: Option<&str>) -> Result<String, String> {
let _: Result<String, String> = match idf_im_lib::ensure_path(&path.to_string()) {
Ok(_) => Ok("ok".to_string()),
Err(err) => return Err(err.to_string()), // probably panic
Expand All @@ -118,7 +118,7 @@ fn download_idf(path: &str, tag: &str, mirror: Option<&str>) -> Result<String, S

let output = idf_im_lib::get_esp_idf_by_tag_name(
&path.to_string(),
&tag.to_string(),
tag,
|stats| {
let current_progress =
((stats.received_objects() as f64) / (stats.total_objects() as f64)) * 100.0;
Expand Down Expand Up @@ -408,7 +408,14 @@ pub async fn run_wizzard_run(mut config: Settings) -> Result<(), String> {
debug!("Selected target: {}", target);
// select version
if config.idf_version.is_none() {
config.idf_version = Some(select_idf_version(&target, &theme).await.unwrap());
let selected_idf_version = select_idf_version(&target, &theme).await;
match selected_idf_version {
Ok(selected_idf_version) => config.idf_version = Some(selected_idf_version),
Err(err) => {
error!("{:?}", err);
return Err(err);
}
}
}
let idf_versions = config.idf_version.unwrap();
debug!("Selected idf version: {}", idf_versions);
Expand Down Expand Up @@ -456,9 +463,14 @@ pub async fn run_wizzard_run(mut config: Settings) -> Result<(), String> {
}
};
// download idf
let tag = if idf_versions == "master" {
None
} else {
Some(idf_versions.clone())
};
match download_idf(
&idf_path.to_str().unwrap(),
&idf_versions,
tag.as_deref(),
Some(&idf_mirror),
) {
Ok(_) => {
Expand Down

0 comments on commit 4267ad9

Please sign in to comment.