| 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 |
}, |
| 77 |
|
| 78 |
Amend { |
| 79 |
#[arg(short, long)] |
| 80 |
message: Option<String>, |
| 81 |
}, |
| 82 |
|
| 83 |
Abandon { change: String }, |
| fce44ae9 Andy McCall ↶ |
84 |
|
| 85 |
Show { change: String }, |
| 86 |
|
| 87 |
Checkout { |
| 88 |
changes: Vec<String>, |
| 89 |
|
| 90 |
#[arg(long)] |
| 91 |
discard: bool, |
| 92 |
}, |
| 93 |
|
| 94 |
Resolve, |
| 95 |
|
| 96 |
Undo, |
| 252e8cb2 Andy McCall ↶ |
97 |
|
| 98 |
Checkpoint, |
| ba160f60 Andy McCall ↶ |
99 |
|
| 100 |
Gc { |
| 101 |
|
| 102 |
#[arg(long)] |
| 103 |
now: bool, |
| 104 |
}, |
| fce44ae9 Andy McCall ↶ |
105 |
|
| 106 |
#[command(name = "op")] |
| 107 |
Op { |
| 108 |
#[command(subcommand)] |
| 109 |
cmd: OpCmd, |
| 110 |
}, |
| 4e88e774 Andy McCall ↶ |
111 |
|
| 112 |
Workspace { |
| 113 |
#[command(subcommand)] |
| 114 |
cmd: WorkspaceCmd, |
| 115 |
}, |
| 132b884b Andy McCall ↶ |
116 |
|
| 117 |
Tag { |
| 118 |
#[command(subcommand)] |
| 119 |
cmd: TagCmd, |
| 120 |
}, |
| fce44ae9 Andy McCall ↶ |
121 |
|
| 122 |
Remote { |
| 123 |
#[command(subcommand)] |
| 124 |
cmd: RemoteCmd, |
| 125 |
}, |
| 126 |
|
| 127 |
Fetch { remote: Option<String> }, |
| 128 |
|
| 129 |
Pull { remote: Option<String> }, |
| 130 |
|
| 131 |
Push { |
| 132 |
remote: Option<String>, |
| 133 |
|
| 134 |
#[arg(long)] |
| 135 |
force: bool, |
| 136 |
}, |
| 2b5ee371 Andy McCall ↶ |
137 |
|
| fce44ae9 Andy McCall ↶ |
138 |
Serve { |
| 139 |
|
| 140 |
#[arg(long, default_value = ".")] |
| 141 |
root: PathBuf, |
| 142 |
#[arg(long, default_value = "127.0.0.1:8890")] |
| 143 |
bind: String, |
| 144 |
|
| 145 |
#[arg(long = "token")] |
| 146 |
tokens: Vec<String>, |
| 2b5ee371 Andy McCall ↶ |
147 |
|
| 148 |
#[arg(long, requires = "tls_key")] |
| 149 |
tls_cert: Option<PathBuf>, |
| 150 |
|
| 151 |
#[arg(long, requires = "tls_cert")] |
| 152 |
tls_key: Option<PathBuf>, |
| fce44ae9 Andy McCall ↶ |
153 |
}, |
| 154 |
|
| 155 |
Identity { |
| 156 |
#[command(subcommand)] |
| 157 |
cmd: IdentityCmd, |
| 158 |
}, |
| 159 |
|
| 160 |
Verify { change: Option<String> }, |
| 79ab8528 Andy McCall ↶ |
161 |
|
| 162 |
Git { |
| 163 |
#[command(subcommand)] |
| 164 |
cmd: GitCmd, |
| 165 |
}, |
| 83e0677b Andy McCall ↶ |
166 |
|
| 167 |
Policy { |
| 168 |
#[command(subcommand)] |
| 169 |
cmd: PolicyCmd, |
| 170 |
}, |
| 7421309f Andy McCall ↶ |
171 |
|
| fce44ae9 Andy McCall ↶ |
172 |
Config { |
| 173 |
key: String, |
| 174 |
value: String, |
| 175 |
|
| 176 |
#[arg(long)] |
| 177 |
user: bool, |
| 178 |
}, |
| 179 |
} |
| 180 |
|
| 181 |
#[derive(Subcommand)] |
| 182 |
enum OpCmd { |
| 183 |
Log, |
| 184 |
} |
| 185 |
|
| 186 |
#[derive(Subcommand)] |
| 4e88e774 Andy McCall ↶ |
187 |
enum WorkspaceCmd { |
| 188 |
|
| 189 |
Add { path: PathBuf, changes: Vec<String> }, |
| 190 |
List, |
| 191 |
|
| 192 |
Forget { workspace: String }, |
| 193 |
} |
| 194 |
|
| 195 |
#[derive(Subcommand)] |
| 132b884b Andy McCall ↶ |
196 |
enum TagCmd { |
| 197 |
|
| 198 |
Create { |
| 199 |
name: String, |
| 200 |
changes: Vec<String>, |
| 201 |
#[arg(short, long, default_value = "")] |
| 202 |
message: String, |
| 203 |
}, |
| 204 |
List, |
| 205 |
} |
| 206 |
|
| 207 |
#[derive(Subcommand)] |
| fce44ae9 Andy McCall ↶ |
208 |
enum RemoteCmd { |
| 209 |
Add { name: String, url: String }, |
| 210 |
Remove { name: String }, |
| 211 |
List, |
| 212 |
} |
| 213 |
|
| 214 |
#[derive(Subcommand)] |
| 215 |
enum IdentityCmd { |
| 216 |
|
| 217 |
Create { |
| 218 |
#[arg(long)] |
| 219 |
name: Option<String>, |
| 220 |
#[arg(long)] |
| 221 |
email: Option<String>, |
| 222 |
|
| 223 |
#[arg(long)] |
| 224 |
local: bool, |
| 225 |
}, |
| 226 |
|
| 227 |
Show, |
| 83e0677b Andy McCall ↶ |
228 |
|
| 229 |
Export { path: Option<PathBuf> }, |
| fce44ae9 Andy McCall ↶ |
230 |
} |
| 231 |
|
| 83e0677b Andy McCall ↶ |
232 |
#[derive(Subcommand)] |
| 79ab8528 Andy McCall ↶ |
233 |
enum GitCmd { |
| 234 |
|
| 235 |
Export { git_dir: PathBuf }, |
| c3069537 Andy McCall ↶ |
236 |
|
| 237 |
Import { |
| 238 |
git_dir: PathBuf, |
| 239 |
dest: PathBuf, |
| 240 |
#[arg(long, default_value = "main")] |
| 241 |
branch: String, |
| 242 |
}, |
| 79ab8528 Andy McCall ↶ |
243 |
} |
| 244 |
|
| 245 |
#[derive(Subcommand)] |
| 83e0677b Andy McCall ↶ |
246 |
enum PolicyCmd { |
| 247 |
|
| 248 |
Init, |
| 249 |
|
| 250 |
Show, |
| 251 |
|
| 252 |
Grant { |
| 253 |
identity_file: PathBuf, |
| 254 |
|
| 255 |
#[arg(long)] |
| 256 |
pattern: Option<String>, |
| 257 |
}, |
| 258 |
|
| 259 |
Revoke { key: String }, |
| 260 |
} |
| 261 |
|
| fce44ae9 Andy McCall ↶ |
262 |
|
| 263 |
fn open() -> Result<Repo> { |
| 264 |
Repo::open(&std::env::current_dir()?).context("opening repository") |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
pub fn run() -> Result<i32> { |
| 269 |
let cli = Cli::parse(); |
| 135212de Andy McCall ↶ |
270 |
ui::init(cli.plain); |
| fce44ae9 Andy McCall ↶ |
271 |
match cli.cmd { |
| 272 |
Cmd::Init { path } => workspace::init(path), |
| 273 |
Cmd::Status => workspace::status(), |
| 135212de Andy McCall ↶ |
274 |
Cmd::Prompt { format } => workspace::prompt(&format), |
| fce44ae9 Andy McCall ↶ |
275 |
Cmd::Commit { message, depends_on } => workspace::commit(&message, &depends_on), |
| 276 |
Cmd::Log => workspace::log(), |
| 277 |
Cmd::Diff => workspace::diff(), |
| 614541c3 Andy McCall ↶ |
278 |
Cmd::Describe { message, change } => workspace::describe(&message, change.as_deref()), |
| 279 |
Cmd::Amend { message } => workspace::amend(message.as_deref()), |
| 280 |
Cmd::Abandon { change } => workspace::abandon(&change), |
| fce44ae9 Andy McCall ↶ |
281 |
Cmd::Show { change } => workspace::show(&change), |
| 282 |
Cmd::Checkout { changes, discard } => workspace::checkout(&changes, discard), |
| 283 |
Cmd::Resolve => workspace::resolve(), |
| 284 |
Cmd::Undo => workspace::undo(), |
| ba160f60 Andy McCall ↶ |
285 |
Cmd::Gc { now } => workspace::gc(now), |
| 252e8cb2 Andy McCall ↶ |
286 |
Cmd::Checkpoint => workspace::checkpoint(), |
| fce44ae9 Andy McCall ↶ |
287 |
Cmd::Op { cmd: OpCmd::Log } => workspace::op_log(), |
| 2863456a Andy McCall ↶ |
288 |
Cmd::Clone { url, dest, max_blob, sparse, depth } => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth), |
| 289 |
Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth), |
| 7421309f Andy McCall ↶ |
290 |
Cmd::Sparse { paths } => workspace::sparse(&paths), |
| 4e88e774 Andy McCall ↶ |
291 |
Cmd::Workspace { cmd } => match cmd { |
| 292 |
WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes), |
| 293 |
WorkspaceCmd::List => workspace::workspace_list(), |
| 294 |
WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace), |
| 295 |
}, |
| 132b884b Andy McCall ↶ |
296 |
Cmd::Tag { cmd } => match cmd { |
| 297 |
TagCmd::Create { name, changes, message } => workspace::tag_create(&name, &changes, &message), |
| 298 |
TagCmd::List => workspace::tag_list(), |
| 299 |
}, |
| fce44ae9 Andy McCall ↶ |
300 |
Cmd::Remote { cmd } => match cmd { |
| 301 |
RemoteCmd::Add { name, url } => sync::remote_add(&name, &url), |
| 302 |
RemoteCmd::Remove { name } => sync::remote_remove(&name), |
| 303 |
RemoteCmd::List => sync::remote_list(), |
| 304 |
}, |
| 305 |
Cmd::Fetch { remote } => sync::fetch(remote.as_deref()), |
| 306 |
Cmd::Pull { remote } => sync::pull(remote.as_deref()), |
| 307 |
Cmd::Push { remote, force } => sync::push(remote.as_deref(), force), |
| 2b5ee371 Andy McCall ↶ |
308 |
Cmd::Serve { root, bind, tokens, tls_cert, tls_key } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)), |
| fce44ae9 Andy McCall ↶ |
309 |
Cmd::Identity { cmd } => match cmd { |
| 310 |
IdentityCmd::Create { name, email, local } => identity::create(name, email, local), |
| 311 |
IdentityCmd::Show => identity::show(), |
| 83e0677b Andy McCall ↶ |
312 |
IdentityCmd::Export { path } => identity::export(path), |
| 313 |
}, |
| 79ab8528 Andy McCall ↶ |
314 |
Cmd::Git { cmd: GitCmd::Export { git_dir } } => sync::git_export(&git_dir), |
| c3069537 Andy McCall ↶ |
315 |
Cmd::Git { cmd: GitCmd::Import { git_dir, dest, branch } } => sync::git_import(&git_dir, &dest, &branch), |
| 83e0677b Andy McCall ↶ |
316 |
Cmd::Policy { cmd } => match cmd { |
| 317 |
PolicyCmd::Init => identity::policy_init(), |
| 318 |
PolicyCmd::Show => identity::policy_show(), |
| 319 |
PolicyCmd::Grant { identity_file, pattern } => identity::policy_grant(&identity_file, pattern.as_deref()), |
| 320 |
PolicyCmd::Revoke { key } => identity::policy_revoke(&key), |
| fce44ae9 Andy McCall ↶ |
321 |
}, |
| 322 |
Cmd::Verify { change } => identity::verify(change.as_deref()), |
| 323 |
Cmd::Config { key, value, user } => identity::config(&key, &value, user), |
| 324 |
} |
| 325 |
} |