Comments (1)
I was experimenting with a pattern like
#[async_trait::async_trait]
#[typetag::serde(tag = "action")]
pub trait Action: Send + Sync + std::fmt::Debug + dyn_clone::DynClone {
fn execute_description(&self) -> String;
fn revert_description(&self) -> String;
async fn execute(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
async fn revert(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
fn action_state(&self) -> ActionState;
fn set_action_state(&mut self, new_state: ActionState);
fn explanation(&self) -> Vec<String> {
vec![]
}
// They should also have an `async fn plan(args...) -> Result<ActionState<Self>, Box<dyn std::error::Error + Send + Sync>>;`
}
#[async_trait::async_trait]
trait ActionImplementation: Action {
fn describe_execute(&self) -> Option<String> {
if self.action_state() == ActionState::Completed {
return None;
}
return Some(self.execute_description());
}
fn describe_revert(&self) -> Option<String> {
if self.action_state() == ActionState::Uncompleted {
return None;
}
return Some(self.revert_description());
}
async fn try_execute(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
if self.action_state() == ActionState::Completed {
tracing::trace!("Completed: (Already done) {}", self.execute_description());
return Ok(());
}
self.set_action_state(ActionState::Progress);
tracing::debug!("Executing: {}", self.execute_description());
self.execute().await?;
self.set_action_state(ActionState::Completed);
tracing::debug!("Completed: {}", self.execute_description());
Ok(())
}
async fn try_revert(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
if self.action_state() == ActionState::Uncompleted {
tracing::trace!("Reverted: (Already done) {}", self.revert_description());
return Ok(());
}
self.set_action_state(ActionState::Progress);
tracing::debug!("Reverting: {}", self.revert_description());
self.revert().await?;
tracing::debug!("Reverted: {}", self.revert_description());
self.set_action_state(ActionState::Uncompleted);
Ok(())
}
}
But I feel this doesn't do a great job handling meta-actions such as ProvisionNix
since it can only output that one...
from nix-installer.
Related Issues (20)
- error: path '/home' is a symlink HOT 22
- Nix in DevContainers
- <autogenerated-issue>
- When using Alacritty as a terminal emulator: "Error: 0: Couldn't get terminal" HOT 2
- Installer fails because UID 301 is used by another account HOT 1
- Suggestion: Plan for a silent install HOT 1
- <autogenerated-issue> HOT 1
- <autogenerated-issue> HOT 2
- <autogenerated-issue>
- <autogenerated-issue>
- <autogenerated-issue> HOT 2
- README's recommended "In a container" installation steps don't work HOT 1
- Broken link in upgrade doc
- Uninstalling Error. HOT 2
- Sourcing Nix in /etc/zshenv on MacOs breaks $PATH when SSH
- <autogenerated-issue>
- re-running nix-installer with additional arguments errors HOT 2
- The keychain lacks a password for the already existing "Nix Store" HOT 2
- Install failure on archlinux arm HOT 1
- Not working with github codespaces
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nix-installer.