upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/sub_commands/login.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/ngit/sub_commands/login.rs')
-rw-r--r--src/bin/ngit/sub_commands/login.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/bin/ngit/sub_commands/login.rs b/src/bin/ngit/sub_commands/login.rs
new file mode 100644
index 0000000..8a3788f
--- /dev/null
+++ b/src/bin/ngit/sub_commands/login.rs
@@ -0,0 +1,52 @@
1use anyhow::{Context, Result};
2use clap;
3
4#[cfg(not(test))]
5use crate::client::Client;
6#[cfg(test)]
7use crate::client::MockConnect;
8use crate::{cli::Cli, client::Connect, git::Repo, login};
9
10#[derive(clap::Args)]
11pub struct SubCommandArgs {
12 /// don't fetch user metadata and relay list from relays
13 #[arg(long, action)]
14 offline: bool,
15}
16
17pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> {
18 let git_repo = Repo::discover().context("cannot find a git repository")?;
19 if command_args.offline {
20 login::launch(
21 &git_repo,
22 &args.bunker_uri,
23 &args.bunker_app_key,
24 &args.nsec,
25 &args.password,
26 None,
27 true,
28 false,
29 )
30 .await?;
31 Ok(())
32 } else {
33 #[cfg(not(test))]
34 let client = Client::default();
35 #[cfg(test)]
36 let client = <MockConnect as std::default::Default>::default();
37
38 login::launch(
39 &git_repo,
40 &args.bunker_uri,
41 &args.bunker_app_key,
42 &args.nsec,
43 &args.password,
44 Some(&client),
45 true,
46 false,
47 )
48 .await?;
49 client.disconnect().await?;
50 Ok(())
51 }
52}