git flow was a mistake #11

Merged
cafkafk merged 29 commits from dev into main 2023-08-09 16:27:57 +02:00
2 changed files with 44 additions and 49 deletions
Showing only changes of commit 5cc54e23f5 - Show all commits

View file

@ -72,6 +72,9 @@ pub struct Args {
#[arg(short, long)] #[arg(short, long)]
pub no_emoji: bool, pub no_emoji: bool,
#[arg(short, long)]
pub message: Option<String>,
#[command(subcommand)] #[command(subcommand)]
pub command: Option<Commands>, pub command: Option<Commands>,
} }
@ -80,39 +83,38 @@ pub struct Args {
pub enum Commands { pub enum Commands {
/// Link all... links /// Link all... links
#[command(visible_alias = "l")] #[command(visible_alias = "l")]
Link { msg: Option<String> }, Link {},
/// Do quick pull-commit-push with msg for commit /// Do quick pull-commit-push with msg for commit
#[command(visible_alias = "q")] #[command(visible_alias = "q")]
Quick { Quick {
category: Option<String>, category: Option<String>,
repo: Option<String>, repo: Option<String>,
msg: Option<String>,
}, },
/// Do fast pull-commit-push with msg for commit, skipping repo on failure /// Do fast pull-commit-push with msg for commit, skipping repo on failure
#[command(visible_alias = "f")] #[command(visible_alias = "f")]
Fast { msg: Option<String> }, Fast {},
/// Clone all repositories /// Clone all repositories
#[command(visible_alias = "c")] #[command(visible_alias = "c")]
Clone { msg: Option<String> }, Clone {},
/// Pull all repositories /// Pull all repositories
#[command(visible_alias = "p")] #[command(visible_alias = "p")]
Pull { msg: Option<String> }, Pull {},
/// Add all files in repositories /// Add all files in repositories
#[command(visible_alias = "a")] #[command(visible_alias = "a")]
Add { msg: Option<String> }, Add {},
/// Perform a git commit in all repositories /// Perform a git commit in all repositories
#[command(visible_alias = "ct")] #[command(visible_alias = "ct")]
Commit { msg: Option<String> }, Commit {},
/// Perform a git commit in all repositories, with predefined message /// Perform a git commit in all repositories, with predefined message
#[command(visible_alias = "m")] #[command(visible_alias = "m")]
CommitMsg { msg: Option<String> }, CommitMsg {},
/// Jump to a given object /// Jump to a given object
#[command(subcommand, visible_alias = "j")] #[command(subcommand, visible_alias = "j")]

View file

@ -62,16 +62,25 @@ fn main() {
pretty_env_logger::init(); pretty_env_logger::init();
let mut args = Args::parse(); let mut args = Args::parse();
let config = Config::new(&args.config); let config = Config::new(&args.config);
// Input from -m flag is stored here, this is just used to construct the
// persistent box
let mut message_input: String = "".to_string();
match &args { match &args {
args if args.license => println!("{}", utils::strings::INTERACTIVE_LICENSE), args if args.license => println!("{}", utils::strings::INTERACTIVE_LICENSE),
args if args.warranty => println!("{}", utils::strings::INTERACTIVE_WARRANTY), args if args.warranty => println!("{}", utils::strings::INTERACTIVE_WARRANTY),
args if args.code_of_conduct => println!("{}", utils::strings::INTERACTIVE_COC), args if args.code_of_conduct => println!("{}", utils::strings::INTERACTIVE_COC),
args if args.quiet => settings::QUIET.store(true, Ordering::Relaxed), args if args.quiet => settings::QUIET.store(true, Ordering::Relaxed),
args if args.no_emoji => settings::EMOJIS.store(true, Ordering::Relaxed), args if args.no_emoji => settings::EMOJIS.store(true, Ordering::Relaxed),
args if args.message.is_some() => message_input = args.message.clone().unwrap(),
_ => (), _ => (),
} }
let message = Box::leak(message_input.into_boxed_str());
match &mut args.command { match &mut args.command {
Some(Commands::Link { msg: _ }) => { Some(Commands::Link {}) => {
config.link_all(); config.link_all();
} }
// NOTE: This implements "sub-subcommand"-like matching on repository, // NOTE: This implements "sub-subcommand"-like matching on repository,
@ -91,64 +100,48 @@ fn main() {
// - [ ] gg quick category // - [ ] gg quick category
// - [ ] gg quick category repository // - [ ] gg quick category repository
// - [ ] gg quick category repository "stuff" // - [ ] gg quick category repository "stuff"
Some(Commands::Quick { //
category, // Roadmap:
repo, // - [-] basic command parsing
msg, // - [ ] lacks -m flag
}) => match (&category, &repo, &msg) { // - [ ] ability to run command on repos in category
// - [ ] ability to run command on single repo
Some(Commands::Quick { category, repo }) => match (&category, &repo) {
// - gg quick // - gg quick
(None, None, None) => { (None, None) => {
let s = Box::leak( config.quick(message);
msg.as_mut()
.get_or_insert(&mut QUICK_COMMIT.to_string())
.clone()
.into_boxed_str(),
);
config.quick(s);
} }
// - [ ] gg quick category // - [ ] gg quick category
(category, None, None) => { (category, None) => {
println!("{}", category.as_ref().unwrap()); println!("{}", category.as_ref().unwrap());
todo!(); todo!();
} }
(category, repo, None) => { (category, repo) => {
println!("{} {}", category.as_ref().unwrap(), repo.as_ref().unwrap()); println!("{} {}", category.as_ref().unwrap(), repo.as_ref().unwrap());
todo!(); todo!();
} } // // - [ ] gg quick category categorysitory "stuff"
// - [ ] gg quick category categorysitory "stuff" // (category, repo) => {
(category, repo, msg) => { // println!("{} {}", category.as_ref().unwrap(), repo.as_ref().unwrap(),);
println!( // todo!();
"{} {} {}", // }
category.as_ref().unwrap(),
repo.as_ref().unwrap(),
msg.as_ref().unwrap(),
);
todo!();
}
}, },
Some(Commands::Fast { msg }) => { Some(Commands::Fast {}) => {
let s = Box::leak( config.fast(message);
msg.as_mut()
.get_or_insert(&mut FAST_COMMIT.to_string())
.clone()
.into_boxed_str(),
);
config.fast(s);
} }
Some(Commands::Clone { msg: _ }) => { Some(Commands::Clone {}) => {
config.clone_all(); config.clone_all();
} }
Some(Commands::Pull { msg: _ }) => { Some(Commands::Pull {}) => {
config.pull_all(); config.pull_all();
} }
Some(Commands::Add { msg: _ }) => { Some(Commands::Add {}) => {
config.add_all(); config.add_all();
} }
Some(Commands::Commit { msg: _ }) => { Some(Commands::Commit {}) => {
config.commit_all(); config.commit_all();
} }
Some(Commands::CommitMsg { msg }) => { Some(Commands::CommitMsg {}) => {
config.commit_all_msg(msg.as_ref().expect("failed to get message from input")); config.commit_all_msg(message);
} }
Some(Commands::Jump(cmd)) => match cmd { Some(Commands::Jump(cmd)) => match cmd {
JumpCommands::Repo { category, name } => { JumpCommands::Repo { category, name } => {