From 96f6721443bb5d93158b37a1d0f37c6925130e71 Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Thu, 12 Nov 2020 15:51:09 +0530 Subject: [PATCH 01/15] added utility funciton required_value_of and refactored Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 332 +++++++++++++++++++------------------ 1 file changed, 175 insertions(+), 157 deletions(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index 075a1b1434..80595b1970 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -535,7 +535,7 @@ async fn start(ui: &mut UI, feature_flags: FeatureFlag) -> Result<()> { } fn sub_cli_setup(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let key_cache = key_cache_from_matches(&m)?; + let key_cache = key_cache_from_matches(m)?; init()?; command::cli::setup::start(ui, &key_cache) @@ -555,13 +555,13 @@ fn sub_cli_completers(m: &ArgMatches<'_>, feature_flags: FeatureFlag) -> Result< } async fn sub_origin_key_download(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let origin = m.value_of("ORIGIN").unwrap().parse()?; // Required via clap + let origin = required_value_of(m, "ORIGIN").parse()?; let revision = m.value_of("REVISION"); let with_secret = m.is_present("WITH_SECRET"); let with_encryption = m.is_present("WITH_ENCRYPTION"); - let token = maybe_auth_token(&m); - let url = bldr_url_from_matches(&m)?; - let key_cache = key_cache_from_matches(&m)?; + let token = maybe_auth_token(m); + let url = bldr_url_from_matches(m)?; + let key_cache = key_cache_from_matches(m)?; command::origin::key::download::start(ui, &url, @@ -574,17 +574,17 @@ async fn sub_origin_key_download(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> } fn sub_origin_key_export(m: &ArgMatches<'_>) -> Result<()> { - let origin = m.value_of("ORIGIN").unwrap().parse()?; // Required via clap + let origin = required_value_of(m, "ORIGIN").parse()?; let key_type = KeyType::from_str(m.value_of("KEY_TYPE").unwrap_or("public"))?; - let key_cache = key_cache_from_matches(&m)?; + let key_cache = key_cache_from_matches(m)?; init()?; command::origin::key::export::start(&origin, key_type, &key_cache) } fn sub_origin_key_generate(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let origin = origin_param_or_env(&m)?; - let key_cache = key_cache_from_matches(&m)?; + let origin = origin_param_or_env(m)?; + let key_cache = key_cache_from_matches(m)?; init()?; command::origin::key::generate::start(ui, &origin, &key_cache) @@ -592,7 +592,7 @@ fn sub_origin_key_generate(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { fn sub_origin_key_import(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let mut content = String::new(); - let key_cache = key_cache_from_matches(&m)?; + let key_cache = key_cache_from_matches(m)?; init()?; io::stdin().read_to_string(&mut content)?; @@ -601,14 +601,14 @@ fn sub_origin_key_import(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { } async fn sub_origin_key_upload(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; - let key_cache = key_cache_from_matches(&m)?; + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; + let key_cache = key_cache_from_matches(m)?; init()?; if m.is_present("ORIGIN") { - let origin = m.value_of("ORIGIN").unwrap().parse()?; + let origin = required_value_of(m, "ORIGIN").parse()?; // you can either specify files, or infer the latest key names let with_secret = m.is_present("WITH_SECRET"); command::origin::key::upload_latest::start(ui, @@ -618,19 +618,20 @@ async fn sub_origin_key_upload(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { with_secret, &key_cache).await } else { - let keyfile = Path::new(m.value_of("PUBLIC_FILE").unwrap()); + let secret_file = required_value_of(m, "PUBLIC_FILE"); + let keyfile = Path::new(secret_file); let secret_keyfile = m.value_of("SECRET_FILE").map(|f| Path::new(f)); command::origin::key::upload::start(ui, &url, &token, &keyfile, secret_keyfile).await } } async fn sub_origin_secret_upload(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; - let origin = origin_param_or_env(&m)?; - let key = m.value_of("KEY_NAME").unwrap(); - let secret = m.value_of("SECRET").unwrap(); - let key_cache = key_cache_from_matches(&m)?; + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; + let origin = origin_param_or_env(m)?; + let key = required_value_of(m, "KEY_NAME"); + let secret = required_value_of(m, "SECRET"); + let key_cache = key_cache_from_matches(m)?; command::origin::secret::upload::start(ui, &url, &token, @@ -641,110 +642,108 @@ async fn sub_origin_secret_upload(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> } async fn sub_origin_secret_delete(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; - let origin = origin_param_or_env(&m)?; - let key = m.value_of("KEY_NAME").unwrap(); + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; + let origin = origin_param_or_env(m)?; + let key = required_value_of(m, "KEY_NAME"); command::origin::secret::delete::start(ui, &url, &token, &origin, &key).await } async fn sub_origin_secret_list(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; - let origin = origin_param_or_env(&m)?; + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; + let origin = origin_param_or_env(m)?; command::origin::secret::list::start(ui, &url, &token, &origin).await } async fn sub_origin_create(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let origin = m.value_of("ORIGIN").expect("required ORIGIN"); - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; + let origin = required_value_of(m, "ORIGIN"); + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; command::origin::create::start(ui, &url, &token, &origin).await } async fn sub_origin_info(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let origin = m.value_of("ORIGIN").expect("required ORIGIN"); - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; + let origin = required_value_of(m, "ORIGIN"); + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; let to_json = m.is_present("TO_JSON"); command::origin::info::start(ui, &url, &token, &origin, to_json).await } async fn sub_origin_delete(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let origin = m.value_of("ORIGIN").expect("required ORIGIN"); - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; + let origin = required_value_of(m, "ORIGIN"); + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; command::origin::delete::start(ui, &url, &token, &origin).await } async fn sub_origin_transfer_ownership(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let origin = m.value_of("ORIGIN").expect("required ORIGIN"); - let account = m.value_of("NEW_OWNER_ACCOUNT") - .expect("required NEW_OWNER_ACCOUNT"); - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; + let origin = required_value_of(m, "ORIGIN"); + let account = required_value_of(m, "NEW_OWNER_ACCOUNT"); + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; command::origin::transfer::start(ui, &url, &token, &origin, &account).await } async fn sub_origin_depart(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let origin = m.value_of("ORIGIN").expect("required ORIGIN"); - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; + let origin = required_value_of(m, "ORIGIN"); + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; command::origin::depart::start(ui, &url, &token, &origin).await } async fn sub_accept_origin_invitation(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let origin = m.value_of("ORIGIN").expect("required ORIGIN"); - let invitation_id: u64 = m.value_of("INVITATION_ID") - .expect("required INVITATION_ID") + let origin = required_value_of(m, "ORIGIN"); + let invitation_id = required_value_of(m, "INVITATION_ID"); + let invitation_id: u64 = invitation_id .parse() .expect("INVITATION_ID should be valid at this point"); - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; command::origin::invitations::accept::start(ui, &url, &origin, &token, invitation_id).await } async fn sub_ignore_origin_invitation(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let origin = m.value_of("ORIGIN").expect("required ORIGIN"); - let invitation_id: u64 = m.value_of("INVITATION_ID") - .expect("required INVITATION_ID") + let origin = required_value_of(m, "ORIGIN"); + let invitation_id = required_value_of(m, "INVITATION_ID"); + let invitation_id: u64 = invitation_id .parse() .expect("INVITATION_ID should be valid at this point"); - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; command::origin::invitations::ignore::start(ui, &url, &origin, &token, invitation_id).await } async fn sub_list_user_invitations(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; command::origin::invitations::list_user::start(ui, &url, &token).await } async fn sub_list_pending_origin_invitations(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let origin = m.value_of("ORIGIN").expect("required ORIGIN"); - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; + let origin = required_value_of(m, "ORIGIN"); + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; command::origin::invitations::list_pending_origin::start(ui, &url, &origin, &token).await } async fn sub_rescind_origin_invitation(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let origin = m.value_of("ORIGIN").expect("required ORIGIN"); - let invitation_id: u64 = m.value_of("INVITATION_ID") - .expect("required INVITATION_ID") + let origin = required_value_of(m, "ORIGIN"); + let invitation_id = required_value_of(m, "INVITATION_ID"); + let invitation_id: u64 = invitation_id .parse() .expect("INVITATION_ID should be valid at this point"); - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; command::origin::invitations::rescind::start(ui, &url, &origin, &token, invitation_id).await } async fn sub_send_origin_invitation(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let origin = m.value_of("ORIGIN").expect("required ORIGIN"); - let invitee_account = m.value_of("INVITEE_ACCOUNT") - .expect("required INVITEE_ACCOUNT"); - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; + let origin = required_value_of(m, "ORIGIN"); + let invitee_account = required_value_of(m, "INVITEE_ACCOUNT"); + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; command::origin::invitations::send::start(ui, &url, &origin, &token, &invitee_account).await } @@ -773,7 +772,8 @@ async fn sub_origin_member_role_set(ui: &mut UI, r: RbacSet) -> Result<()> { fn sub_pkg_binlink(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let ident = required_pkg_ident_from_input(m)?; - let dest_dir = Path::new(m.value_of("DEST_DIR").unwrap()); // required by clap + let dest_dir = required_value_of(m, "DEST_DIR"); + let dest_dir = Path::new(dest_dir); let force = m.is_present("FORCE"); match m.value_of("BINARY") { Some(binary) => { @@ -795,7 +795,7 @@ fn hab_key_origins(m: &ArgMatches<'_>) -> Result) -> Result<()> { - let plan_context = m.value_of("PLAN_CONTEXT").unwrap(); // Required via clap + let plan_context = required_value_of(m, "PLAN_CONTEXT"); let root = m.value_of("HAB_STUDIO_ROOT"); let src = m.value_of("SRC_PATH"); @@ -848,8 +848,8 @@ async fn sub_pkg_download(ui: &mut UI, m: &ArgMatches<'_>, _feature_flags: FeatureFlag) -> Result<()> { - let token = maybe_auth_token(&m); - let url = bldr_url_from_matches(&m)?; + let token = maybe_auth_token(m); + let url = bldr_url_from_matches(m)?; let download_dir = download_dir_from_matches(m); // Construct flat file based inputs @@ -920,7 +920,7 @@ async fn sub_pkg_uninstall(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { } else { command::pkg::Scope::PackageAndDependencies }; - let excludes = excludes_from_matches(&m); + let excludes = excludes_from_matches(m); let uninstall_hook_mode = if m.is_present("IGNORE_UNINSTALL_HOOK") { UninstallHookMode::Ignore } else { @@ -938,33 +938,33 @@ async fn sub_pkg_uninstall(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { } async fn sub_bldr_channel_create(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let origin = origin_param_or_env(&m)?; - let channel = required_channel_from_matches(&m); - let token = auth_token_param_or_env(&m)?; + let url = bldr_url_from_matches(m)?; + let origin = origin_param_or_env(m)?; + let channel = required_channel_from_matches(m); + let token = auth_token_param_or_env(m)?; command::bldr::channel::create::start(ui, &url, &token, &origin, &channel).await } async fn sub_bldr_channel_destroy(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let origin = origin_param_or_env(&m)?; - let channel = required_channel_from_matches(&m); - let token = auth_token_param_or_env(&m)?; + let url = bldr_url_from_matches(m)?; + let origin = origin_param_or_env(m)?; + let channel = required_channel_from_matches(m); + let token = auth_token_param_or_env(m)?; command::bldr::channel::destroy::start(ui, &url, &token, &origin, &channel).await } async fn sub_bldr_channel_list(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let origin = origin_param_or_env(&m)?; + let url = bldr_url_from_matches(m)?; + let origin = origin_param_or_env(m)?; command::bldr::channel::list::start(ui, &url, &origin).await } async fn sub_bldr_channel_promote(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let origin = origin_param_or_env(&m)?; - let token = auth_token_param_or_env(&m)?; - let source_channel = required_source_channel_from_matches(&m); - let target_channel = required_target_channel_from_matches(&m); + let url = bldr_url_from_matches(m)?; + let origin = origin_param_or_env(m)?; + let token = auth_token_param_or_env(m)?; + let source_channel = required_source_channel_from_matches(m); + let target_channel = required_target_channel_from_matches(m); command::bldr::channel::promote::start(ui, &url, &token, @@ -974,11 +974,11 @@ async fn sub_bldr_channel_promote(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> } async fn sub_bldr_channel_demote(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let origin = origin_param_or_env(&m)?; - let token = auth_token_param_or_env(&m)?; - let source_channel = required_source_channel_from_matches(&m); - let target_channel = required_target_channel_from_matches(&m); + let url = bldr_url_from_matches(m)?; + let origin = origin_param_or_env(m)?; + let token = auth_token_param_or_env(m)?; + let source_channel = required_source_channel_from_matches(m); + let target_channel = required_target_channel_from_matches(m); command::bldr::channel::demote::start(ui, &url, &token, @@ -989,17 +989,17 @@ async fn sub_bldr_channel_demote(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> async fn sub_bldr_job_start(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let ident = required_pkg_ident_from_input(m)?; - let url = bldr_url_from_matches(&m)?; + let url = bldr_url_from_matches(m)?; let target = target_from_matches(m)?; let group = m.is_present("GROUP"); - let token = auth_token_param_or_env(&m)?; + let token = auth_token_param_or_env(m)?; command::bldr::job::start::start(ui, &url, (&ident, target), &token, group).await } async fn sub_bldr_job_cancel(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let group_id = m.value_of("GROUP_ID").unwrap(); // Required via clap - let token = auth_token_param_or_env(&m)?; + let url = bldr_url_from_matches(m)?; + let group_id = required_value_of(m, "GROUP_ID"); + let token = auth_token_param_or_env(m)?; let force = m.is_present("FORCE"); command::bldr::job::cancel::start(ui, &url, &group_id, &token, force).await } @@ -1008,13 +1008,13 @@ async fn sub_bldr_job_promote_or_demote(ui: &mut UI, m: &ArgMatches<'_>, promote: bool) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let group_id = m.value_of("GROUP_ID").unwrap(); // Required via clap - let channel = required_channel_from_matches(&m); + let url = bldr_url_from_matches(m)?; + let group_id = required_value_of(m, "GROUP_ID"); + let channel = required_channel_from_matches(m); let origin = m.value_of("ORIGIN"); let interactive = m.is_present("INTERACTIVE"); let verbose = m.is_present("VERBOSE"); - let token = auth_token_param_or_env(&m)?; + let token = auth_token_param_or_env(m)?; command::bldr::job::promote::start(ui, &url, &group_id, @@ -1027,7 +1027,7 @@ async fn sub_bldr_job_promote_or_demote(ui: &mut UI, } async fn sub_bldr_job_status(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; + let url = bldr_url_from_matches(m)?; let group_id = m.value_of("GROUP_ID"); let origin = m.value_of("ORIGIN"); let limit = m.value_of("LIMIT") @@ -1041,7 +1041,7 @@ async fn sub_bldr_job_status(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { fn sub_plan_init(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let name = m.value_of("PKG_NAME").map(String::from); - let origin = origin_param_or_env(&m)?; + let origin = origin_param_or_env(m)?; let minimal = m.is_present("MIN"); let scaffolding_ident = if cfg!(windows) { match m.value_of("SCAFFOLDING") { @@ -1056,9 +1056,11 @@ fn sub_plan_init(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { } fn sub_plan_render(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let template_path = Path::new(m.value_of("TEMPLATE_PATH").unwrap()); + let template_path = required_value_of(m, "TEMPLATE_PATH"); + let template_path = Path::new(template_path); - let default_toml_path = Path::new(m.value_of("DEFAULT_TOML").unwrap()); + let default_toml_path = required_value_of(m, "DEFAULT_TOML"); + let default_toml_path = Path::new(default_toml_path); let user_toml_path = m.value_of("USER_TOML").map(Path::new); @@ -1068,7 +1070,8 @@ fn sub_plan_render(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let render = !m.is_present("NO_RENDER"); let quiet = m.is_present("QUIET"); - let render_dir = Path::new(m.value_of("RENDER_DIR").unwrap()); + let render_dir = required_value_of(m, "RENDER_DIR"); + let render_dir = Path::new(render_dir); command::plan::render::start(ui, template_path, @@ -1085,10 +1088,10 @@ async fn sub_pkg_install(ui: &mut UI, m: &ArgMatches<'_>, feature_flags: FeatureFlag) -> Result<()> { - let url = bldr_url_from_matches(&m)?; + let url = bldr_url_from_matches(m)?; let channel = channel_from_matches_or_default(m); let install_sources = install_sources_from_matches(m)?; - let token = maybe_auth_token(&m); + let token = maybe_auth_token(m); let install_mode = if feature_flags.contains(FeatureFlag::OFFLINE_INSTALL) && m.is_present("OFFLINE") { InstallMode::Offline @@ -1150,7 +1153,7 @@ fn sub_pkg_list(m: &ArgMatches<'_>) -> Result<()> { } fn sub_pkg_provides(m: &ArgMatches<'_>) -> Result<()> { - let filename = m.value_of("FILE").unwrap(); // Required via clap + let filename = required_value_of(m, "FILE"); let full_releases = m.is_present("FULL_RELEASES"); let full_paths = m.is_present("FULL_PATHS"); @@ -1159,23 +1162,25 @@ fn sub_pkg_provides(m: &ArgMatches<'_>) -> Result<()> { } async fn sub_pkg_search(m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let search_term = m.value_of("SEARCH_TERM").expect("required opt SEARCH_TERM"); - let limit = m.value_of("LIMIT") - .expect("required opt LIMIT") + let url = bldr_url_from_matches(m)?; + let search_term = required_value_of(m, "SEARCH_TERM"); + let limit = required_value_of(m, "LIMIT"); + let limit = limit .parse() .expect("valid LIMIT"); - let token = maybe_auth_token(&m); + let token = maybe_auth_token(m); command::pkg::search::start(&search_term, &url, limit, token.as_deref()).await } fn sub_pkg_sign(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let origin = origin_param_or_env(&m)?; + let origin = origin_param_or_env(m)?; - let src = Path::new(m.value_of("SOURCE").unwrap()); // Required via clap - let dst = Path::new(m.value_of("DEST").unwrap()); // Required via clap + let src = required_value_of(m, "SOURCE"); + let src = Path::new(src); + let dst = required_value_of(m, "DEST"); + let dst = Path::new(dst); - let key_cache = key_cache_from_matches(&m)?; + let key_cache = key_cache_from_matches(m)?; init()?; @@ -1213,12 +1218,12 @@ async fn sub_pkg_bulkupload(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { } async fn sub_pkg_upload(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let key_cache = key_cache_from_matches(&m)?; - let url = bldr_url_from_matches(&m)?; + let key_cache = key_cache_from_matches(m)?; + let url = bldr_url_from_matches(m)?; // When packages are uploaded, they *always* go to `unstable`; // they can optionally get added to another channel, too. - let additional_release_channel = channel_from_matches(&m); + let additional_release_channel = channel_from_matches(m); // When packages are uploaded we check if they exist in the db // before allowing a write to the backend, this bypasses the check @@ -1230,7 +1235,7 @@ async fn sub_pkg_upload(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { BuildOnUpload::PackageDefault }; - let token = auth_token_param_or_env(&m)?; + let token = auth_token_param_or_env(m)?; let artifact_paths = m.values_of("HART_FILE").unwrap(); // Required via clap for artifact_path in artifact_paths.map(Path::new) { command::pkg::upload::start(ui, @@ -1246,8 +1251,8 @@ async fn sub_pkg_upload(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { } async fn sub_pkg_delete(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let token = auth_token_param_or_env(&m)?; + let url = bldr_url_from_matches(m)?; + let token = auth_token_param_or_env(m)?; let ident = required_pkg_ident_from_input(m)?; let target = target_from_matches(m)?; @@ -1257,22 +1262,25 @@ async fn sub_pkg_delete(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { } fn sub_pkg_verify(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let src = Path::new(m.value_of("SOURCE").unwrap()); // Required via clap - let key_cache = key_cache_from_matches(&m)?; + let src = required_value_of(m, "SOURCE"); + let src = Path::new(src); + let key_cache = key_cache_from_matches(m)?; init()?; command::pkg::verify::start(ui, &src, &key_cache) } fn sub_pkg_header(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let src = Path::new(m.value_of("SOURCE").unwrap()); // Required via clap + let src = required_value_of(m, "SOURCE"); + let src = Path::new(src); init()?; command::pkg::header::start(ui, &src) } fn sub_pkg_info(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let src = Path::new(m.value_of("SOURCE").unwrap()); // Required via clap + let src = required_value_of(m, "SOURCE"); + let src = Path::new(src); let to_json = m.is_present("TO_JSON"); init()?; @@ -1280,27 +1288,27 @@ fn sub_pkg_info(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { } async fn sub_pkg_promote(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let channel = required_channel_from_matches(&m); - let token = auth_token_param_or_env(&m)?; + let url = bldr_url_from_matches(m)?; + let channel = required_channel_from_matches(m); + let token = auth_token_param_or_env(m)?; let target = target_from_matches(m)?; let ident = required_pkg_ident_from_input(m)?; command::pkg::promote::start(ui, &url, (&ident, target), &channel, &token).await } async fn sub_pkg_demote(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; - let channel = required_channel_from_matches(&m); - let token = auth_token_param_or_env(&m)?; + let url = bldr_url_from_matches(m)?; + let channel = required_channel_from_matches(m); + let token = auth_token_param_or_env(m)?; let target = target_from_matches(m)?; let ident = required_pkg_ident_from_input(m)?; command::pkg::demote::start(ui, &url, (&ident, target), &channel, &token).await } async fn sub_pkg_channels(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let url = bldr_url_from_matches(&m)?; + let url = bldr_url_from_matches(m)?; let ident = required_pkg_ident_from_input(m)?; - let token = maybe_auth_token(&m); + let token = maybe_auth_token(m); let target = target_from_matches(m)?; command::pkg::channels::start(ui, &url, (&ident, target), token.as_deref()).await @@ -1309,7 +1317,8 @@ async fn sub_pkg_channels(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { async fn sub_svc_set(m: &ArgMatches<'_>) -> Result<()> { let remote_sup_addr = remote_sup_from_input(m)?; let remote_sup_addr = SrvClient::ctl_addr(remote_sup_addr.as_ref())?; - let service_group = ServiceGroup::from_str(m.value_of("SERVICE_GROUP").unwrap())?; + let service_group = required_value_of(m, "SERVICE_GROUP"); + let service_group = ServiceGroup::from_str(service_group)?; let mut ui = ui::ui(); let mut validate = sup_proto::ctl::SvcValidateCfg::default(); validate.service_group = Some(service_group.clone().into()); @@ -1327,10 +1336,10 @@ async fn sub_svc_set(m: &ArgMatches<'_>) -> Result<()> { process::exit(1); } validate.cfg = Some(buf.clone()); - let key_cache = key_cache_from_matches(&m)?; + let key_cache = key_cache_from_matches(m)?; let mut set = sup_proto::ctl::SvcSetCfg::default(); - match (service_group.org(), user_param_or_env(&m)) { + match (service_group.org(), user_param_or_env(m)) { (Some(_org), Some(username)) => { let user_key = key_cache.latest_user_secret_key(&username)?; let service_key = key_cache.latest_service_public_key(&service_group)?; @@ -1495,12 +1504,14 @@ async fn sub_svc_stop(m: &ArgMatches<'_>) -> Result<()> { } async fn sub_file_put(m: &ArgMatches<'_>) -> Result<()> { - let service_group = ServiceGroup::from_str(m.value_of("SERVICE_GROUP").unwrap())?; + let service_group = required_value_of(m, "SERVICE_GROUP"); + let service_group = ServiceGroup::from_str(service_group)?; let remote_sup_addr = remote_sup_from_input(m)?; let remote_sup_addr = SrvClient::ctl_addr(remote_sup_addr.as_ref())?; let mut ui = ui::ui(); let mut msg = sup_proto::ctl::SvcFilePut::default(); - let file = Path::new(m.value_of("FILE").unwrap()); + let file = required_value_of(m, "FILE"); + let file = Path::new(file); if file.metadata()?.len() > sup_proto::butterfly::MAX_FILE_PUT_SIZE_BYTES as u64 { ui.fatal(format!("File too large. Maximum size allowed is {} bytes.", sup_proto::butterfly::MAX_FILE_PUT_SIZE_BYTES))?; @@ -1510,7 +1521,7 @@ async fn sub_file_put(m: &ArgMatches<'_>) -> Result<()> { msg.version = Some(value_t!(m, "VERSION_NUMBER", u64).unwrap()); msg.filename = Some(file.file_name().unwrap().to_string_lossy().into_owned()); let mut buf = Vec::with_capacity(sup_proto::butterfly::MAX_FILE_PUT_SIZE_BYTES); - let key_cache = key_cache_from_matches(&m)?; + let key_cache = key_cache_from_matches(m)?; ui.begin(format!("Uploading file {} to {} incarnation {}", file.display(), @@ -1524,7 +1535,7 @@ async fn sub_file_put(m: &ArgMatches<'_>) -> Result<()> { .unwrap_or_else(|| "UKNOWN".to_string()),))?; ui.status(Status::Creating, "service file")?; File::open(&file)?.read_to_end(&mut buf)?; - match (service_group.org(), user_param_or_env(&m)) { + match (service_group.org(), user_param_or_env(m)) { (Some(_org), Some(username)) => { // That Some(_org) bit is really "was an org specified for // this service group?" @@ -1638,16 +1649,16 @@ fn sub_supportbundle(ui: &mut UI) -> Result<()> { } fn sub_ring_key_export(m: &ArgMatches<'_>) -> Result<()> { - let ring = m.value_of("RING").unwrap(); // Required via clap - let key_cache = key_cache_from_matches(&m)?; + let ring = required_value_of(m, "RING"); + let key_cache = key_cache_from_matches(m)?; init()?; command::ring::key::export::start(ring, &key_cache) } fn sub_ring_key_generate(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let ring = m.value_of("RING").unwrap(); // Required via clap - let key_cache = key_cache_from_matches(&m)?; + let ring = required_value_of(m, "RING"); + let key_cache = key_cache_from_matches(m)?; init()?; command::ring::key::generate::start(ui, ring, &key_cache) @@ -1655,7 +1666,7 @@ fn sub_ring_key_generate(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { fn sub_ring_key_import(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let mut content = String::new(); - let key_cache = key_cache_from_matches(&m)?; + let key_cache = key_cache_from_matches(m)?; init()?; io::stdin().read_to_string(&mut content)?; @@ -1664,17 +1675,18 @@ fn sub_ring_key_import(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { } fn sub_service_key_generate(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let org = org_param_or_env(&m)?; - let service_group = ServiceGroup::from_str(m.value_of("SERVICE_GROUP").unwrap())?; - let key_cache = key_cache_from_matches(&m)?; + let org = org_param_or_env(m)?; + let service_group = required_value_of(m, "SERVICE_GROUP"); + let service_group = ServiceGroup::from_str(service_group)?; + let key_cache = key_cache_from_matches(m)?; init()?; command::service::key::generate::start(ui, &org, &service_group, &key_cache) } fn sub_user_key_generate(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let user = m.value_of("USER").unwrap(); // Required via clap - let key_cache = key_cache_from_matches(&m)?; + let user = required_value_of(m, "USER"); + let key_cache = key_cache_from_matches(m)?; init()?; command::user::key::generate::start(ui, user, &key_cache) @@ -1709,7 +1721,7 @@ fn auth_token_param_or_env(m: &ArgMatches<'_>) -> Result { /// auth_token_param_or_env, it's ok for no auth token to be present here. This is useful for /// commands that can optionally take an auth token for operating on private packages. fn maybe_auth_token(m: &ArgMatches<'_>) -> Option { - match auth_token_param_or_env(&m) { + match auth_token_param_or_env(m) { Ok(t) => Some(t), Err(_) => None, } @@ -2031,6 +2043,12 @@ fn user_param_or_env(m: &ArgMatches<'_>) -> Option { } } +/// Helper function to get information about the argument given its name +fn required_value_of<'a>(matches: &'a ArgMatches<'a>, name: &str) -> &'a str { + matches.value_of(name) + .expect(&format!("{} CLAP required arg missing", name)) +} + #[cfg(test)] mod test { use super::*; From 6919ea7db74bc72499130cb5c63abecc04c782e5 Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Sat, 14 Nov 2020 10:58:07 +0530 Subject: [PATCH 02/15] replaced if/else with match Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index 80595b1970..a6dc5f877c 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -607,21 +607,23 @@ async fn sub_origin_key_upload(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { init()?; - if m.is_present("ORIGIN") { - let origin = required_value_of(m, "ORIGIN").parse()?; - // you can either specify files, or infer the latest key names - let with_secret = m.is_present("WITH_SECRET"); - command::origin::key::upload_latest::start(ui, - &url, - &token, - &origin, - with_secret, - &key_cache).await - } else { - let secret_file = required_value_of(m, "PUBLIC_FILE"); - let keyfile = Path::new(secret_file); - let secret_keyfile = m.value_of("SECRET_FILE").map(|f| Path::new(f)); - command::origin::key::upload::start(ui, &url, &token, &keyfile, secret_keyfile).await + match m.value_of("ORIGIN") { + Some(origin) => { + let origin = origin.parse()?; + // you can either specify files, or infer the latest key names + let with_secret = m.is_present("WITH_SECRET"); + command::origin::key::upload_latest::start(ui, + &url, + &token, + &origin, + with_secret, + &key_cache).await + }, + None => { + let keyfile = Path::new(required_value_of(m, "PUBLIC_FILE")); + let secret_keyfile = m.value_of("SECRET_FILE").map(|f| Path::new(f)); + command::origin::key::upload::start(ui, &url, &token, &keyfile, secret_keyfile).await + } } } From 795d5530b1fb5e54d8229a57c21ed7b77692ca64 Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Sat, 14 Nov 2020 11:01:34 +0530 Subject: [PATCH 03/15] remove separate variable binding Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index a6dc5f877c..50aba92e46 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -697,8 +697,7 @@ async fn sub_origin_depart(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { async fn sub_accept_origin_invitation(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let origin = required_value_of(m, "ORIGIN"); - let invitation_id = required_value_of(m, "INVITATION_ID"); - let invitation_id: u64 = invitation_id + let invitation_id = required_value_of(m, "INVITATION_ID") .parse() .expect("INVITATION_ID should be valid at this point"); let url = bldr_url_from_matches(m)?; @@ -708,8 +707,7 @@ async fn sub_accept_origin_invitation(ui: &mut UI, m: &ArgMatches<'_>) -> Result async fn sub_ignore_origin_invitation(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let origin = required_value_of(m, "ORIGIN"); - let invitation_id = required_value_of(m, "INVITATION_ID"); - let invitation_id: u64 = invitation_id + let invitation_id = required_value_of(m, "INVITATION_ID") .parse() .expect("INVITATION_ID should be valid at this point"); let url = bldr_url_from_matches(m)?; From dd6fa36ca230c6b8bb9a8341c9bb54aa6c9a17f5 Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Sat, 14 Nov 2020 11:04:02 +0530 Subject: [PATCH 04/15] remove separate variable binding Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index 50aba92e46..16c56e4341 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -772,8 +772,7 @@ async fn sub_origin_member_role_set(ui: &mut UI, r: RbacSet) -> Result<()> { fn sub_pkg_binlink(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let ident = required_pkg_ident_from_input(m)?; - let dest_dir = required_value_of(m, "DEST_DIR"); - let dest_dir = Path::new(dest_dir); + let dest_dir = Path::new(required_value_of(m, "DEST_DIR")); let force = m.is_present("FORCE"); match m.value_of("BINARY") { Some(binary) => { From ca642dda17f3bd46782e1478957c2257aebb180b Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Sat, 14 Nov 2020 11:08:53 +0530 Subject: [PATCH 05/15] remove separate variable binding Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index 16c56e4341..bd4672e66d 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -1163,8 +1163,7 @@ fn sub_pkg_provides(m: &ArgMatches<'_>) -> Result<()> { async fn sub_pkg_search(m: &ArgMatches<'_>) -> Result<()> { let url = bldr_url_from_matches(m)?; let search_term = required_value_of(m, "SEARCH_TERM"); - let limit = required_value_of(m, "LIMIT"); - let limit = limit + let limit = required_value_of(m, "LIMIT") .parse() .expect("valid LIMIT"); let token = maybe_auth_token(m); From f08792f7d2a05a37bfe5d15b78e2472ef54f6545 Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Sat, 14 Nov 2020 11:09:38 +0530 Subject: [PATCH 06/15] remove separate variable binding Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index bd4672e66d..a446d26512 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -1173,10 +1173,8 @@ async fn sub_pkg_search(m: &ArgMatches<'_>) -> Result<()> { fn sub_pkg_sign(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let origin = origin_param_or_env(m)?; - let src = required_value_of(m, "SOURCE"); - let src = Path::new(src); - let dst = required_value_of(m, "DEST"); - let dst = Path::new(dst); + let src = Path::new(required_value_of(m, "SOURCE")); + let dst = Path::new(required_value_of(m, "DEST")); let key_cache = key_cache_from_matches(m)?; From 3eb46e0609c1a086d0b7d503b68f60916e339204 Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Sat, 14 Nov 2020 11:11:30 +0530 Subject: [PATCH 07/15] remove separate variable binding Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index a446d26512..f56d4ac717 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -1258,8 +1258,7 @@ async fn sub_pkg_delete(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { } fn sub_pkg_verify(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let src = required_value_of(m, "SOURCE"); - let src = Path::new(src); + let src = Path::new(required_value_of(m, "SOURCE")); let key_cache = key_cache_from_matches(m)?; init()?; @@ -1267,16 +1266,14 @@ fn sub_pkg_verify(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { } fn sub_pkg_header(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let src = required_value_of(m, "SOURCE"); - let src = Path::new(src); + let src = Path::new(required_value_of(m, "SOURCE")); init()?; command::pkg::header::start(ui, &src) } fn sub_pkg_info(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { - let src = required_value_of(m, "SOURCE"); - let src = Path::new(src); + let src = Path::new(required_value_of(m, "SOURCE")); let to_json = m.is_present("TO_JSON"); init()?; From 60b750d7894be5f476e8fb463ee239f2ca777fb8 Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Sat, 14 Nov 2020 13:47:42 +0530 Subject: [PATCH 08/15] service group remove separate variable binding Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index f56d4ac717..cfda8de262 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -1310,8 +1310,7 @@ async fn sub_pkg_channels(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { async fn sub_svc_set(m: &ArgMatches<'_>) -> Result<()> { let remote_sup_addr = remote_sup_from_input(m)?; let remote_sup_addr = SrvClient::ctl_addr(remote_sup_addr.as_ref())?; - let service_group = required_value_of(m, "SERVICE_GROUP"); - let service_group = ServiceGroup::from_str(service_group)?; + let service_group = required_value_of(m, "SERVICE_GROUP").parse::()?; let mut ui = ui::ui(); let mut validate = sup_proto::ctl::SvcValidateCfg::default(); validate.service_group = Some(service_group.clone().into()); @@ -1497,14 +1496,12 @@ async fn sub_svc_stop(m: &ArgMatches<'_>) -> Result<()> { } async fn sub_file_put(m: &ArgMatches<'_>) -> Result<()> { - let service_group = required_value_of(m, "SERVICE_GROUP"); - let service_group = ServiceGroup::from_str(service_group)?; + let service_group = required_value_of(m, "SERVICE_GROUP").parse::()?; let remote_sup_addr = remote_sup_from_input(m)?; let remote_sup_addr = SrvClient::ctl_addr(remote_sup_addr.as_ref())?; let mut ui = ui::ui(); let mut msg = sup_proto::ctl::SvcFilePut::default(); - let file = required_value_of(m, "FILE"); - let file = Path::new(file); + let file = Path::new(required_value_of(m, "FILE")); if file.metadata()?.len() > sup_proto::butterfly::MAX_FILE_PUT_SIZE_BYTES as u64 { ui.fatal(format!("File too large. Maximum size allowed is {} bytes.", sup_proto::butterfly::MAX_FILE_PUT_SIZE_BYTES))?; @@ -1669,8 +1666,7 @@ fn sub_ring_key_import(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { fn sub_service_key_generate(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let org = org_param_or_env(m)?; - let service_group = required_value_of(m, "SERVICE_GROUP"); - let service_group = ServiceGroup::from_str(service_group)?; + let service_group = required_value_of(m, "SERVICE_GROUP").parse::()?; let key_cache = key_cache_from_matches(m)?; init()?; From fe565207f7a8ef2f4ec8f1d5b49a1f1a35e292cf Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Tue, 17 Nov 2020 14:19:16 +0530 Subject: [PATCH 09/15] [PR Feedback] removed unnecessary type hint Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index cfda8de262..7288102e05 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -1666,7 +1666,7 @@ fn sub_ring_key_import(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { fn sub_service_key_generate(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let org = org_param_or_env(m)?; - let service_group = required_value_of(m, "SERVICE_GROUP").parse::()?; + let service_group = required_value_of(m, "SERVICE_GROUP").parse()?; let key_cache = key_cache_from_matches(m)?; init()?; From e16d6f1120431a7f6887406e558fd1986ce09346 Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Tue, 17 Nov 2020 20:35:32 +0530 Subject: [PATCH 10/15] [PR Feedback] remove unnecessary variable binding Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index 7288102e05..95627cea21 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -730,8 +730,7 @@ async fn sub_list_pending_origin_invitations(ui: &mut UI, m: &ArgMatches<'_>) -> async fn sub_rescind_origin_invitation(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let origin = required_value_of(m, "ORIGIN"); - let invitation_id = required_value_of(m, "INVITATION_ID"); - let invitation_id: u64 = invitation_id + let invitation_id = required_value_of(m, "INVITATION_ID") .parse() .expect("INVITATION_ID should be valid at this point"); let url = bldr_url_from_matches(m)?; From d31ddc80a854dcf65f34b19610044f230b5a6a76 Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Tue, 17 Nov 2020 20:38:37 +0530 Subject: [PATCH 11/15] [PR Feedback] correct rustfmt error on match Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index 95627cea21..5dba03486d 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -618,7 +618,7 @@ async fn sub_origin_key_upload(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { &origin, with_secret, &key_cache).await - }, + } None => { let keyfile = Path::new(required_value_of(m, "PUBLIC_FILE")); let secret_keyfile = m.value_of("SECRET_FILE").map(|f| Path::new(f)); From 9e2e9cfc1cda0f073e442cab863e7cc53c9e224e Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Tue, 17 Nov 2020 20:43:02 +0530 Subject: [PATCH 12/15] [PR Feedback] correct rustfmt errors (invitation_id) Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index 5dba03486d..1974219d05 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -697,9 +697,9 @@ async fn sub_origin_depart(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { async fn sub_accept_origin_invitation(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let origin = required_value_of(m, "ORIGIN"); - let invitation_id = required_value_of(m, "INVITATION_ID") - .parse() - .expect("INVITATION_ID should be valid at this point"); + let invitation_id = + required_value_of(m, "INVITATION_ID").parse() + .expect("INVITATION_ID should be valid at this point"); let url = bldr_url_from_matches(m)?; let token = auth_token_param_or_env(m)?; command::origin::invitations::accept::start(ui, &url, &origin, &token, invitation_id).await @@ -707,9 +707,9 @@ async fn sub_accept_origin_invitation(ui: &mut UI, m: &ArgMatches<'_>) -> Result async fn sub_ignore_origin_invitation(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let origin = required_value_of(m, "ORIGIN"); - let invitation_id = required_value_of(m, "INVITATION_ID") - .parse() - .expect("INVITATION_ID should be valid at this point"); + let invitation_id = + required_value_of(m, "INVITATION_ID").parse() + .expect("INVITATION_ID should be valid at this point"); let url = bldr_url_from_matches(m)?; let token = auth_token_param_or_env(m)?; command::origin::invitations::ignore::start(ui, &url, &origin, &token, invitation_id).await @@ -730,9 +730,9 @@ async fn sub_list_pending_origin_invitations(ui: &mut UI, m: &ArgMatches<'_>) -> async fn sub_rescind_origin_invitation(ui: &mut UI, m: &ArgMatches<'_>) -> Result<()> { let origin = required_value_of(m, "ORIGIN"); - let invitation_id = required_value_of(m, "INVITATION_ID") - .parse() - .expect("INVITATION_ID should be valid at this point"); + let invitation_id = + required_value_of(m, "INVITATION_ID").parse() + .expect("INVITATION_ID should be valid at this point"); let url = bldr_url_from_matches(m)?; let token = auth_token_param_or_env(m)?; command::origin::invitations::rescind::start(ui, &url, &origin, &token, invitation_id).await From f42c7962a2c95a834faf68f01eda429d1b71ddc3 Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Tue, 17 Nov 2020 20:44:33 +0530 Subject: [PATCH 13/15] [PR Feedback] correct rustfmt error (limit) Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index 1974219d05..e30a6d776f 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -1162,9 +1162,7 @@ fn sub_pkg_provides(m: &ArgMatches<'_>) -> Result<()> { async fn sub_pkg_search(m: &ArgMatches<'_>) -> Result<()> { let url = bldr_url_from_matches(m)?; let search_term = required_value_of(m, "SEARCH_TERM"); - let limit = required_value_of(m, "LIMIT") - .parse() - .expect("valid LIMIT"); + let limit = required_value_of(m, "LIMIT").parse().expect("valid LIMIT"); let token = maybe_auth_token(m); command::pkg::search::start(&search_term, &url, limit, token.as_deref()).await } From 069b40f17b2649ea51dd3b578f0cfc59c46e46e7 Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Tue, 17 Nov 2020 20:45:46 +0530 Subject: [PATCH 14/15] [PR Feedback] correct rustfmt error on required_value_of function Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index e30a6d776f..2df73614e4 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -2032,7 +2032,7 @@ fn user_param_or_env(m: &ArgMatches<'_>) -> Option { /// Helper function to get information about the argument given its name fn required_value_of<'a>(matches: &'a ArgMatches<'a>, name: &str) -> &'a str { matches.value_of(name) - .expect(&format!("{} CLAP required arg missing", name)) + .expect(&format!("{} CLAP required arg missing", name)) } #[cfg(test)] From 666d24fcb29d2412d26f80d393e9f78c6d26b3a8 Mon Sep 17 00:00:00 2001 From: Phani Sajja Date: Thu, 19 Nov 2020 15:32:19 +0530 Subject: [PATCH 15/15] [PR Feedback] clippy error fix Signed-off-by: Phani Sajja --- components/hab/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/hab/src/main.rs b/components/hab/src/main.rs index 2df73614e4..9dc8f347f3 100755 --- a/components/hab/src/main.rs +++ b/components/hab/src/main.rs @@ -2032,7 +2032,7 @@ fn user_param_or_env(m: &ArgMatches<'_>) -> Option { /// Helper function to get information about the argument given its name fn required_value_of<'a>(matches: &'a ArgMatches<'a>, name: &str) -> &'a str { matches.value_of(name) - .expect(&format!("{} CLAP required arg missing", name)) + .unwrap_or_else(|| panic!("{} CLAP required arg missing", name)) } #[cfg(test)]