refactor
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
pub const EDIT: &str = "edit";
|
||||
pub const GROUPS: &str = "groups";
|
||||
pub const SYNC: &str = "sync";
|
||||
pub const UNMANAGED: &str = "unmanaged";
|
||||
pub const VERSION: &str = "version";
|
||||
+2
-6
@@ -1,10 +1,6 @@
|
||||
use clap::{Arg, Command};
|
||||
|
||||
pub const EDIT: &str = "edit";
|
||||
pub const GROUPS: &str = "groups";
|
||||
pub const SYNC: &str = "sync";
|
||||
pub const UNMANAGED: &str = "unmanaged";
|
||||
pub const VERSION: &str = "version";
|
||||
use crate::action::*;
|
||||
|
||||
fn get_arg_parser() -> Command<'static> {
|
||||
let result = Command::new("pacdef")
|
||||
@@ -28,6 +24,6 @@ fn get_arg_parser() -> Command<'static> {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn get_matched_arguments() -> clap::ArgMatches {
|
||||
pub fn get_args() -> clap::ArgMatches {
|
||||
get_arg_parser().get_matches()
|
||||
}
|
||||
|
||||
+6
-6
@@ -2,7 +2,7 @@ use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
|
||||
use crate::args;
|
||||
use crate::action;
|
||||
use crate::cmd::run_install_command;
|
||||
use crate::db::{get_all_installed_packages, get_explicitly_installed_packages};
|
||||
use crate::group::{Group, GROUPS_DIR};
|
||||
@@ -64,11 +64,11 @@ impl Pacdef {
|
||||
pub fn run_action_from_arg(self) {
|
||||
match self.args.subcommand() {
|
||||
// Some((args::EDIT, groups)) => println!("{groups:#?}"),
|
||||
Some((args::EDIT, groups)) => self.edit_group_files(groups),
|
||||
Some((args::GROUPS, _)) => self.show_groups(),
|
||||
Some((args::SYNC, _)) => self.install_packages(),
|
||||
Some((args::UNMANAGED, _)) => self.show_unmanaged_packages(),
|
||||
Some((args::VERSION, _)) => self.show_version(),
|
||||
Some((action::EDIT, groups)) => self.edit_group_files(groups),
|
||||
Some((action::GROUPS, _)) => self.show_groups(),
|
||||
Some((action::SYNC, _)) => self.install_packages(),
|
||||
Some((action::UNMANAGED, _)) => self.show_unmanaged_packages(),
|
||||
Some((action::VERSION, _)) => self.show_version(),
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
mod action;
|
||||
pub mod args;
|
||||
mod cmd;
|
||||
mod core;
|
||||
@@ -7,6 +8,6 @@ mod package;
|
||||
mod ui;
|
||||
|
||||
pub use crate::core::Pacdef;
|
||||
pub use args::get_matched_arguments;
|
||||
pub use args::get_args;
|
||||
pub use group::Group;
|
||||
pub use package::Package;
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ use anyhow::Result;
|
||||
use pacdef::{args, Group, Pacdef};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = args::get_matched_arguments();
|
||||
let args = args::get_args();
|
||||
let groups = Group::load_from_dir();
|
||||
let pacdef = Pacdef::new(args, groups);
|
||||
pacdef.run_action_from_arg();
|
||||
|
||||
Reference in New Issue
Block a user