diff options
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/ngit/cli.rs | 9 | ||||
| -rw-r--r-- | src/bin/ngit/main.rs | 19 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/apply.rs | 12 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/checkout.rs | 12 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/list.rs | 16 |
5 files changed, 46 insertions, 22 deletions
diff --git a/src/bin/ngit/cli.rs b/src/bin/ngit/cli.rs index c77e719..85c74cd 100644 --- a/src/bin/ngit/cli.rs +++ b/src/bin/ngit/cli.rs | |||
| @@ -117,11 +117,17 @@ pub enum Commands { | |||
| 117 | json: bool, | 117 | json: bool, |
| 118 | /// Show details for specific proposal (event-id or nevent) | 118 | /// Show details for specific proposal (event-id or nevent) |
| 119 | id: Option<String>, | 119 | id: Option<String>, |
| 120 | /// Use local cache only, skip network fetch | ||
| 121 | #[arg(long)] | ||
| 122 | offline: bool, | ||
| 120 | }, | 123 | }, |
| 121 | /// checkout a proposal branch by event-id or nevent | 124 | /// checkout a proposal branch by event-id or nevent |
| 122 | Checkout { | 125 | Checkout { |
| 123 | /// Proposal event-id (hex) or nevent (bech32) | 126 | /// Proposal event-id (hex) or nevent (bech32) |
| 124 | id: String, | 127 | id: String, |
| 128 | /// Use local cache only, skip network fetch | ||
| 129 | #[arg(long)] | ||
| 130 | offline: bool, | ||
| 125 | }, | 131 | }, |
| 126 | /// apply proposal patches to current branch | 132 | /// apply proposal patches to current branch |
| 127 | Apply { | 133 | Apply { |
| @@ -130,6 +136,9 @@ pub enum Commands { | |||
| 130 | /// Output patches to stdout instead of applying | 136 | /// Output patches to stdout instead of applying |
| 131 | #[arg(long)] | 137 | #[arg(long)] |
| 132 | stdout: bool, | 138 | stdout: bool, |
| 139 | /// Use local cache only, skip network fetch | ||
| 140 | #[arg(long)] | ||
| 141 | offline: bool, | ||
| 133 | }, | 142 | }, |
| 134 | /// update repo git servers to reflect nostr state (add, update or delete | 143 | /// update repo git servers to reflect nostr state (add, update or delete |
| 135 | /// remote refs) | 144 | /// remote refs) |
diff --git a/src/bin/ngit/main.rs b/src/bin/ngit/main.rs index 77ef955..5458251 100644 --- a/src/bin/ngit/main.rs +++ b/src/bin/ngit/main.rs | |||
| @@ -49,13 +49,22 @@ async fn main() { | |||
| 49 | } | 49 | } |
| 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::List { status, json, id } => { | 52 | Commands::List { |
| 53 | sub_commands::list::launch(status.clone(), *json, id.clone()).await | 53 | status, |
| 54 | } | 54 | json, |
| 55 | id, | ||
| 56 | offline, | ||
| 57 | } => sub_commands::list::launch(status.clone(), *json, id.clone(), *offline).await, | ||
| 55 | Commands::Send(args) => sub_commands::send::launch(&cli, args, false).await, | 58 | Commands::Send(args) => sub_commands::send::launch(&cli, args, false).await, |
| 56 | Commands::Sync(args) => sub_commands::sync::launch(args).await, | 59 | Commands::Sync(args) => sub_commands::sync::launch(args).await, |
| 57 | Commands::Checkout { id } => sub_commands::checkout::launch(id).await, | 60 | Commands::Checkout { id, offline } => { |
| 58 | Commands::Apply { id, stdout } => sub_commands::apply::launch(id, *stdout).await, | 61 | sub_commands::checkout::launch(id, *offline).await |
| 62 | } | ||
| 63 | Commands::Apply { | ||
| 64 | id, | ||
| 65 | stdout, | ||
| 66 | offline, | ||
| 67 | } => sub_commands::apply::launch(id, *stdout, *offline).await, | ||
| 59 | } | 68 | } |
| 60 | } else { | 69 | } else { |
| 61 | // Handle the case where no command is provided | 70 | // Handle the case where no command is provided |
diff --git a/src/bin/ngit/sub_commands/apply.rs b/src/bin/ngit/sub_commands/apply.rs index 2d5d8d5..4b13975 100644 --- a/src/bin/ngit/sub_commands/apply.rs +++ b/src/bin/ngit/sub_commands/apply.rs | |||
| @@ -73,7 +73,7 @@ fn run_git_fetch(remote_name: &str) -> Result<()> { | |||
| 73 | Ok(()) | 73 | Ok(()) |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | pub async fn launch(id: &str, stdout: bool) -> Result<()> { | 76 | pub async fn launch(id: &str, stdout: bool, offline: bool) -> Result<()> { |
| 77 | let event_id = parse_event_id(id)?; | 77 | let event_id = parse_event_id(id)?; |
| 78 | 78 | ||
| 79 | let git_repo = Repo::discover().context("failed to find a git repository")?; | 79 | let git_repo = Repo::discover().context("failed to find a git repository")?; |
| @@ -91,10 +91,12 @@ pub async fn launch(id: &str, stdout: bool) -> Result<()> { | |||
| 91 | .ok() | 91 | .ok() |
| 92 | .flatten(); | 92 | .flatten(); |
| 93 | 93 | ||
| 94 | if let Some((remote_name, _)) = &nostr_remote { | 94 | if !offline { |
| 95 | run_git_fetch(remote_name)?; | 95 | if let Some((remote_name, _)) = &nostr_remote { |
| 96 | } else { | 96 | run_git_fetch(remote_name)?; |
| 97 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; | 97 | } else { |
| 98 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; | ||
| 99 | } | ||
| 98 | } | 100 | } |
| 99 | 101 | ||
| 100 | let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; | 102 | let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; |
diff --git a/src/bin/ngit/sub_commands/checkout.rs b/src/bin/ngit/sub_commands/checkout.rs index 2fc9a09..19e39d0 100644 --- a/src/bin/ngit/sub_commands/checkout.rs +++ b/src/bin/ngit/sub_commands/checkout.rs | |||
| @@ -28,7 +28,7 @@ use crate::{ | |||
| 28 | repo_ref::get_repo_coordinates_when_remote_unknown, | 28 | repo_ref::get_repo_coordinates_when_remote_unknown, |
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | pub async fn launch(id: &str) -> Result<()> { | 31 | pub async fn launch(id: &str, offline: bool) -> Result<()> { |
| 32 | let event_id = parse_event_id(id)?; | 32 | let event_id = parse_event_id(id)?; |
| 33 | 33 | ||
| 34 | let git_repo = Repo::discover().context("failed to find a git repository")?; | 34 | let git_repo = Repo::discover().context("failed to find a git repository")?; |
| @@ -44,10 +44,12 @@ pub async fn launch(id: &str) -> Result<()> { | |||
| 44 | .ok() | 44 | .ok() |
| 45 | .flatten(); | 45 | .flatten(); |
| 46 | 46 | ||
| 47 | if let Some((remote_name, _)) = &nostr_remote { | 47 | if !offline { |
| 48 | run_git_fetch(remote_name)?; | 48 | if let Some((remote_name, _)) = &nostr_remote { |
| 49 | } else { | 49 | run_git_fetch(remote_name)?; |
| 50 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; | 50 | } else { |
| 51 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; | ||
| 52 | } | ||
| 51 | } | 53 | } |
| 52 | 54 | ||
| 53 | let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; | 55 | let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; |
diff --git a/src/bin/ngit/sub_commands/list.rs b/src/bin/ngit/sub_commands/list.rs index fc0883a..80eec21 100644 --- a/src/bin/ngit/sub_commands/list.rs +++ b/src/bin/ngit/sub_commands/list.rs | |||
| @@ -95,7 +95,7 @@ fn run_git_fetch(remote_name: &str) -> Result<()> { | |||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | #[allow(clippy::too_many_lines)] | 97 | #[allow(clippy::too_many_lines)] |
| 98 | pub async fn launch(status: String, json: bool, id: Option<String>) -> Result<()> { | 98 | pub async fn launch(status: String, json: bool, id: Option<String>, offline: bool) -> Result<()> { |
| 99 | if std::env::var("NGIT_INTERACTIVE_MODE").is_ok() { | 99 | if std::env::var("NGIT_INTERACTIVE_MODE").is_ok() { |
| 100 | return launch_interactive().await; | 100 | return launch_interactive().await; |
| 101 | } | 101 | } |
| @@ -113,14 +113,16 @@ pub async fn launch(status: String, json: bool, id: Option<String>) -> Result<() | |||
| 113 | .ok() | 113 | .ok() |
| 114 | .flatten(); | 114 | .flatten(); |
| 115 | 115 | ||
| 116 | if let Some((remote_name, _)) = &nostr_remote { | 116 | if !offline { |
| 117 | if std::env::var("NGITTEST").is_ok() { | 117 | if let Some((remote_name, _)) = &nostr_remote { |
| 118 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; | 118 | if std::env::var("NGITTEST").is_ok() { |
| 119 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; | ||
| 120 | } else { | ||
| 121 | run_git_fetch(remote_name)?; | ||
| 122 | } | ||
| 119 | } else { | 123 | } else { |
| 120 | run_git_fetch(remote_name)?; | 124 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; |
| 121 | } | 125 | } |
| 122 | } else { | ||
| 123 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; | ||
| 124 | } | 126 | } |
| 125 | 127 | ||
| 126 | let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; | 128 | let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; |