upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-11-27 09:42:37 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-11-27 09:44:24 +0000
commitcb92d2ac8a7e014eac28ddf9ad1e6500b840739f (patch)
tree15fc284c905a9ac636fada066ed3caa933ce562f
parentc002cef1e5d19946244086531f1178446fed8545 (diff)
feat(account): move login/out cmds to account
move login, logout export-keys commands to sub commands under account
-rw-r--r--src/bin/ngit/cli.rs16
-rw-r--r--src/bin/ngit/main.rs12
-rw-r--r--tests/ngit_login.rs25
3 files changed, 34 insertions, 19 deletions
diff --git a/src/bin/ngit/cli.rs b/src/bin/ngit/cli.rs
index fce5664..851dd70 100644
--- a/src/bin/ngit/cli.rs
+++ b/src/bin/ngit/cli.rs
@@ -57,8 +57,6 @@ pub enum Commands {
57 Fetch(sub_commands::fetch::SubCommandArgs), 57 Fetch(sub_commands::fetch::SubCommandArgs),
58 /// signal you are this repo's maintainer accepting proposals via nostr 58 /// signal you are this repo's maintainer accepting proposals via nostr
59 Init(sub_commands::init::SubCommandArgs), 59 Init(sub_commands::init::SubCommandArgs),
60 /// export nostr keys to login to other nostr clients
61 ExportKeys,
62 /// issue commits as a proposal 60 /// issue commits as a proposal
63 Send(sub_commands::send::SubCommandArgs), 61 Send(sub_commands::send::SubCommandArgs),
64 /// list proposals; checkout, apply or download selected 62 /// list proposals; checkout, apply or download selected
@@ -67,8 +65,22 @@ pub enum Commands {
67 Push(sub_commands::push::SubCommandArgs), 65 Push(sub_commands::push::SubCommandArgs),
68 /// fetch and apply new proposal commits / revisions linked to branch 66 /// fetch and apply new proposal commits / revisions linked to branch
69 Pull, 67 Pull,
68 /// login, logout or export keys
69 Account(AccountSubCommandArgs),
70}
71
72#[derive(Subcommand)]
73pub enum AccountCommands {
70 /// run with --nsec flag to change npub 74 /// run with --nsec flag to change npub
71 Login(sub_commands::login::SubCommandArgs), 75 Login(sub_commands::login::SubCommandArgs),
72 /// remove nostr account details stored in git config 76 /// remove nostr account details stored in git config
73 Logout, 77 Logout,
78 /// export nostr keys to login to other nostr clients
79 ExportKeys,
80}
81
82#[derive(clap::Parser)]
83pub struct AccountSubCommandArgs {
84 #[command(subcommand)]
85 pub account_command: AccountCommands,
74} 86}
diff --git a/src/bin/ngit/main.rs b/src/bin/ngit/main.rs
index cdd0e97..a49267b 100644
--- a/src/bin/ngit/main.rs
+++ b/src/bin/ngit/main.rs
@@ -4,7 +4,7 @@
4 4
5use anyhow::Result; 5use anyhow::Result;
6use clap::Parser; 6use clap::Parser;
7use cli::{Cli, Commands}; 7use cli::{AccountCommands, Cli, Commands};
8 8
9mod cli; 9mod cli;
10use ngit::{cli_interactor, client, git, git_events, login, repo_ref}; 10use ngit::{cli_interactor, client, git, git_events, login, repo_ref};
@@ -15,14 +15,16 @@ mod sub_commands;
15async fn main() -> Result<()> { 15async fn main() -> Result<()> {
16 let cli = Cli::parse(); 16 let cli = Cli::parse();
17 match &cli.command { 17 match &cli.command {
18 Commands::Account(args) => match &args.account_command {
19 AccountCommands::Login(sub_args) => sub_commands::login::launch(&cli, sub_args).await,
20 AccountCommands::Logout => sub_commands::logout::launch().await,
21 AccountCommands::ExportKeys => sub_commands::export_keys::launch().await,
22 },
18 Commands::Fetch(args) => sub_commands::fetch::launch(&cli, args).await, 23 Commands::Fetch(args) => sub_commands::fetch::launch(&cli, args).await,
19 Commands::Login(args) => sub_commands::login::launch(&cli, args).await,
20 Commands::Logout => sub_commands::logout::launch().await,
21 Commands::Init(args) => sub_commands::init::launch(&cli, args).await, 24 Commands::Init(args) => sub_commands::init::launch(&cli, args).await,
22 Commands::ExportKeys => sub_commands::export_keys::launch().await,
23 Commands::Send(args) => sub_commands::send::launch(&cli, args, false).await,
24 Commands::List => sub_commands::list::launch().await, 25 Commands::List => sub_commands::list::launch().await,
25 Commands::Pull => sub_commands::pull::launch().await, 26 Commands::Pull => sub_commands::pull::launch().await,
26 Commands::Push(args) => sub_commands::push::launch(&cli, args).await, 27 Commands::Push(args) => sub_commands::push::launch(&cli, args).await,
28 Commands::Send(args) => sub_commands::send::launch(&cli, args, false).await,
27 } 29 }
28} 30}
diff --git a/tests/ngit_login.rs b/tests/ngit_login.rs
index 0a8bc19..3d74c4a 100644
--- a/tests/ngit_login.rs
+++ b/tests/ngit_login.rs
@@ -38,7 +38,7 @@ fn first_time_login_choices_succeeds_with_nsec(p: &mut CliTester, nsec: &str) ->
38 38
39fn standard_first_time_login_with_nsec() -> Result<CliTester> { 39fn standard_first_time_login_with_nsec() -> Result<CliTester> {
40 let test_repo = GitTestRepo::default(); 40 let test_repo = GitTestRepo::default();
41 let mut p = CliTester::new_from_dir(&test_repo.dir, ["login", "--offline"]); 41 let mut p = CliTester::new_from_dir(&test_repo.dir, ["account", "login", "--offline"]);
42 42
43 first_time_login_choices_succeeds_with_nsec(&mut p, TEST_KEY_1_NSEC)?; 43 first_time_login_choices_succeeds_with_nsec(&mut p, TEST_KEY_1_NSEC)?;
44 44
@@ -77,7 +77,7 @@ mod with_relays {
77 77
78 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 78 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
79 let test_repo = GitTestRepo::default(); 79 let test_repo = GitTestRepo::default();
80 let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); 80 let mut p = CliTester::new_from_dir(&test_repo.dir, ["account", "login"]);
81 81
82 first_time_login_choices_succeeds_with_nsec(&mut p, TEST_KEY_1_NSEC)?; 82 first_time_login_choices_succeeds_with_nsec(&mut p, TEST_KEY_1_NSEC)?;
83 83
@@ -108,7 +108,7 @@ mod with_relays {
108 108
109 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 109 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
110 let test_repo = GitTestRepo::default(); 110 let test_repo = GitTestRepo::default();
111 let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); 111 let mut p = CliTester::new_from_dir(&test_repo.dir, ["account", "login"]);
112 112
113 first_time_login_choices_succeeds_with_nsec(&mut p, TEST_KEY_1_NSEC)?; 113 first_time_login_choices_succeeds_with_nsec(&mut p, TEST_KEY_1_NSEC)?;
114 114
@@ -416,7 +416,7 @@ mod with_relays {
416 let test_repo = GitTestRepo::default(); 416 let test_repo = GitTestRepo::default();
417 let mut p = CliTester::new_from_dir( 417 let mut p = CliTester::new_from_dir(
418 &test_repo.dir, 418 &test_repo.dir,
419 ["login", "--nsec", TEST_KEY_1_NSEC], 419 ["account", "login", "--nsec", TEST_KEY_1_NSEC],
420 ); 420 );
421 421
422 p.expect("saved login details to local git config. you are only logged in to this local repository.\r\n")?; 422 p.expect("saved login details to local git config. you are only logged in to this local repository.\r\n")?;
@@ -458,7 +458,7 @@ mod with_relays {
458 458
459 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 459 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
460 let test_repo = GitTestRepo::default(); 460 let test_repo = GitTestRepo::default();
461 let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); 461 let mut p = CliTester::new_from_dir(&test_repo.dir, ["account", "login"]);
462 462
463 first_time_login_choices_succeeds_with_nsec(&mut p, TEST_KEY_1_NSEC)?; 463 first_time_login_choices_succeeds_with_nsec(&mut p, TEST_KEY_1_NSEC)?;
464 464
@@ -512,7 +512,7 @@ mod with_relays {
512 512
513 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 513 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
514 let test_repo = GitTestRepo::default(); 514 let test_repo = GitTestRepo::default();
515 let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); 515 let mut p = CliTester::new_from_dir(&test_repo.dir, ["account", "login"]);
516 516
517 first_time_login_choices_succeeds_with_nsec(&mut p, TEST_KEY_1_NSEC)?; 517 first_time_login_choices_succeeds_with_nsec(&mut p, TEST_KEY_1_NSEC)?;
518 518
@@ -553,7 +553,7 @@ mod with_relays {
553 553
554 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 554 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
555 let test_repo = GitTestRepo::default(); 555 let test_repo = GitTestRepo::default();
556 let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); 556 let mut p = CliTester::new_from_dir(&test_repo.dir, ["account", "login"]);
557 557
558 first_time_login_choices_succeeds_with_nsec(&mut p, TEST_KEY_1_NSEC)?; 558 first_time_login_choices_succeeds_with_nsec(&mut p, TEST_KEY_1_NSEC)?;
559 559
@@ -628,7 +628,7 @@ mod with_offline_flag {
628 #[test] 628 #[test]
629 fn succeeds_with_text_logged_in_as_npub() -> Result<()> { 629 fn succeeds_with_text_logged_in_as_npub() -> Result<()> {
630 let test_repo = GitTestRepo::default(); 630 let test_repo = GitTestRepo::default();
631 let mut p = CliTester::new_from_dir(&test_repo.dir, ["login", "--offline"]); 631 let mut p = CliTester::new_from_dir(&test_repo.dir, ["account", "login", "--offline"]);
632 632
633 show_first_time_login_choices(&mut p)?.succeeds_with(0, false, Some(0))?; 633 show_first_time_login_choices(&mut p)?.succeeds_with(0, false, Some(0))?;
634 634
@@ -643,7 +643,7 @@ mod with_offline_flag {
643 #[test] 643 #[test]
644 fn succeeds_with_hex_secret_key_in_place_of_nsec() -> Result<()> { 644 fn succeeds_with_hex_secret_key_in_place_of_nsec() -> Result<()> {
645 let test_repo = GitTestRepo::default(); 645 let test_repo = GitTestRepo::default();
646 let mut p = CliTester::new_from_dir(&test_repo.dir, ["login", "--offline"]); 646 let mut p = CliTester::new_from_dir(&test_repo.dir, ["account", "login", "--offline"]);
647 647
648 show_first_time_login_choices(&mut p)?.succeeds_with(0, false, Some(0))?; 648 show_first_time_login_choices(&mut p)?.succeeds_with(0, false, Some(0))?;
649 649
@@ -661,7 +661,8 @@ mod with_offline_flag {
661 #[test] 661 #[test]
662 fn prompts_for_nsec_until_valid() -> Result<()> { 662 fn prompts_for_nsec_until_valid() -> Result<()> {
663 let test_repo = GitTestRepo::default(); 663 let test_repo = GitTestRepo::default();
664 let mut p = CliTester::new_from_dir(&test_repo.dir, ["login", "--offline"]); 664 let mut p =
665 CliTester::new_from_dir(&test_repo.dir, ["account", "login", "--offline"]);
665 666
666 show_first_time_login_choices(&mut p)?.succeeds_with(0, false, Some(0))?; 667 show_first_time_login_choices(&mut p)?.succeeds_with(0, false, Some(0))?;
667 668
@@ -698,7 +699,7 @@ mod with_offline_flag {
698 let test_repo = GitTestRepo::default(); 699 let test_repo = GitTestRepo::default();
699 let mut p = CliTester::new_from_dir( 700 let mut p = CliTester::new_from_dir(
700 &test_repo.dir, 701 &test_repo.dir,
701 ["login", "--offline", "--nsec", TEST_KEY_1_NSEC], 702 ["account", "login", "--offline", "--nsec", TEST_KEY_1_NSEC],
702 ); 703 );
703 704
704 p.expect("saved login details to local git config. you are only logged in to this local repository.\r\n")?; 705 p.expect("saved login details to local git config. you are only logged in to this local repository.\r\n")?;
@@ -713,7 +714,7 @@ mod with_offline_flag {
713 let test_repo = GitTestRepo::default(); 714 let test_repo = GitTestRepo::default();
714 let mut p = CliTester::new_from_dir( 715 let mut p = CliTester::new_from_dir(
715 &test_repo.dir, 716 &test_repo.dir,
716 ["login", "--offline", "--nsec", TEST_INVALID_NSEC], 717 ["account", "login", "--offline", "--nsec", TEST_INVALID_NSEC],
717 ); 718 );
718 719
719 p.expect_end_with( 720 p.expect_end_with(