diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2023-05-21 11:27:04 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2023-05-21 11:27:04 +0000 |
| commit | 318e467b158b158cf9eb843318dc14141d1b8c54 (patch) | |
| tree | 46ec99fccfac487b1ff2dd29d3b01fb970fcb88d /src/main.rs | |
| parent | 2ce71c5434fb7245aad4d070e08bbf6792d79b4d (diff) | |
main and remaining subcommands
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e819b5a --- /dev/null +++ b/src/main.rs | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | use clap::{Parser, Subcommand}; | ||
| 2 | use nostr_sdk::Result; | ||
| 3 | |||
| 4 | mod branch_refs; | ||
| 5 | mod sub_commands; | ||
| 6 | mod funcs; | ||
| 7 | mod fetch_pull_push; | ||
| 8 | mod groups; | ||
| 9 | mod merge; | ||
| 10 | mod pull_request; | ||
| 11 | mod repos; | ||
| 12 | mod patch; | ||
| 13 | mod ngit_tag; | ||
| 14 | mod kind; | ||
| 15 | mod utils; | ||
| 16 | mod config; | ||
| 17 | mod repo_config; | ||
| 18 | mod cli_helpers; | ||
| 19 | |||
| 20 | /// Simple CLI application to use git through nostr | ||
| 21 | #[derive(Parser)] | ||
| 22 | #[command(name = "ngit")] | ||
| 23 | #[command(author = "DanConwayDev <DanConwayDev@protonmail.com")] | ||
| 24 | #[command(version = "0.0.1")] | ||
| 25 | #[command(author, version, about, long_about = None)] | ||
| 26 | struct Cli { | ||
| 27 | #[command(subcommand)] | ||
| 28 | command: Commands, | ||
| 29 | /// Relay to connect to | ||
| 30 | #[arg(short, long, action = clap::ArgAction::Append)] | ||
| 31 | relays: Vec<String>, | ||
| 32 | } | ||
| 33 | |||
| 34 | #[derive(Subcommand)] | ||
| 35 | enum Commands { | ||
| 36 | /// Initialize a repoistory | ||
| 37 | Clone(sub_commands::clone::CloneSubCommand), | ||
| 38 | /// Initialize a repoistory | ||
| 39 | Init(sub_commands::init::InitSubCommand), | ||
| 40 | /// Pull to events and relays | ||
| 41 | Pull(sub_commands::pull::PullSubCommand), | ||
| 42 | /// Push to events and relays | ||
| 43 | Push(sub_commands::push::PushSubCommand), | ||
| 44 | /// Merge to events and relays | ||
| 45 | Merge(sub_commands::merge::MergeSubCommand), | ||
| 46 | /// Fetch from relays | ||
| 47 | Fetch(sub_commands::fetch::FetchSubCommand), | ||
| 48 | /// View active PRs from relays | ||
| 49 | Prs(sub_commands::prs::PrsSubCommand), | ||
| 50 | /// rebroadcast all repository events | ||
| 51 | Rebroadcast(sub_commands::rebroadcast::RebroadcastSubCommand), | ||
| 52 | ChangeUser(sub_commands::change_user::ChangeUserSubCommand), | ||
| 53 | } | ||
| 54 | |||
| 55 | fn main() -> Result<()> { | ||
| 56 | println!("ngit prototype v0.0.1-alpha"); | ||
| 57 | // Parse input | ||
| 58 | let args: Cli = Cli::parse(); | ||
| 59 | |||
| 60 | // Post event | ||
| 61 | match &args.command { | ||
| 62 | Commands::Init(sub_command_args) => sub_commands::init::create_and_broadcast_init( | ||
| 63 | args.relays, | ||
| 64 | sub_command_args, | ||
| 65 | ), | ||
| 66 | Commands::Clone(sub_command_args) => { | ||
| 67 | sub_commands::clone::clone_from_relays( | ||
| 68 | args.relays, | ||
| 69 | sub_command_args, | ||
| 70 | ); | ||
| 71 | Ok(()) | ||
| 72 | }, | ||
| 73 | Commands::Pull(sub_command_args) => { | ||
| 74 | sub_commands::pull::pull_from_relays( | ||
| 75 | None, | ||
| 76 | sub_command_args, | ||
| 77 | ); | ||
| 78 | Ok(()) | ||
| 79 | }, | ||
| 80 | Commands::Push(sub_command_args) => { | ||
| 81 | sub_commands::push::push( | ||
| 82 | sub_command_args, | ||
| 83 | ); | ||
| 84 | Ok(()) | ||
| 85 | } | ||
| 86 | Commands::Merge(sub_command_args) => { | ||
| 87 | sub_commands::merge::merge( | ||
| 88 | sub_command_args, | ||
| 89 | ); | ||
| 90 | Ok(()) | ||
| 91 | } | ||
| 92 | Commands::Fetch(_sub_command_args) => { | ||
| 93 | sub_commands::fetch::fetch_from_relays(None); | ||
| 94 | Ok(()) | ||
| 95 | }, | ||
| 96 | Commands::Prs(sub_command_args) => { | ||
| 97 | sub_commands::prs::prs( | ||
| 98 | sub_command_args, | ||
| 99 | ); | ||
| 100 | Ok(()) | ||
| 101 | } | ||
| 102 | Commands::Rebroadcast(sub_command_args) => { | ||
| 103 | sub_commands::rebroadcast::rebroadcast( | ||
| 104 | sub_command_args, | ||
| 105 | ); | ||
| 106 | Ok(()) | ||
| 107 | } | ||
| 108 | Commands::ChangeUser(sub_command_args) => { | ||
| 109 | sub_commands::change_user::change_user( | ||
| 110 | sub_command_args, | ||
| 111 | ); | ||
| 112 | Ok(()) | ||
| 113 | } | ||
| 114 | } | ||
| 115 | } | ||