disable 'as dependency' if backend does not support it

This commit is contained in:
steven-omaha
2023-02-27 19:54:52 +01:00
parent de06bf6b40
commit e3e193f7e1
8 changed files with 25 additions and 4 deletions
-1
View File
@@ -1,4 +1,3 @@
# To Do
- tutorial
- disable "as dependency" where it is not supported (python, rust)
@@ -23,6 +23,8 @@ const SWITCHES_INSTALL: Switches = &["--sync"];
const SWITCHES_MAKE_DEPENDENCY: Switches = &["--database", "--asdeps"];
const SWITCHES_REMOVE: Switches = &["--remove", "--recursive"];
const SUPPORTS_AS_DEPENDENCY: bool = true;
impl Backend for Arch {
impl_backend_constants!();
@@ -22,6 +22,8 @@ const SWITCHES_INSTALL: Switches = &["install"];
const SWITCHES_MAKE_DEPENDENCY: Switches = &[]; // not needed
const SWITCHES_REMOVE: Switches = &["remove"];
const SUPPORTS_AS_DEPENDENCY: bool = true;
impl Backend for Debian {
impl_backend_constants!();
@@ -22,6 +22,8 @@ const SWITCHES_INSTALL: Switches = &["install"];
const SWITCHES_MAKE_DEPENDENCY: Switches = &[]; // not needed
const SWITCHES_REMOVE: Switches = &["uninstall"];
const SUPPORTS_AS_DEPENDENCY: bool = false;
impl Backend for Python {
impl_backend_constants!();
@@ -16,11 +16,14 @@ pub struct Rust {
const BINARY: Text = "cargo";
const SECTION: Text = "rust";
const SWITCHES_INSTALL: Switches = &["install"];
const SWITCHES_INFO: Switches = &["search", "--limit", "1"];
const SWITCHES_MAKE_DEPENDENCY: Switches = &[];
const SWITCHES_REMOVE: Switches = &["uninstall"];
const SUPPORTS_AS_DEPENDENCY: bool = false;
impl Backend for Rust {
impl_backend_constants!();
@@ -120,6 +120,8 @@ pub trait Backend: Debug {
}
fn as_any_mut(&mut self) -> &mut dyn Any;
fn supports_as_dependency(&self) -> bool;
}
fn get_group_packages_map(
+4
View File
@@ -53,5 +53,9 @@ macro_rules! impl_backend_constants {
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}
fn supports_as_dependency(&self) -> bool {
SUPPORTS_AS_DEPENDENCY
}
};
}
+10 -3
View File
@@ -76,8 +76,9 @@ fn get_action_for_package(
backend: &dyn Backend,
) -> Result<ContinueWithReview> {
loop {
match ask_user_action_for_package()? {
match ask_user_action_for_package(backend.supports_as_dependency())? {
ReviewIntention::AsDependency => {
assert!(!backend.supports_as_dependency());
reviews.push(ReviewAction::AsDependency(package));
break;
}
@@ -102,9 +103,15 @@ fn get_action_for_package(
Ok(ContinueWithReview::Yes)
}
fn ask_user_action_for_package() -> Result<ReviewIntention> {
print!("assign to (g)roup, (d)elete, (s)kip, (i)nfo, (a)s dependency, (q)uit? ");
fn ask_user_action_for_package(supports_as_dependency: bool) -> Result<ReviewIntention> {
print!("assign to (g)roup, (d)elete, (s)kip, (i)nfo, ");
if supports_as_dependency {
print!("(a)s dependency, ");
}
print!("(q)uit? ");
stdout().lock().flush()?;
match read_single_char_from_terminal()? {
'a' => Ok(ReviewIntention::AsDependency),
'd' => Ok(ReviewIntention::Delete),