diff options
Diffstat (limited to 'src/bin/ngit')
| -rw-r--r-- | src/bin/ngit/cli.rs | 3 | ||||
| -rw-r--r-- | src/bin/ngit/main.rs | 2 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/repo/mod.rs | 49 |
3 files changed, 34 insertions, 20 deletions
diff --git a/src/bin/ngit/cli.rs b/src/bin/ngit/cli.rs index fa5d906..164035b 100644 --- a/src/bin/ngit/cli.rs +++ b/src/bin/ngit/cli.rs | |||
| @@ -187,6 +187,9 @@ pub struct AccountSubCommandArgs { | |||
| 187 | pub struct RepoSubCommandArgs { | 187 | pub struct RepoSubCommandArgs { |
| 188 | #[command(subcommand)] | 188 | #[command(subcommand)] |
| 189 | pub repo_command: Option<RepoCommands>, | 189 | pub repo_command: Option<RepoCommands>, |
| 190 | /// Use local cache only, skip network fetch | ||
| 191 | #[arg(long)] | ||
| 192 | pub offline: bool, | ||
| 190 | } | 193 | } |
| 191 | 194 | ||
| 192 | #[derive(Subcommand)] | 195 | #[derive(Subcommand)] |
diff --git a/src/bin/ngit/main.rs b/src/bin/ngit/main.rs index 924a714..5a7654a 100644 --- a/src/bin/ngit/main.rs +++ b/src/bin/ngit/main.rs | |||
| @@ -50,7 +50,7 @@ async fn main() { | |||
| 50 | }, | 50 | }, |
| 51 | Commands::Init(args) => sub_commands::init::launch(&cli, args).await, | 51 | Commands::Init(args) => sub_commands::init::launch(&cli, args).await, |
| 52 | Commands::Repo(args) => { | 52 | Commands::Repo(args) => { |
| 53 | sub_commands::repo::launch(&cli, args.repo_command.as_ref()).await | 53 | sub_commands::repo::launch(&cli, args.repo_command.as_ref(), args.offline).await |
| 54 | } | 54 | } |
| 55 | Commands::List { | 55 | Commands::List { |
| 56 | status, | 56 | status, |
diff --git a/src/bin/ngit/sub_commands/repo/mod.rs b/src/bin/ngit/sub_commands/repo/mod.rs index 7914e1d..b15afdb 100644 --- a/src/bin/ngit/sub_commands/repo/mod.rs +++ b/src/bin/ngit/sub_commands/repo/mod.rs | |||
| @@ -23,13 +23,13 @@ use crate::{ | |||
| 23 | sub_commands::init, | 23 | sub_commands::init, |
| 24 | }; | 24 | }; |
| 25 | 25 | ||
| 26 | pub async fn launch(cli_args: &Cli, repo_command: Option<&RepoCommands>) -> Result<()> { | 26 | pub async fn launch(cli_args: &Cli, repo_command: Option<&RepoCommands>, offline: bool) -> Result<()> { |
| 27 | match repo_command { | 27 | match repo_command { |
| 28 | Some(RepoCommands::Init(args) | RepoCommands::Edit(args)) => { | 28 | Some(RepoCommands::Init(args) | RepoCommands::Edit(args)) => { |
| 29 | init::launch(cli_args, args).await | 29 | init::launch(cli_args, args).await |
| 30 | } | 30 | } |
| 31 | Some(RepoCommands::Accept(args)) => accept::launch(cli_args, args).await, | 31 | Some(RepoCommands::Accept(args)) => accept::launch(cli_args, args).await, |
| 32 | None => show_info(cli_args).await, | 32 | None => show_info(cli_args, offline).await, |
| 33 | } | 33 | } |
| 34 | } | 34 | } |
| 35 | 35 | ||
| @@ -37,7 +37,7 @@ pub async fn launch(cli_args: &Cli, repo_command: Option<&RepoCommands>) -> Resu | |||
| 37 | // `ngit repo` (no subcommand) — show repository info | 37 | // `ngit repo` (no subcommand) — show repository info |
| 38 | // --------------------------------------------------------------------------- | 38 | // --------------------------------------------------------------------------- |
| 39 | 39 | ||
| 40 | async fn show_info(cli_args: &Cli) -> Result<()> { | 40 | async fn show_info(cli_args: &Cli, offline: bool) -> Result<()> { |
| 41 | let git_repo = Repo::discover().context("failed to find a git repository")?; | 41 | let git_repo = Repo::discover().context("failed to find a git repository")?; |
| 42 | let git_repo_path = git_repo.get_path()?; | 42 | let git_repo_path = git_repo.get_path()?; |
| 43 | let client = Client::new(Params::with_git_config_relay_defaults(&Some(&git_repo))); | 43 | let client = Client::new(Params::with_git_config_relay_defaults(&Some(&git_repo))); |
| @@ -69,7 +69,9 @@ async fn show_info(cli_args: &Cli) -> Result<()> { | |||
| 69 | // Fetch latest data from relays — suppress the summary line. | 69 | // Fetch latest data from relays — suppress the summary line. |
| 70 | // fetching_quietly writes a blank line to stderr after errors so there | 70 | // fetching_quietly writes a blank line to stderr after errors so there |
| 71 | // is clear separation before the repo info below. | 71 | // is clear separation before the repo info below. |
| 72 | let _ = fetching_quietly(git_repo_path, &client, &repo_coordinate).await; | 72 | if !offline { |
| 73 | let _ = fetching_quietly(git_repo_path, &client, &repo_coordinate).await; | ||
| 74 | } | ||
| 73 | 75 | ||
| 74 | let Some(repo_ref) = | 76 | let Some(repo_ref) = |
| 75 | (get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinate).await).ok() | 77 | (get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinate).await).ok() |
| @@ -95,9 +97,14 @@ async fn print_repo_info( | |||
| 95 | coordinate: &Nip19Coordinate, | 97 | coordinate: &Nip19Coordinate, |
| 96 | git_repo_path: &Path, | 98 | git_repo_path: &Path, |
| 97 | ) { | 99 | ) { |
| 98 | let heading = Style::new().bold(); | 100 | let title = Style::new().bold().yellow(); |
| 101 | let heading = Style::new().bold().dim(); | ||
| 99 | let dim = Style::new().dim(); | 102 | let dim = Style::new().dim(); |
| 100 | 103 | ||
| 104 | let term_width = console::Term::stdout().size().1 as usize; | ||
| 105 | let rule_width = term_width.clamp(20, 60); | ||
| 106 | let rule = dim.apply_to("─".repeat(rule_width)); | ||
| 107 | |||
| 101 | let multi_maintainer = repo_ref.maintainers.len() > 1 | 108 | let multi_maintainer = repo_ref.maintainers.len() > 1 |
| 102 | || repo_ref | 109 | || repo_ref |
| 103 | .maintainers_without_annoucnement | 110 | .maintainers_without_annoucnement |
| @@ -105,38 +112,31 @@ async fn print_repo_info( | |||
| 105 | .is_some_and(|v| !v.is_empty()); | 112 | .is_some_and(|v| !v.is_empty()); |
| 106 | 113 | ||
| 107 | // --- Basic metadata --- | 114 | // --- Basic metadata --- |
| 108 | println!("{}", heading.apply_to(&repo_ref.name)); | 115 | println!("{rule}"); |
| 116 | println!(" {}", title.apply_to(&repo_ref.name)); | ||
| 109 | 117 | ||
| 110 | // Show identifier only when it differs from the name | 118 | // Show identifier only when it differs from the name |
| 111 | let identifier_slug = repo_ref.identifier.to_lowercase().replace(' ', "-"); | 119 | let identifier_slug = repo_ref.identifier.to_lowercase().replace(' ', "-"); |
| 112 | let name_slug = repo_ref.name.to_lowercase().replace(' ', "-"); | 120 | let name_slug = repo_ref.name.to_lowercase().replace(' ', "-"); |
| 113 | if identifier_slug != name_slug { | 121 | if identifier_slug != name_slug { |
| 114 | println!( | 122 | println!( |
| 115 | "{}", | 123 | " {}", |
| 116 | dim.apply_to(format!("identifier: {}", repo_ref.identifier)) | 124 | dim.apply_to(format!("identifier: {}", repo_ref.identifier)) |
| 117 | ); | 125 | ); |
| 118 | } | 126 | } |
| 119 | 127 | ||
| 120 | if !repo_ref.description.is_empty() { | 128 | if !repo_ref.description.is_empty() { |
| 121 | println!("{}", repo_ref.description); | 129 | println!(" {}", repo_ref.description); |
| 122 | } | 130 | } |
| 123 | if !repo_ref.web.is_empty() { | 131 | if !repo_ref.web.is_empty() { |
| 124 | for url in &repo_ref.web { | 132 | for url in &repo_ref.web { |
| 125 | println!("{}", dim.apply_to(url)); | 133 | println!(" {}", dim.apply_to(url)); |
| 126 | } | 134 | } |
| 127 | } | 135 | } |
| 128 | if !repo_ref.hashtags.is_empty() { | 136 | if !repo_ref.hashtags.is_empty() { |
| 129 | println!("{}", dim.apply_to(repo_ref.hashtags.join(" "))); | 137 | println!(" {}", dim.apply_to(repo_ref.hashtags.join(" "))); |
| 130 | } | ||
| 131 | if !repo_ref.root_commit.is_empty() { | ||
| 132 | println!( | ||
| 133 | "{}", | ||
| 134 | dim.apply_to(format!( | ||
| 135 | "earliest unique commit: {}", | ||
| 136 | &repo_ref.root_commit[..7.min(repo_ref.root_commit.len())] | ||
| 137 | )) | ||
| 138 | ); | ||
| 139 | } | 138 | } |
| 139 | println!("{rule}"); | ||
| 140 | println!(); | 140 | println!(); |
| 141 | 141 | ||
| 142 | // --- Maintainers --- | 142 | // --- Maintainers --- |
| @@ -317,6 +317,17 @@ async fn print_repo_info( | |||
| 317 | println!(); | 317 | println!(); |
| 318 | } | 318 | } |
| 319 | 319 | ||
| 320 | if !repo_ref.root_commit.is_empty() { | ||
| 321 | println!( | ||
| 322 | "{}", | ||
| 323 | dim.apply_to(format!( | ||
| 324 | "earliest unique commit: {}", | ||
| 325 | &repo_ref.root_commit[..7.min(repo_ref.root_commit.len())] | ||
| 326 | )) | ||
| 327 | ); | ||
| 328 | println!(); | ||
| 329 | } | ||
| 330 | |||
| 320 | // --- Maintainer model note (only relevant when there are multiple maintainers) --- | 331 | // --- Maintainer model note (only relevant when there are multiple maintainers) --- |
| 321 | if multi_maintainer { | 332 | if multi_maintainer { |
| 322 | println!( | 333 | println!( |