Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more cli options #4

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,69 @@ pub enum Operations {
Upgrade,
Sync,
AddRepo(AddRepo),
Downgrade(Downgrade),
Resume(Resume),
}

#[derive(Parser, Debug)]
pub struct Install {
#[arg(index = 1)]
#[arg(short = 'p', long = "package", help = "Specify package(s) to install")]
pub pkgs: Vec<String>,

#[arg(short = 'f', long = "force", help = "Force installation")]
pub force: bool,
}

#[derive(Parser, Debug)]
pub struct Remove {
#[arg(index = 1)]
#[arg(short = 'p', long = "package", help = "Specify package(s) to remove")]
pub pkgs: Vec<String>,

#[arg(short = 'y', long = "yes", help = "Automatically answer yes to prompts")]
pub yes: bool,
}

#[derive(Parser, Debug)]
pub struct Search {
#[arg(index = 1)]
#[arg(short = 't', long = "term", help = "Specify search term(s)")]
pub terms: Vec<String>,

#[arg(short = 'a', long = "all", help = "Search all available packages")]
pub all: bool,
}

#[derive(Parser, Debug)]
pub struct Query {
#[arg(index = 1)]
#[arg(short = 't', long = "term", help = "Specify query term(s)")]
pub terms: Vec<String>,

#[arg(short = 'd', long = "details", help = "Show detailed information")]
pub details: bool,
}

#[derive(Parser, Debug)]
pub struct AddRepo {
#[arg(index = 1)]
#[arg(short = 'r', long = "repo", help = "Specify repository URL")]
pub repo: String,

#[arg(short = 'u', long = "update", help = "Update the repository list")]
pub update: bool,
}

#[derive(Parser, Debug)]
pub struct Downgrade {
#[arg(short = 'p', long = "package", help = "Specify package(s) to downgrade")]
pub pkgs: Vec<String>,

#[arg(short = 'v', long = "version", help = "Specify version to downgrade to")]
pub version: Option<String>,
}

#[derive(Parser, Debug)]
pub struct Resume {
#[arg(short = 'a', long = "all", help = "Resume all paused operations")]
pub all: bool,

#[arg(short = 'i', long = "id", help = "Specify ID of the operation to resume")]
pub id: Option<String>,
}
32 changes: 32 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,38 @@ fn print_version() {
fn main() {
let cli = Cli::parse();

// Handle the version flag
if cli.version {
print_version();
return;
}

// Handle the specified operation
if let Some(operation) = cli.operation {
match operation {
Operations::Install(install) => {
println!("Installing packages: {:?}", install.pkgs);
if install.force {
println!("Force installation enabled.");
}
}
Operations::Remove(remove) => {
println!("Removing packages: {:?}", remove.pkgs);
if remove.yes {
println!("Automatic yes to prompts enabled.");
}
}
Operations::Search(search) => {
println!("Searching packages: {:?}", search.terms);
if search.all {
println!("Searching all available packages.");
}
}
Operations::Query(query) => {
println!("Querying packages: {:?}", query.terms);
if query.details {
println!("Detailed information requested.");
}
}
Operations::List => {
println!("Listing packages");
Expand All @@ -54,6 +68,24 @@ fn main() {
}
Operations::AddRepo(add_repo) => {
println!("Adding repository: {}", add_repo.repo);
if add_repo.update {
println!("Updating repository list.");
}
}
Operations::Downgrade(downgrade) => {
println!("Downgrading packages: {:?}", downgrade.pkgs);
if let Some(version) = downgrade.version {
println!("Downgrading to version: {}", version);
}
}
Operations::Resume(resume) => {
if resume.all {
println!("Resuming all paused operations.");
} else if let Some(id) = resume.id {
println!("Resuming operation with ID: {}", id);
} else {
println!("Resuming operation");
}
}
}
} else {
Expand Down