diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-06-19 16:38:58 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-06-19 16:38:58 +0100 |
| commit | d1a6d62e895acd329cb6bae51eb88eb9f290b0a4 (patch) | |
| tree | c4455844fc2e2173e6dd2bb61bcf86d0bb407a90 /src/bin/ngit | |
| parent | 3598a05b98852baeb324bdaa00cb69035157f636 (diff) | |
refactor: rename ngit_relay to grasp
in function, params and variable names
Diffstat (limited to 'src/bin/ngit')
| -rw-r--r-- | src/bin/ngit/sub_commands/init.rs | 91 |
1 files changed, 47 insertions, 44 deletions
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 7e095a3..1242e45 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs | |||
| @@ -16,7 +16,7 @@ use ngit::{ | |||
| 16 | client::{Params, send_events}, | 16 | client::{Params, send_events}, |
| 17 | git::nostr_url::{CloneUrl, NostrUrlDecoded}, | 17 | git::nostr_url::{CloneUrl, NostrUrlDecoded}, |
| 18 | repo_ref::{ | 18 | repo_ref::{ |
| 19 | detect_existing_ngit_relays, extract_npub, extract_pks, normalize_ngit_relay_url, | 19 | detect_existing_grasp_servers, extract_npub, extract_pks, normalize_grasp_server_url, |
| 20 | save_repo_config_to_yaml, | 20 | save_repo_config_to_yaml, |
| 21 | }, | 21 | }, |
| 22 | }; | 22 | }; |
| @@ -252,20 +252,20 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 252 | args.blossoms.clone() | 252 | args.blossoms.clone() |
| 253 | }; | 253 | }; |
| 254 | 254 | ||
| 255 | let fallback_ngit_relays = | 255 | let fallback_grasp_servers = |
| 256 | if let Ok(Some(s)) = git_repo.get_git_config_item("nostr.grasp-default-set", None) { | 256 | if let Ok(Some(s)) = git_repo.get_git_config_item("nostr.grasp-default-set", None) { |
| 257 | s.split(';') | 257 | s.split(';') |
| 258 | .filter_map(|url| normalize_ngit_relay_url(url).ok()) // Attempt to parse and filter out errors | 258 | .filter_map(|url| normalize_grasp_server_url(url).ok()) // Attempt to parse and filter out errors |
| 259 | .collect() | 259 | .collect() |
| 260 | } else { | 260 | } else { |
| 261 | vec!["relay.ngit.dev".to_string(), "gitnostr.com".to_string()] | 261 | vec!["relay.ngit.dev".to_string(), "gitnostr.com".to_string()] |
| 262 | }; | 262 | }; |
| 263 | 263 | ||
| 264 | let selected_ngit_relays = if has_server_and_relay_flags { | 264 | let selected_grasp_servers = if has_server_and_relay_flags { |
| 265 | // ignore so a script running `ngit init` can contiue without prompts | 265 | // ignore so a script running `ngit init` can contiue without prompts |
| 266 | vec![] | 266 | vec![] |
| 267 | } else { | 267 | } else { |
| 268 | let mut options: Vec<String> = detect_existing_ngit_relays( | 268 | let mut options: Vec<String> = detect_existing_grasp_servers( |
| 269 | repo_ref.as_ref(), | 269 | repo_ref.as_ref(), |
| 270 | &args.relays, | 270 | &args.relays, |
| 271 | &args.clone_url, | 271 | &args.clone_url, |
| @@ -274,7 +274,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 274 | ); | 274 | ); |
| 275 | let mut selections: Vec<bool> = vec![true; options.len()]; // Initialize selections based on existing options | 275 | let mut selections: Vec<bool> = vec![true; options.len()]; // Initialize selections based on existing options |
| 276 | let empty = options.is_empty(); | 276 | let empty = options.is_empty(); |
| 277 | for fallback in fallback_ngit_relays { | 277 | for fallback in fallback_grasp_servers { |
| 278 | // Check if any option contains the fallback as a substring | 278 | // Check if any option contains the fallback as a substring |
| 279 | if !options.iter().any(|option| option.contains(&fallback)) { | 279 | if !options.iter().any(|option| option.contains(&fallback)) { |
| 280 | options.push(fallback.clone()); // Add fallback if not found | 280 | options.push(fallback.clone()); // Add fallback if not found |
| @@ -286,22 +286,25 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 286 | "grasp server", | 286 | "grasp server", |
| 287 | options, | 287 | options, |
| 288 | selections, | 288 | selections, |
| 289 | normalize_ngit_relay_url, | 289 | normalize_grasp_server_url, |
| 290 | )?; | 290 | )?; |
| 291 | show_multi_input_prompt_success("grasp servers", &selected); | 291 | show_multi_input_prompt_success("grasp servers", &selected); |
| 292 | selected | 292 | selected |
| 293 | }; | 293 | }; |
| 294 | 294 | ||
| 295 | // ensure ngit relays are added as git server, relay and blossom entries | 295 | // ensure ngit relays are added as git server, relay and blossom entries |
| 296 | for ngit_relay in &selected_ngit_relays { | 296 | for grasp_server in &selected_grasp_servers { |
| 297 | if args.clone_url.is_empty() { | 297 | if args.clone_url.is_empty() { |
| 298 | let clone_url = | 298 | let clone_url = format_grasp_server_url_as_clone_url( |
| 299 | format_ngit_relay_url_as_clone_url(ngit_relay, &user_ref.public_key, &identifier)?; | 299 | grasp_server, |
| 300 | &user_ref.public_key, | ||
| 301 | &identifier, | ||
| 302 | )?; | ||
| 300 | 303 | ||
| 301 | let ngit_relay_clone_root = if clone_url.contains("https://") { | 304 | let grasp_server_clone_root = if clone_url.contains("https://") { |
| 302 | format!("https://{ngit_relay}") | 305 | format!("https://{grasp_server}") |
| 303 | } else { | 306 | } else { |
| 304 | ngit_relay.to_string() | 307 | grasp_server.to_string() |
| 305 | }; | 308 | }; |
| 306 | 309 | ||
| 307 | // Find all positions of entries containing the relay root | 310 | // Find all positions of entries containing the relay root |
| @@ -309,7 +312,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 309 | .iter() | 312 | .iter() |
| 310 | .enumerate() | 313 | .enumerate() |
| 311 | .filter_map(|(idx, url)| { | 314 | .filter_map(|(idx, url)| { |
| 312 | if url.contains(&ngit_relay_clone_root) { | 315 | if url.contains(&grasp_server_clone_root) { |
| 313 | Some(idx) | 316 | Some(idx) |
| 314 | } else { | 317 | } else { |
| 315 | None | 318 | None |
| @@ -332,13 +335,13 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 332 | } | 335 | } |
| 333 | } | 336 | } |
| 334 | if args.relays.is_empty() { | 337 | if args.relays.is_empty() { |
| 335 | let relay_url = format_ngit_relay_url_as_relay_url(ngit_relay)?; | 338 | let relay_url = format_grasp_server_url_as_relay_url(grasp_server)?; |
| 336 | if !relay_defaults.contains(&relay_url) { | 339 | if !relay_defaults.contains(&relay_url) { |
| 337 | relay_defaults.push(relay_url); | 340 | relay_defaults.push(relay_url); |
| 338 | } | 341 | } |
| 339 | } | 342 | } |
| 340 | if args.blossoms.is_empty() { | 343 | if args.blossoms.is_empty() { |
| 341 | let blossom = format_ngit_relay_url_as_blossom_url(ngit_relay)?; | 344 | let blossom = format_grasp_server_url_as_blossom_url(grasp_server)?; |
| 342 | if !blossoms_defaults.contains(&blossom) { | 345 | if !blossoms_defaults.contains(&blossom) { |
| 343 | blossoms_defaults.push(blossom); | 346 | blossoms_defaults.push(blossom); |
| 344 | } | 347 | } |
| @@ -370,18 +373,18 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 370 | } | 373 | } |
| 371 | 374 | ||
| 372 | let git_server = if args.clone_url.is_empty() { | 375 | let git_server = if args.clone_url.is_empty() { |
| 373 | let ngit_relay_git_servers: Vec<String> = git_server_defaults | 376 | let grasp_server_git_servers: Vec<String> = git_server_defaults |
| 374 | .iter() | 377 | .iter() |
| 375 | .filter(|s| selected_ngit_relays.iter().any(|r| s.contains(r))) | 378 | .filter(|s| selected_grasp_servers.iter().any(|r| s.contains(r))) |
| 376 | .cloned() | 379 | .cloned() |
| 377 | .collect(); | 380 | .collect(); |
| 378 | let mut additional_server_options: Vec<String> = git_server_defaults | 381 | let mut additional_server_options: Vec<String> = git_server_defaults |
| 379 | .iter() | 382 | .iter() |
| 380 | .filter(|s| ngit_relay_git_servers.iter().any(|r| s.eq(&r))) | 383 | .filter(|s| grasp_server_git_servers.iter().any(|r| s.eq(&r))) |
| 381 | .cloned() | 384 | .cloned() |
| 382 | .collect(); | 385 | .collect(); |
| 383 | 386 | ||
| 384 | if simple_mode && !selected_ngit_relays.is_empty() { | 387 | if simple_mode && !selected_grasp_servers.is_empty() { |
| 385 | if additional_server_options.is_empty() { | 388 | if additional_server_options.is_empty() { |
| 386 | // additional git servers were listed | 389 | // additional git servers were listed |
| 387 | let selected = loop { | 390 | let selected = loop { |
| @@ -414,7 +417,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 414 | break selected; | 417 | break selected; |
| 415 | }; | 418 | }; |
| 416 | show_multi_input_prompt_success("git servers", &selected); | 419 | show_multi_input_prompt_success("git servers", &selected); |
| 417 | let mut combined = ngit_relay_git_servers; | 420 | let mut combined = grasp_server_git_servers; |
| 418 | combined.extend(selected); | 421 | combined.extend(selected); |
| 419 | combined | 422 | combined |
| 420 | } else { | 423 | } else { |
| @@ -444,14 +447,14 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 444 | 447 | ||
| 445 | let relays: Vec<RelayUrl> = { | 448 | let relays: Vec<RelayUrl> = { |
| 446 | if simple_mode { | 449 | if simple_mode { |
| 447 | let formatted_selected_ngit_relays: Vec<String> = selected_ngit_relays | 450 | let formatted_selected_grasp_servers: Vec<String> = selected_grasp_servers |
| 448 | .iter() | 451 | .iter() |
| 449 | .filter_map(|r| format_ngit_relay_url_as_relay_url(r).ok()) | 452 | .filter_map(|r| format_grasp_server_url_as_relay_url(r).ok()) |
| 450 | .collect(); | 453 | .collect(); |
| 451 | let mut options: Vec<String> = relay_defaults | 454 | let mut options: Vec<String> = relay_defaults |
| 452 | .iter() | 455 | .iter() |
| 453 | .filter(|s| { | 456 | .filter(|s| { |
| 454 | !formatted_selected_ngit_relays | 457 | !formatted_selected_grasp_servers |
| 455 | .iter() | 458 | .iter() |
| 456 | .any(|r| s.as_str() == r) | 459 | .any(|r| s.as_str() == r) |
| 457 | }) | 460 | }) |
| @@ -463,7 +466,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 463 | // add fallback relays as options | 466 | // add fallback relays as options |
| 464 | for relay in client.get_fallback_relays().clone() { | 467 | for relay in client.get_fallback_relays().clone() { |
| 465 | if !options.iter().any(|r| r.contains(&relay)) | 468 | if !options.iter().any(|r| r.contains(&relay)) |
| 466 | && !formatted_selected_ngit_relays | 469 | && !formatted_selected_grasp_servers |
| 467 | .iter() | 470 | .iter() |
| 468 | .any(|r| relay.contains(r)) | 471 | .any(|r| relay.contains(r)) |
| 469 | { | 472 | { |
| @@ -485,7 +488,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 485 | )?; | 488 | )?; |
| 486 | show_multi_input_prompt_success("additional nostr relays", &selected); | 489 | show_multi_input_prompt_success("additional nostr relays", &selected); |
| 487 | [ | 490 | [ |
| 488 | formatted_selected_ngit_relays | 491 | formatted_selected_grasp_servers |
| 489 | .iter() | 492 | .iter() |
| 490 | .filter_map(|r| parse_relay_url(r).ok()) | 493 | .filter_map(|r| parse_relay_url(r).ok()) |
| 491 | .collect::<Vec<RelayUrl>>(), | 494 | .collect::<Vec<RelayUrl>>(), |
| @@ -538,7 +541,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 538 | blossoms_defaults, | 541 | blossoms_defaults, |
| 539 | selections, | 542 | selections, |
| 540 | |s| { | 543 | |s| { |
| 541 | format_ngit_relay_url_as_blossom_url(s) | 544 | format_grasp_server_url_as_blossom_url(s) |
| 542 | .context(format!("Invalid blossom URL format: {s}")) | 545 | .context(format!("Invalid blossom URL format: {s}")) |
| 543 | }, | 546 | }, |
| 544 | )?; | 547 | )?; |
| @@ -616,7 +619,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 616 | default_maintainers | 619 | default_maintainers |
| 617 | }; | 620 | }; |
| 618 | 621 | ||
| 619 | if selected_ngit_relays.is_empty() && git_server.iter().any(|s| s.contains("github.com") || s.contains("codeberg.org")) && Interactor::default().confirm( | 622 | if selected_grasp_servers.is_empty() && git_server.iter().any(|s| s.contains("github.com") || s.contains("codeberg.org")) && Interactor::default().confirm( |
| 620 | PromptConfirmParms::default() | 623 | PromptConfirmParms::default() |
| 621 | .with_prompt("you have listed github / codeberg. Are you or other maintainers planning on pushing directly to github / codeberg rather than using your shiny new nostr clone url which will do this for you?") | 624 | .with_prompt("you have listed github / codeberg. Are you or other maintainers planning on pushing directly to github / codeberg rather than using your shiny new nostr clone url which will do this for you?") |
| 622 | .with_default(false), | 625 | .with_default(false), |
| @@ -782,7 +785,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 782 | // ignore during tests as git-remote-nostr isn't installed during ngit binary | 785 | // ignore during tests as git-remote-nostr isn't installed during ngit binary |
| 783 | // tests | 786 | // tests |
| 784 | 787 | ||
| 785 | if selected_ngit_relays.is_empty() { | 788 | if selected_grasp_servers.is_empty() { |
| 786 | println!("running `git push` to publish your repository data"); | 789 | println!("running `git push` to publish your repository data"); |
| 787 | } else { | 790 | } else { |
| 788 | let countdown_start = 5; | 791 | let countdown_start = 5; |
| @@ -940,38 +943,38 @@ where | |||
| 940 | Ok(selected_choices) | 943 | Ok(selected_choices) |
| 941 | } | 944 | } |
| 942 | 945 | ||
| 943 | fn format_ngit_relay_url_as_clone_url( | 946 | fn format_grasp_server_url_as_clone_url( |
| 944 | url: &str, | 947 | url: &str, |
| 945 | public_key: &PublicKey, | 948 | public_key: &PublicKey, |
| 946 | identifier: &str, | 949 | identifier: &str, |
| 947 | ) -> Result<String> { | 950 | ) -> Result<String> { |
| 948 | let ngit_relay_url = normalize_ngit_relay_url(url)?; | 951 | let grasp_server_url = normalize_grasp_server_url(url)?; |
| 949 | if ngit_relay_url.contains("http://") { | 952 | if grasp_server_url.contains("http://") { |
| 950 | return Ok(format!( | 953 | return Ok(format!( |
| 951 | "{ngit_relay_url}/{}/{identifier}.git", | 954 | "{grasp_server_url}/{}/{identifier}.git", |
| 952 | public_key.to_bech32()? | 955 | public_key.to_bech32()? |
| 953 | )); | 956 | )); |
| 954 | } | 957 | } |
| 955 | Ok(format!( | 958 | Ok(format!( |
| 956 | "https://{ngit_relay_url}/{}/{identifier}.git", | 959 | "https://{grasp_server_url}/{}/{identifier}.git", |
| 957 | public_key.to_bech32()? | 960 | public_key.to_bech32()? |
| 958 | )) | 961 | )) |
| 959 | } | 962 | } |
| 960 | 963 | ||
| 961 | fn format_ngit_relay_url_as_relay_url(url: &str) -> Result<String> { | 964 | fn format_grasp_server_url_as_relay_url(url: &str) -> Result<String> { |
| 962 | let ngit_relay_url = normalize_ngit_relay_url(url)?; | 965 | let grasp_server_url = normalize_grasp_server_url(url)?; |
| 963 | if ngit_relay_url.contains("http://") { | 966 | if grasp_server_url.contains("http://") { |
| 964 | return Ok(ngit_relay_url.replace("http://", "ws://")); | 967 | return Ok(grasp_server_url.replace("http://", "ws://")); |
| 965 | } | 968 | } |
| 966 | Ok(format!("wss://{ngit_relay_url}")) | 969 | Ok(format!("wss://{grasp_server_url}")) |
| 967 | } | 970 | } |
| 968 | 971 | ||
| 969 | fn format_ngit_relay_url_as_blossom_url(url: &str) -> Result<String> { | 972 | fn format_grasp_server_url_as_blossom_url(url: &str) -> Result<String> { |
| 970 | let ngit_relay_url = normalize_ngit_relay_url(url)?; | 973 | let grasp_server_url = normalize_grasp_server_url(url)?; |
| 971 | if ngit_relay_url.contains("http://") { | 974 | if grasp_server_url.contains("http://") { |
| 972 | return Ok(ngit_relay_url); | 975 | return Ok(grasp_server_url); |
| 973 | } | 976 | } |
| 974 | Ok(format!("https://{ngit_relay_url}")) | 977 | Ok(format!("https://{grasp_server_url}")) |
| 975 | } | 978 | } |
| 976 | 979 | ||
| 977 | fn parse_relay_url(s: &str) -> Result<RelayUrl> { | 980 | fn parse_relay_url(s: &str) -> Result<RelayUrl> { |