| fce44ae9 Andy McCall ↶ |
1 |
|
| 2 |
|
| 3 |
mod format; |
| 4 |
mod identity; |
| 5 |
mod sync; |
| 135212de Andy McCall ↶ |
6 |
pub mod ui; |
| fce44ae9 Andy McCall ↶ |
7 |
mod workspace; |
| 8 |
|
| 9 |
use anyhow::{Context, Result}; |
| 10 |
use clap::{Parser, Subcommand}; |
| 11 |
use oxy_core::repo::Repo; |
| 12 |
use std::path::PathBuf; |
| 13 |
|
| 14 |
#[derive(Parser)] |
| 15 |
#[command(name = "oxy", version, about = "Oxygen: breathing fresh air into version control")] |
| 16 |
struct Cli { |
| 135212de Andy McCall ↶ |
17 |
|
| 18 |
#[arg(long, global = true)] |
| 19 |
plain: bool, |
| fce44ae9 Andy McCall ↶ |
20 |
#[command(subcommand)] |
| 21 |
cmd: Cmd, |
| 22 |
} |
| 23 |
|
| 24 |
#[derive(Subcommand)] |
| 25 |
enum Cmd { |
| 26 |
|
| 27 |
Init { path: Option<PathBuf> }, |
| 28 |
|
| b3c5a59a Andy McCall ↶ |
29 |
Clone { |
| 30 |
url: String, |
| 31 |
dest: Option<PathBuf>, |
| 32 |
|
| 33 |
#[arg(long)] |
| 34 |
max_blob: Option<String>, |
| 7421309f Andy McCall ↶ |
35 |
|
| 36 |
#[arg(long = "sparse")] |
| 37 |
sparse: Vec<String>, |
| 2863456a Andy McCall ↶ |
38 |
|
| 39 |
#[arg(long)] |
| 40 |
depth: Option<u32>, |
| b3c5a59a Andy McCall ↶ |
41 |
}, |
| 2863456a Andy McCall ↶ |
42 |
|
| 43 |
Deepen { |
| 44 |
#[arg(default_value_t = 10)] |
| 45 |
depth: u32, |
| 46 |
#[arg(long, default_value = "origin")] |
| 47 |
remote: String, |
| 48 |
}, |
| 7421309f Andy McCall ↶ |
49 |
|
| 50 |
Sparse { paths: Vec<String> }, |
| fce44ae9 Andy McCall ↶ |
51 |
|
| 52 |
Status, |
| 135212de Andy McCall ↶ |
53 |
|
| 54 |
Prompt { |
| 55 |
|
| 56 |
#[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)] |
| 57 |
format: String, |
| 58 |
}, |
| fce44ae9 Andy McCall ↶ |
59 |
|
| 60 |
Commit { |
| 61 |
#[arg(short, long)] |
| 62 |
message: String, |
| 63 |
|
| 64 |
#[arg(long = "depends-on")] |
| 65 |
depends_on: Vec<String>, |
| 66 |
}, |
| 67 |
|
| 68 |
Log, |
| 69 |
|
| 70 |
Diff, |
| 614541c3 Andy McCall ↶ |
71 |
|
| 72 |
Describe { |
| 73 |
#[arg(short, long)] |
| 74 |
message: String, |
| 75 |
change: Option<String>, |
| 76 |
}, |
| 23b217d7 Andy McCall ↶ |
77 |
|
| 614541c3 Andy McCall ↶ |
78 |
Amend { |
| 79 |
#[arg(short, long)] |
| 80 |
message: Option<String>, |
| 23b217d7 Andy McCall ↶ |
81 |
|
| 82 |
#[arg(long)] |
| 83 |
into: Option<String>, |
| 614541c3 Andy McCall ↶ |
84 |
}, |
| 23b217d7 Andy McCall ↶ |
85 |
|
| 86 |
Split { |
| 87 |
change: String, |
| 88 |
paths: Vec<String>, |
| 89 |
}, |
| 614541c3 Andy McCall ↶ |
90 |
|
| 91 |
Abandon { change: String }, |
| fce44ae9 Andy McCall ↶ |
92 |
|
| 93 |
Show { change: String }, |
| 94 |
|
| 95 |
Checkout { |
| 96 |
changes: Vec<String>, |
| 97 |
|
| 98 |
#[arg(long)] |
| 99 |
discard: bool, |
| 100 |
}, |
| 101 |
|
| 102 |
Resolve, |
| 103 |
|
| 104 |
Undo, |
| 252e8cb2 Andy McCall ↶ |
105 |
|
| 106 |
Checkpoint, |
| ba160f60 Andy McCall ↶ |
107 |
|
| 108 |
Gc { |
| 109 |
|
| 110 |
#[arg(long)] |
| 111 |
now: bool, |
| 112 |
}, |
| fce44ae9 Andy McCall ↶ |
113 |
|
| 114 |
#[command(name = "op")] |
| 115 |
Op { |
| 116 |
#[command(subcommand)] |
| 117 |
cmd: OpCmd, |
| 118 |
}, |
| cdb5beba Andy McCall ↶ |
119 |
|
| 120 |
Lock { path: String }, |
| 121 |
|
| 122 |
Unlock { path: String }, |
| 4e88e774 Andy McCall ↶ |
123 |
|
| 124 |
Workspace { |
| 125 |
#[command(subcommand)] |
| 126 |
cmd: WorkspaceCmd, |
| 127 |
}, |
| 132b884b Andy McCall ↶ |
128 |
|
| 129 |
Tag { |
| 130 |
#[command(subcommand)] |
| 131 |
cmd: TagCmd, |
| 132 |
}, |
| fce44ae9 Andy McCall ↶ |
133 |
|
| 134 |
Remote { |
| 135 |
#[command(subcommand)] |
| 136 |
cmd: RemoteCmd, |
| 137 |
}, |
| 138 |
|
| 139 |
Fetch { remote: Option<String> }, |
| 140 |
|
| 141 |
Pull { remote: Option<String> }, |
| 142 |
|
| 143 |
Push { |
| 144 |
remote: Option<String>, |
| 145 |
|
| 146 |
#[arg(long)] |
| 147 |
force: bool, |
| 148 |
}, |
| 2b5ee371 Andy McCall ↶ |
149 |
|
| fce44ae9 Andy McCall ↶ |
150 |
Serve { |
| 151 |
|
| 152 |
#[arg(long, default_value = ".")] |
| 153 |
root: PathBuf, |
| 154 |
#[arg(long, default_value = "127.0.0.1:8890")] |
| 155 |
bind: String, |
| 156 |
|
| 157 |
#[arg(long = "token")] |
| 158 |
tokens: Vec<String>, |
| 2b5ee371 Andy McCall ↶ |
159 |
|
| 160 |
#[arg(long, requires = "tls_key")] |
| 161 |
tls_cert: Option<PathBuf>, |
| 162 |
|
| 163 |
#[arg(long, requires = "tls_cert")] |
| 164 |
tls_key: Option<PathBuf>, |
| fce44ae9 Andy McCall ↶ |
165 |
}, |
| 166 |
|
| 167 |
Identity { |
| 168 |
#[command(subcommand)] |
| 169 |
cmd: IdentityCmd, |
| 170 |
}, |
| 171 |
|
| 172 |
Verify { change: Option<String> }, |
| 79ab8528 Andy McCall ↶ |
173 |
|
| 174 |
Git { |
| 175 |
#[command(subcommand)] |
| 176 |
cmd: GitCmd, |
| 177 |
}, |
| 83e0677b Andy McCall ↶ |
178 |
|
| 179 |
Policy { |
| 180 |
#[command(subcommand)] |
| 181 |
cmd: PolicyCmd, |
| 182 |
}, |
| 7421309f Andy McCall ↶ |
183 |
|
| fce44ae9 Andy McCall ↶ |
184 |
Config { |
| 185 |
key: String, |
| 186 |
value: String, |
| 187 |
|
| 188 |
#[arg(long)] |
| 189 |
user: bool, |
| 190 |
}, |
| 191 |
} |
| 192 |
|
| 193 |
#[derive(Subcommand)] |
| 194 |
enum OpCmd { |
| 195 |
Log, |
| 196 |
} |
| 197 |
|
| 198 |
#[derive(Subcommand)] |
| 4e88e774 Andy McCall ↶ |
199 |
enum WorkspaceCmd { |
| 200 |
|
| 201 |
Add { path: PathBuf, changes: Vec<String> }, |
| 202 |
List, |
| 203 |
|
| 204 |
Forget { workspace: String }, |
| 205 |
} |
| 206 |
|
| 207 |
#[derive(Subcommand)] |
| 132b884b Andy McCall ↶ |
208 |
enum TagCmd { |
| 209 |
|
| 210 |
Create { |
| 211 |
name: String, |
| 212 |
changes: Vec<String>, |
| 213 |
#[arg(short, long, default_value = "")] |
| 214 |
message: String, |
| 215 |
}, |
| 216 |
List, |
| 217 |
} |
| 218 |
|
| 219 |
#[derive(Subcommand)] |
| fce44ae9 Andy McCall ↶ |
220 |
enum RemoteCmd { |
| 221 |
Add { name: String, url: String }, |
| 222 |
Remove { name: String }, |
| 223 |
List, |
| 224 |
} |
| 225 |
|
| 226 |
#[derive(Subcommand)] |
| 227 |
enum IdentityCmd { |
| 228 |
|
| 229 |
Create { |
| 230 |
#[arg(long)] |
| 231 |
name: Option<String>, |
| 232 |
#[arg(long)] |
| 233 |
email: Option<String>, |
| 234 |
|
| 235 |
#[arg(long)] |
| 236 |
local: bool, |
| 237 |
}, |
| 238 |
|
| 239 |
Show, |
| 83e0677b Andy McCall ↶ |
240 |
|
| 241 |
Export { path: Option<PathBuf> }, |
| fce44ae9 Andy McCall ↶ |
242 |
} |
| 243 |
|
| 83e0677b Andy McCall ↶ |
244 |
#[derive(Subcommand)] |
| 79ab8528 Andy McCall ↶ |
245 |
enum GitCmd { |
| 246 |
|
| 247 |
Export { git_dir: PathBuf }, |
| c3069537 Andy McCall ↶ |
248 |
|
| 249 |
Import { |
| 250 |
git_dir: PathBuf, |
| 251 |
dest: PathBuf, |
| 252 |
#[arg(long, default_value = "main")] |
| 253 |
branch: String, |
| 254 |
}, |
| 79ab8528 Andy McCall ↶ |
255 |
} |
| 256 |
|
| 257 |
#[derive(Subcommand)] |
| 83e0677b Andy McCall ↶ |
258 |
enum PolicyCmd { |
| 259 |
|
| 260 |
Init, |
| 261 |
|
| 262 |
Show, |
| 263 |
|
| 264 |
Grant { |
| 265 |
identity_file: PathBuf, |
| 266 |
|
| 267 |
#[arg(long)] |
| 268 |
pattern: Option<String>, |
| 269 |
}, |
| 270 |
|
| 271 |
Revoke { key: String }, |
| 272 |
} |
| 273 |
|
| fce44ae9 Andy McCall ↶ |
274 |
|
| 275 |
fn open() -> Result<Repo> { |
| 276 |
Repo::open(&std::env::current_dir()?).context("opening repository") |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
pub fn run() -> Result<i32> { |
| 281 |
let cli = Cli::parse(); |
| 135212de Andy McCall ↶ |
282 |
ui::init(cli.plain); |
| fce44ae9 Andy McCall ↶ |
283 |
match cli.cmd { |
| 284 |
Cmd::Init { path } => workspace::init(path), |
| 285 |
Cmd::Status => workspace::status(), |
| 135212de Andy McCall ↶ |
286 |
Cmd::Prompt { format } => workspace::prompt(&format), |
| fce44ae9 Andy McCall ↶ |
287 |
Cmd::Commit { message, depends_on } => workspace::commit(&message, &depends_on), |
| 288 |
Cmd::Log => workspace::log(), |
| 289 |
Cmd::Diff => workspace::diff(), |
| 614541c3 Andy McCall ↶ |
290 |
Cmd::Describe { message, change } => workspace::describe(&message, change.as_deref()), |
| 23b217d7 Andy McCall ↶ |
291 |
Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()), |
| 292 |
Cmd::Split { change, paths } => workspace::split(&change, &paths), |
| 614541c3 Andy McCall ↶ |
293 |
Cmd::Abandon { change } => workspace::abandon(&change), |
| fce44ae9 Andy McCall ↶ |
294 |
Cmd::Show { change } => workspace::show(&change), |
| 295 |
Cmd::Checkout { changes, discard } => workspace::checkout(&changes, discard), |
| 296 |
Cmd::Resolve => workspace::resolve(), |
| 297 |
Cmd::Undo => workspace::undo(), |
| ba160f60 Andy McCall ↶ |
298 |
Cmd::Gc { now } => workspace::gc(now), |
| 252e8cb2 Andy McCall ↶ |
299 |
Cmd::Checkpoint => workspace::checkpoint(), |
| fce44ae9 Andy McCall ↶ |
300 |
Cmd::Op { cmd: OpCmd::Log } => workspace::op_log(), |
| 2863456a Andy McCall ↶ |
301 |
Cmd::Clone { url, dest, max_blob, sparse, depth } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth), |
| 302 |
Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth), |
| 7421309f Andy McCall ↶ |
303 |
Cmd::Sparse { paths } => workspace::sparse(&paths), |
| cdb5beba Andy McCall ↶ |
304 |
Cmd::Lock { path } => workspace::lock(&path), |
| 305 |
Cmd::Unlock { path } => workspace::unlock(&path), |
| 4e88e774 Andy McCall ↶ |
306 |
Cmd::Workspace { cmd } => match cmd { |
| 307 |
WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes), |
| 308 |
WorkspaceCmd::List => workspace::workspace_list(), |
| 309 |
WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace), |
| 310 |
}, |
| 132b884b Andy McCall ↶ |
311 |
Cmd::Tag { cmd } => match cmd { |
| 312 |
TagCmd::Create { name, changes, message } => workspace::tag_create(&name, &changes, &message), |
| 313 |
TagCmd::List => workspace::tag_list(), |
| 314 |
}, |
| fce44ae9 Andy McCall ↶ |
315 |
Cmd::Remote { cmd } => match cmd { |
| 316 |
RemoteCmd::Add { name, url } => sync::remote_add(&name, &url), |
| 317 |
RemoteCmd::Remove { name } => sync::remote_remove(&name), |
| 318 |
RemoteCmd::List => sync::remote_list(), |
| 319 |
}, |
| 320 |
Cmd::Fetch { remote } => sync::fetch(remote.as_deref()), |
| 321 |
Cmd::Pull { remote } => sync::pull(remote.as_deref()), |
| 322 |
Cmd::Push { remote, force } => sync::push(remote.as_deref(), force), |
| 2b5ee371 Andy McCall ↶ |
323 |
Cmd::Serve { root, bind, tokens, tls_cert, tls_key } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)), |
| fce44ae9 Andy McCall ↶ |
324 |
Cmd::Identity { cmd } => match cmd { |
| 325 |
IdentityCmd::Create { name, email, local } => identity::create(name, email, local), |
| 326 |
IdentityCmd::Show => identity::show(), |
| 83e0677b Andy McCall ↶ |
327 |
IdentityCmd::Export { path } => identity::export(path), |
| 328 |
}, |
| 79ab8528 Andy McCall ↶ |
329 |
Cmd::Git { cmd: GitCmd::Export { git_dir } } => sync::git_export(&git_dir), |
| c3069537 Andy McCall ↶ |
330 |
Cmd::Git { cmd: GitCmd::Import { git_dir, dest, branch } } => sync::git_import(&git_dir, &dest, &branch), |
| 83e0677b Andy McCall ↶ |
331 |
Cmd::Policy { cmd } => match cmd { |
| 332 |
PolicyCmd::Init => identity::policy_init(), |
| 333 |
PolicyCmd::Show => identity::policy_show(), |
| 334 |
PolicyCmd::Grant { identity_file, pattern } => identity::policy_grant(&identity_file, pattern.as_deref()), |
| 335 |
PolicyCmd::Revoke { key } => identity::policy_revoke(&key), |
| fce44ae9 Andy McCall ↶ |
336 |
}, |
| 337 |
Cmd::Verify { change } => identity::verify(change.as_deref()), |
| 338 |
Cmd::Config { key, value, user } => identity::config(&key, &value, user), |
| 339 |
} |
| 340 |
} |