diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-04 08:04:48 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-04 13:30:59 +0100 |
| commit | 949c6459aa7683453a7160423b689ceadb08954b (patch) | |
| tree | 230c26ecb11b99916e5570e548673eb09ecf0a36 /src/sub_commands/login.rs | |
| parent | a825311f2c55661aaab3a163bda9109295c96044 (diff) | |
refactor: organise into lib and bin structure
the make the code more readable
this commit just moves the files, the next commit should fix the imports
Diffstat (limited to 'src/sub_commands/login.rs')
| -rw-r--r-- | src/sub_commands/login.rs | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/src/sub_commands/login.rs b/src/sub_commands/login.rs deleted file mode 100644 index 8a3788f..0000000 --- a/src/sub_commands/login.rs +++ /dev/null | |||
| @@ -1,52 +0,0 @@ | |||
| 1 | use anyhow::{Context, Result}; | ||
| 2 | use clap; | ||
| 3 | |||
| 4 | #[cfg(not(test))] | ||
| 5 | use crate::client::Client; | ||
| 6 | #[cfg(test)] | ||
| 7 | use crate::client::MockConnect; | ||
| 8 | use crate::{cli::Cli, client::Connect, git::Repo, login}; | ||
| 9 | |||
| 10 | #[derive(clap::Args)] | ||
| 11 | pub struct SubCommandArgs { | ||
| 12 | /// don't fetch user metadata and relay list from relays | ||
| 13 | #[arg(long, action)] | ||
| 14 | offline: bool, | ||
| 15 | } | ||
| 16 | |||
| 17 | pub 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 | } | ||