From 85a32cd50c5bb4ec0b4a093d58a2b93ea38ba832 Mon Sep 17 00:00:00 2001 From: siddhantCodes Date: Tue, 31 Oct 2023 13:04:51 +0530 Subject: [PATCH] fix: fastn -c fastn_core_commands should do nothing in case of no subcommand --- fastn/src/main.rs | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/fastn/src/main.rs b/fastn/src/main.rs index ffc73481d8..8249612fcc 100644 --- a/fastn/src/main.rs +++ b/fastn/src/main.rs @@ -39,15 +39,7 @@ async fn async_main() -> Result<(), Error> { check_for_update_cmd(&matches) )?; - match std::env::var("FASTN_CHECK_FOR_UPDATES") { - Ok(val) => { - if val != "false" && !matches.get_flag("check-for-updates") { - check_for_update(false).await?; - } - Ok(()) - } - Err(_) => Ok(()), - } + Ok(()) } async fn cloud_commands(matches: &clap::ArgMatches) -> Result { @@ -61,6 +53,10 @@ async fn fastn_core_commands(matches: &clap::ArgMatches) -> fastn_core::Result<( use colored::Colorize; use fastn_core::utils::ValueOf; + if matches.subcommand_name().is_none() { + return Ok(()); + } + match matches.subcommand() { Some((fastn_core::commands::stop_tracking::COMMAND, matches)) => { return fastn_core::commands::stop_tracking::handle_command(matches).await; @@ -274,16 +270,23 @@ async fn fastn_core_commands(matches: &clap::ArgMatches) -> fastn_core::Result<( return fastn_core::post_build_check(&config).await; } - if matches.get_flag("check-for-updates") { - return check_for_update(true).await; - } - - unreachable!("No subcommand matched"); + Ok(()) } async fn check_for_update_cmd(matches: &clap::ArgMatches) -> fastn_core::Result<()> { - if matches.get_flag("check-for-updates") { - check_for_update(false).await?; + let env_var_set = { + if let Ok(val) = std::env::var("FASTN_CHECK_FOR_UPDATES") { + val != "false" + } else { + false + } + }; + + let flag = matches.get_flag("check-for-updates"); + + // if the env var is set or the -c flag is passed then check for updates + if flag || env_var_set { + check_for_update(flag).await?; } Ok(()) @@ -313,6 +316,7 @@ async fn check_for_update(report: bool) -> fastn_core::Result<()> { current_version, release.tag_name ); } else if report { + // log only when -c is passed println!("You are using the latest release of fastn."); } @@ -322,11 +326,11 @@ async fn check_for_update(report: bool) -> fastn_core::Result<()> { fn app(version: &'static str) -> clap::Command { clap::Command::new("fastn: Full-stack Web Development Made Easy") .version(version) - .arg(clap::arg!(-c --"check-for-updates" "Check for updates")) .arg_required_else_help(true) .arg(clap::arg!(verbose: -v "Sets the level of verbosity")) .arg(clap::arg!(--test "Runs the command in test mode").hide(true)) .arg(clap::arg!(--trace "Activate tracing").hide(true)) + .arg(clap::arg!(-c --"check-for-updates" "Check for updates")) .subcommand( // Initial subcommand format // fastn create-package [project-path]