| 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>, |
| b3c5a59a Andy McCall ↶ |
38 |
}, |
| 7421309f Andy McCall ↶ |
39 |
|
| 40 |
Sparse { paths: Vec<String> }, |
| fce44ae9 Andy McCall ↶ |
41 |
|
| 42 |
Status, |
| 135212de Andy McCall ↶ |
43 |
|
| 44 |
Prompt { |
| 45 |
|
| 46 |
#[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)] |
| 47 |
format: String, |
| 48 |
}, |
| fce44ae9 Andy McCall ↶ |
49 |
|
| 50 |
Commit { |
| 51 |
#[arg(short, long)] |
| 52 |
message: String, |
| 53 |
|
| 54 |
#[arg(long = "depends-on")] |
| 55 |
depends_on: Vec<String>, |
| 56 |
}, |
| 57 |
|
| 58 |
Log, |
| 59 |
|
| 60 |
Diff, |
| 614541c3 Andy McCall ↶ |
61 |
|
| 62 |
Describe { |
| 63 |
#[arg(short, long)] |
| 64 |
message: String, |
| 65 |
change: Option<String>, |
| 66 |
}, |
| 67 |
|
| 68 |
Amend { |
| 69 |
#[arg(short, long)] |
| 70 |
message: Option<String>, |
| 71 |
}, |
| 72 |
|
| 73 |
Abandon { change: String }, |
| fce44ae9 Andy McCall ↶ |
74 |
|
| 75 |
Show { change: String }, |
| 76 |
|
| 77 |
Checkout { |
| 78 |
changes: Vec<String>, |
| 79 |
|
| 80 |
#[arg(long)] |
| 81 |
discard: bool, |
| 82 |
}, |
| 83 |
|
| 84 |
Resolve, |
| 85 |
|
| 86 |
Undo, |
| 252e8cb2 Andy McCall ↶ |
87 |
|
| 88 |
Checkpoint, |
| ba160f60 Andy McCall ↶ |
89 |
|
| 90 |
Gc { |
| 91 |
|
| 92 |
#[arg(long)] |
| 93 |
now: bool, |
| 94 |
}, |
| fce44ae9 Andy McCall ↶ |
95 |
|
| 96 |
#[command(name = "op")] |
| 97 |
Op { |
| 98 |
#[command(subcommand)] |
| 99 |
cmd: OpCmd, |
| 100 |
}, |
| 101 |
|
| 102 |
Remote { |
| 103 |
#[command(subcommand)] |
| 104 |
cmd: RemoteCmd, |
| 105 |
}, |
| 106 |
|
| 107 |
Fetch { remote: Option<String> }, |
| 108 |
|
| 109 |
Pull { remote: Option<String> }, |
| 110 |
|
| 111 |
Push { |
| 112 |
remote: Option<String>, |
| 113 |
|
| 114 |
#[arg(long)] |
| 115 |
force: bool, |
| 116 |
}, |
| 2b5ee371 Andy McCall ↶ |
117 |
|
| fce44ae9 Andy McCall ↶ |
118 |
Serve { |
| 119 |
|
| 120 |
#[arg(long, default_value = ".")] |
| 121 |
root: PathBuf, |
| 122 |
#[arg(long, default_value = "127.0.0.1:8890")] |
| 123 |
bind: String, |
| 124 |
|
| 125 |
#[arg(long = "token")] |
| 126 |
tokens: Vec<String>, |
| 2b5ee371 Andy McCall ↶ |
127 |
|
| 128 |
#[arg(long, requires = "tls_key")] |
| 129 |
tls_cert: Option<PathBuf>, |
| 130 |
|
| 131 |
#[arg(long, requires = "tls_cert")] |
| 132 |
tls_key: Option<PathBuf>, |
| fce44ae9 Andy McCall ↶ |
133 |
}, |
| 134 |
|
| 135 |
Identity { |
| 136 |
#[command(subcommand)] |
| 137 |
cmd: IdentityCmd, |
| 138 |
}, |
| 139 |
|
| 140 |
Verify { change: Option<String> }, |
| 79ab8528 Andy McCall ↶ |
141 |
|
| 142 |
Git { |
| 143 |
#[command(subcommand)] |
| 144 |
cmd: GitCmd, |
| 145 |
}, |
| 83e0677b Andy McCall ↶ |
146 |
|
| 147 |
Policy { |
| 148 |
#[command(subcommand)] |
| 149 |
cmd: PolicyCmd, |
| 150 |
}, |
| 7421309f Andy McCall ↶ |
151 |
|
| fce44ae9 Andy McCall ↶ |
152 |
Config { |
| 153 |
key: String, |
| 154 |
value: String, |
| 155 |
|
| 156 |
#[arg(long)] |
| 157 |
user: bool, |
| 158 |
}, |
| 159 |
} |
| 160 |
|
| 161 |
#[derive(Subcommand)] |
| 162 |
enum OpCmd { |
| 163 |
Log, |
| 164 |
} |
| 165 |
|
| 166 |
#[derive(Subcommand)] |
| 167 |
enum RemoteCmd { |
| 168 |
Add { name: String, url: String }, |
| 169 |
Remove { name: String }, |
| 170 |
List, |
| 171 |
} |
| 172 |
|
| 173 |
#[derive(Subcommand)] |
| 174 |
enum IdentityCmd { |
| 175 |
|
| 176 |
Create { |
| 177 |
#[arg(long)] |
| 178 |
name: Option<String>, |
| 179 |
#[arg(long)] |
| 180 |
email: Option<String>, |
| 181 |
|
| 182 |
#[arg(long)] |
| 183 |
local: bool, |
| 184 |
}, |
| 185 |
|
| 186 |
Show, |
| 83e0677b Andy McCall ↶ |
187 |
|
| 188 |
Export { path: Option<PathBuf> }, |
| fce44ae9 Andy McCall ↶ |
189 |
} |
| 190 |
|
| 83e0677b Andy McCall ↶ |
191 |
#[derive(Subcommand)] |
| 79ab8528 Andy McCall ↶ |
192 |
enum GitCmd { |
| 193 |
|
| 194 |
Export { git_dir: PathBuf }, |
| c3069537 Andy McCall ↶ |
195 |
|
| 196 |
Import { |
| 197 |
git_dir: PathBuf, |
| 198 |
dest: PathBuf, |
| 199 |
#[arg(long, default_value = "main")] |
| 200 |
branch: String, |
| 201 |
}, |
| 79ab8528 Andy McCall ↶ |
202 |
} |
| 203 |
|
| 204 |
#[derive(Subcommand)] |
| 83e0677b Andy McCall ↶ |
205 |
enum PolicyCmd { |
| 206 |
|
| 207 |
Init, |
| 208 |
|
| 209 |
Show, |
| 210 |
|
| 211 |
Grant { |
| 212 |
identity_file: PathBuf, |
| 213 |
|
| 214 |
#[arg(long)] |
| 215 |
pattern: Option<String>, |
| 216 |
}, |
| 217 |
|
| 218 |
Revoke { key: String }, |
| 219 |
} |
| 220 |
|
| fce44ae9 Andy McCall ↶ |
221 |
|
| 222 |
fn open() -> Result<Repo> { |
| 223 |
Repo::open(&std::env::current_dir()?).context("opening repository") |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
pub fn run() -> Result<i32> { |
| 228 |
let cli = Cli::parse(); |
| 135212de Andy McCall ↶ |
229 |
ui::init(cli.plain); |
| fce44ae9 Andy McCall ↶ |
230 |
match cli.cmd { |
| 231 |
Cmd::Init { path } => workspace::init(path), |
| 232 |
Cmd::Status => workspace::status(), |
| 135212de Andy McCall ↶ |
233 |
Cmd::Prompt { format } => workspace::prompt(&format), |
| fce44ae9 Andy McCall ↶ |
234 |
Cmd::Commit { message, depends_on } => workspace::commit(&message, &depends_on), |
| 235 |
Cmd::Log => workspace::log(), |
| 236 |
Cmd::Diff => workspace::diff(), |
| 614541c3 Andy McCall ↶ |
237 |
Cmd::Describe { message, change } => workspace::describe(&message, change.as_deref()), |
| 238 |
Cmd::Amend { message } => workspace::amend(message.as_deref()), |
| 239 |
Cmd::Abandon { change } => workspace::abandon(&change), |
| fce44ae9 Andy McCall ↶ |
240 |
Cmd::Show { change } => workspace::show(&change), |
| 241 |
Cmd::Checkout { changes, discard } => workspace::checkout(&changes, discard), |
| 242 |
Cmd::Resolve => workspace::resolve(), |
| 243 |
Cmd::Undo => workspace::undo(), |
| ba160f60 Andy McCall ↶ |
244 |
Cmd::Gc { now } => workspace::gc(now), |
| 252e8cb2 Andy McCall ↶ |
245 |
Cmd::Checkpoint => workspace::checkpoint(), |
| fce44ae9 Andy McCall ↶ |
246 |
Cmd::Op { cmd: OpCmd::Log } => workspace::op_log(), |
| 7421309f Andy McCall ↶ |
247 |
Cmd::Clone { url, dest, max_blob, sparse } => sync::clone(&url, dest, max_blob.as_deref(), &sparse), |
| 248 |
Cmd::Sparse { paths } => workspace::sparse(&paths), |
| fce44ae9 Andy McCall ↶ |
249 |
Cmd::Remote { cmd } => match cmd { |
| 250 |
RemoteCmd::Add { name, url } => sync::remote_add(&name, &url), |
| 251 |
RemoteCmd::Remove { name } => sync::remote_remove(&name), |
| 252 |
RemoteCmd::List => sync::remote_list(), |
| 253 |
}, |
| 254 |
Cmd::Fetch { remote } => sync::fetch(remote.as_deref()), |
| 255 |
Cmd::Pull { remote } => sync::pull(remote.as_deref()), |
| 256 |
Cmd::Push { remote, force } => sync::push(remote.as_deref(), force), |
| 2b5ee371 Andy McCall ↶ |
257 |
Cmd::Serve { root, bind, tokens, tls_cert, tls_key } => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)), |
| fce44ae9 Andy McCall ↶ |
258 |
Cmd::Identity { cmd } => match cmd { |
| 259 |
IdentityCmd::Create { name, email, local } => identity::create(name, email, local), |
| 260 |
IdentityCmd::Show => identity::show(), |
| 83e0677b Andy McCall ↶ |
261 |
IdentityCmd::Export { path } => identity::export(path), |
| 262 |
}, |
| 79ab8528 Andy McCall ↶ |
263 |
Cmd::Git { cmd: GitCmd::Export { git_dir } } => sync::git_export(&git_dir), |
| c3069537 Andy McCall ↶ |
264 |
Cmd::Git { cmd: GitCmd::Import { git_dir, dest, branch } } => sync::git_import(&git_dir, &dest, &branch), |
| 83e0677b Andy McCall ↶ |
265 |
Cmd::Policy { cmd } => match cmd { |
| 266 |
PolicyCmd::Init => identity::policy_init(), |
| 267 |
PolicyCmd::Show => identity::policy_show(), |
| 268 |
PolicyCmd::Grant { identity_file, pattern } => identity::policy_grant(&identity_file, pattern.as_deref()), |
| 269 |
PolicyCmd::Revoke { key } => identity::policy_revoke(&key), |
| fce44ae9 Andy McCall ↶ |
270 |
}, |
| 271 |
Cmd::Verify { change } => identity::verify(change.as_deref()), |
| 272 |
Cmd::Config { key, value, user } => identity::config(&key, &value, user), |
| 273 |
} |
| 274 |
} |