upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/main.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-02-10 13:10:18 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-02-10 13:10:18 +0000
commit1e7aeb4d7972d29c6586df18128a8a4f7667845a (patch)
tree0f7e5fcaa5a005aeec7ae2d9f35b2c473ef8f785 /src/bin/ngit/main.rs
parentd2412565334f48bd31e57d29d7959c24258ccd98 (diff)
parentaae452697d152694a8f163219f707356e84b420b (diff)
Make ngit non-interactive by default
Implements non-interactive mode as the default behavior for ngit. Users must now use -i flag for interactive prompts, or provide all required arguments explicitly. Adds -d flag for sensible defaults and -f flag for force operations. Changes: - CLI interactor infrastructure supports non-interactive mode - Global flags: -i (interactive), --defaults (use defaults), -f (force) - ngit init: requires --name or --identifier, supports --defaults - ngit account: new signup command, login supports non-interactive - ngit send: validates required fields, supports --defaults - git-remote-nostr: fixed to prevent interactive prompts during push - Comprehensive test coverage: 234 unit tests + integration tests
Diffstat (limited to 'src/bin/ngit/main.rs')
-rw-r--r--src/bin/ngit/main.rs26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/bin/ngit/main.rs b/src/bin/ngit/main.rs
index 71b6e85..5d29b02 100644
--- a/src/bin/ngit/main.rs
+++ b/src/bin/ngit/main.rs
@@ -2,13 +2,13 @@
2#![allow(clippy::large_futures)] 2#![allow(clippy::large_futures)]
3#![cfg_attr(not(test), warn(clippy::expect_used))] 3#![cfg_attr(not(test), warn(clippy::expect_used))]
4 4
5use anyhow::Result;
6use clap::Parser; 5use clap::Parser;
7use cli::{AccountCommands, CUSTOMISE_TEMPLATE, Cli, Commands}; 6use cli::{AccountCommands, CUSTOMISE_TEMPLATE, Cli, Commands};
8 7
9mod cli; 8mod cli;
10use ngit::{ 9use ngit::{
11 cli_interactor, client, 10 cli_interactor::{self, CliError},
11 client,
12 git::{self, utils::set_git_timeout}, 12 git::{self, utils::set_git_timeout},
13 git_events, login, repo_ref, 13 git_events, login, repo_ref,
14}; 14};
@@ -16,9 +16,15 @@ use ngit::{
16mod sub_commands; 16mod sub_commands;
17 17
18#[tokio::main] 18#[tokio::main]
19async fn main() -> Result<()> { 19async fn main() {
20 let cli = Cli::parse(); 20 let cli = Cli::parse();
21 21
22 // Non-interactive by default; set NGIT_INTERACTIVE_MODE only when -i is
23 // specified
24 if cli.interactive {
25 std::env::set_var("NGIT_INTERACTIVE_MODE", "1");
26 }
27
22 if cli.customize { 28 if cli.customize {
23 print!("{CUSTOMISE_TEMPLATE}"); 29 print!("{CUSTOMISE_TEMPLATE}");
24 std::process::exit(0); // Exit the program 30 std::process::exit(0); // Exit the program
@@ -26,7 +32,7 @@ async fn main() -> Result<()> {
26 32
27 let _ = set_git_timeout(); 33 let _ = set_git_timeout();
28 34
29 if let Some(command) = &cli.command { 35 let result = if let Some(command) = &cli.command {
30 match command { 36 match command {
31 Commands::Account(args) => match &args.account_command { 37 Commands::Account(args) => match &args.account_command {
32 AccountCommands::Login(sub_args) => { 38 AccountCommands::Login(sub_args) => {
@@ -34,6 +40,9 @@ async fn main() -> Result<()> {
34 } 40 }
35 AccountCommands::Logout => sub_commands::logout::launch().await, 41 AccountCommands::Logout => sub_commands::logout::launch().await,
36 AccountCommands::ExportKeys => sub_commands::export_keys::launch().await, 42 AccountCommands::ExportKeys => sub_commands::export_keys::launch().await,
43 AccountCommands::Create(sub_args) => {
44 sub_commands::create::launch(&cli, sub_args).await
45 }
37 }, 46 },
38 Commands::Init(args) => sub_commands::init::launch(&cli, args).await, 47 Commands::Init(args) => sub_commands::init::launch(&cli, args).await,
39 Commands::List => sub_commands::list::launch().await, 48 Commands::List => sub_commands::list::launch().await,
@@ -44,5 +53,14 @@ async fn main() -> Result<()> {
44 // Handle the case where no command is provided 53 // Handle the case where no command is provided
45 eprintln!("Error: A command must be provided. Use '--help' for more information."); 54 eprintln!("Error: A command must be provided. Use '--help' for more information.");
46 std::process::exit(1); 55 std::process::exit(1);
56 };
57
58 if let Err(err) = result {
59 if err.downcast_ref::<CliError>().is_some() {
60 // Already printed styled output to stderr
61 std::process::exit(1);
62 }
63 eprintln!("Error: {err:?}");
64 std::process::exit(1);
47 } 65 }
48} 66}