Onset: version control where nobody waits and nothing gets lost. The on command, its core and onset-server.
| 5 | use vcs_core::version::Version; |
| 6 |
| 7 | use crate::app::App; |
| 8 | use crate::db::{Change, Db, Project}; |
| 9 | use crate::host::{Host, LandRequest, Landed}; |
| 10 | use crate::objects::Store; |
| 11 | use crate::out::Fail; |
| 12 |
| 13 | pub struct Remote { |
| 14 | pub api: String, |
| 15 | } |
| 16 |
| 17 | impl Remote { |
| 18 | pub fn for_project(project: &Project) -> Remote { |
| 19 | Remote { api: project.api.clone().unwrap_or_default() } |
| 20 | } |
| 21 |
| 22 | pub fn fetch_change(&self, _db: &Db, _store: &Store, _project: &Project, _prefix: &str) -> Result<Option<Change>> { |
| 23 | Ok(None) |
| 24 | } |
| 25 |
| 26 | pub fn fetch_saves(&self, _db: &Db, _store: &Store, _project: &Project, _change: &Change) -> Result<()> { |
| 27 | Ok(()) |
| 28 | } |
| 29 | } |
| 30 |
| 31 | impl Host for Remote { |
| 32 | fn refresh(&self, db: &Db, _store: &Store, project: &Project) -> Result<Option<Version>> { |
| 33 | db.latest_version(&project.id) |
| 34 | } |
| 35 |
| 36 | fn fetch_tree(&self, _store: &Store, _project: &Project, _tree: &Id, _have: Option<&Id>) -> Result<()> { |
| 37 | Ok(()) |
| 38 | } |
| 39 |
| 40 | fn land(&self, _db: &Db, _store: &Store, _project: &Project, _request: &LandRequest) -> Result<Landed> { |
| 41 | Err(anyhow::anyhow!("hosted projects aren't available yet")) |
| 42 | } |
| 43 | } |
| 44 |
| 45 | /// The signed-in account for a project's host: (name, email). |
| 46 | pub fn account(_project: &Project) -> Option<(String, String)> { |
| 47 | None |
| 48 | } |
| 49 |
| 50 | pub fn project(_app: &App, target: &str) -> Result<Project, Fail> { |
| 51 | Err(Fail::new("not_found", format!("can't reach {target}")).state("nothing changed")) |
| 52 | } |
| 53 |
| 54 | /// Changes this person can see in the project: local ones plus the host's. |
| 55 | pub fn visible_changes(app: &App, project: &Project) -> Result<Vec<Change>> { |
| 56 | app.db.changes(&project.id) |
| 57 | } |
| 58 |
| 59 | pub fn access_change(_app: &App, _s: &crate::app::Session, _target: &str, _who: Vec<String>, _edit: bool) -> crate::out::Out { |
| 60 | Err(Fail::new("bad_usage", "sharing changes needs a hosted project").state("nothing changed")) |
| 61 | } |
| 62 |
| 63 | /// The host's path rules: (path, who). |
| 64 | pub fn path_rules(_app: &App, _project: &Project) -> Result<Vec<(String, Vec<String>)>> { |
| 65 | Ok(Vec::new()) |
| 66 | } |
| 67 |
| 68 | pub fn set_path_rule(_app: &App, _s: &crate::app::Session, _path: &str, _who: Vec<String>) -> crate::out::Out { |
| 69 | Err(Fail::new("bad_usage", "path rules need a hosted project").state("nothing changed")) |
| 70 | } |
| 71 |
| 72 | pub fn import(_app: &App, url: &str, _to: Option<String>, _folder: Option<std::path::PathBuf>) -> crate::out::Out { |
| 73 | Err(Fail::new("failed", format!("importing {url} isn't ready yet")).state("nothing changed")) |
| 74 | } |
| 75 |
| 76 | pub fn publish(_app: &App, project: &str) -> crate::out::Out { |
| 77 | Err(Fail::new("failed", format!("publishing to {project} isn't ready yet")).state("nothing changed")) |
| 78 | } |
| 79 |
| 80 | pub fn login(_app: &App, _host: Option<String>, _token: Option<String>) -> crate::out::Out { |
| 81 | Err(Fail::new("failed", "login isn't ready yet").state("nothing changed")) |
| 82 | } |
| 83 |
| 84 | pub fn saver(_app: &App) -> crate::out::Out { |
| 85 | Ok(crate::out::Report::new()) |
| 86 | } |
| 87 |