| 1 |
|
| 2 |
|
| 3 |
mod format; |
| 4 |
mod identity; |
| 5 |
mod json; |
| 6 |
mod proposal; |
| 7 |
mod receipt; |
| 8 |
mod sync; |
| 9 |
pub mod ui; |
| 10 |
mod workspace; |
| 11 |
|
| 12 |
use anyhow::{Context, Result}; |
| 13 |
use clap::{Parser, Subcommand}; |
| 14 |
use oxy_core::repo::Repo; |
| 15 |
use std::path::PathBuf; |
| 16 |
|
| 17 |
#[derive(Parser)] |
| 18 |
#[command( |
| 19 |
name = "oxy", |
| 20 |
version, |
| 21 |
about = "Oxygen: breathing fresh air into version control" |
| 22 |
)] |
| 23 |
struct Cli { |
| 24 |
|
| 25 |
#[arg(long, global = true)] |
| 26 |
plain: bool, |
| 27 |
#[command(subcommand)] |
| 28 |
cmd: Cmd, |
| 29 |
} |
| 30 |
|
| 31 |
#[derive(Subcommand)] |
| 32 |
enum Cmd { |
| 33 |
|
| 34 |
Init { |
| 35 |
|
| 36 |
path: Option<PathBuf>, |
| 37 |
|
| 38 |
#[arg(long)] |
| 39 |
bare: bool, |
| 40 |
}, |
| 41 |
|
| 42 |
Clone { |
| 43 |
|
| 44 |
url: String, |
| 45 |
|
| 46 |
dest: Option<PathBuf>, |
| 47 |
|
| 48 |
#[arg(long)] |
| 49 |
max_blob: Option<String>, |
| 50 |
|
| 51 |
#[arg(long = "sparse")] |
| 52 |
sparse: Vec<String>, |
| 53 |
|
| 54 |
#[arg(long)] |
| 55 |
depth: Option<u32>, |
| 56 |
}, |
| 57 |
|
| 58 |
Deepen { |
| 59 |
|
| 60 |
#[arg(default_value_t = 10)] |
| 61 |
depth: u32, |
| 62 |
|
| 63 |
#[arg(long, default_value = "origin")] |
| 64 |
remote: String, |
| 65 |
}, |
| 66 |
|
| 67 |
Sparse { |
| 68 |
|
| 69 |
paths: Vec<String>, |
| 70 |
}, |
| 71 |
|
| 72 |
Status { |
| 73 |
|
| 74 |
#[arg(long)] |
| 75 |
json: bool, |
| 76 |
}, |
| 77 |
|
| 78 |
Prompt { |
| 79 |
|
| 80 |
#[arg(long, default_value = oxy_core::repo::DEFAULT_PROMPT_FORMAT)] |
| 81 |
format: String, |
| 82 |
|
| 83 |
#[arg(long)] |
| 84 |
glyphs: bool, |
| 85 |
|
| 86 |
#[arg(long, value_parser = ["raw", "bash", "zsh"])] |
| 87 |
color: Option<String>, |
| 88 |
}, |
| 89 |
|
| 90 |
Commit { |
| 91 |
|
| 92 |
#[arg(short, long, required_unless_present = "file", conflicts_with = "file")] |
| 93 |
message: Option<String>, |
| 94 |
|
| 95 |
#[arg(short = 'F', long, value_name = "FILE")] |
| 96 |
file: Option<PathBuf>, |
| 97 |
|
| 98 |
#[arg(long = "depends-on")] |
| 99 |
depends_on: Vec<String>, |
| 100 |
|
| 101 |
paths: Vec<String>, |
| 102 |
|
| 103 |
#[arg(short, long)] |
| 104 |
interactive: bool, |
| 105 |
|
| 106 |
#[arg(long, value_delimiter = ',')] |
| 107 |
hunks: Vec<usize>, |
| 108 |
}, |
| 109 |
|
| 110 |
Squash { |
| 111 |
|
| 112 |
change: String, |
| 113 |
|
| 114 |
#[arg(long)] |
| 115 |
into: String, |
| 116 |
}, |
| 117 |
|
| 118 |
Rebase { |
| 119 |
|
| 120 |
change: String, |
| 121 |
|
| 122 |
#[arg(long, required = true, num_args = 1..)] |
| 123 |
onto: Vec<String>, |
| 124 |
}, |
| 125 |
|
| 126 |
Blame { |
| 127 |
|
| 128 |
path: String, |
| 129 |
|
| 130 |
#[arg(long)] |
| 131 |
json: bool, |
| 132 |
}, |
| 133 |
|
| 134 |
Bisect { |
| 135 |
#[command(subcommand)] |
| 136 |
cmd: BisectCmd, |
| 137 |
}, |
| 138 |
|
| 139 |
Log { |
| 140 |
|
| 141 |
#[arg(short = 'n', long)] |
| 142 |
limit: Option<usize>, |
| 143 |
|
| 144 |
#[arg(short, long)] |
| 145 |
verbose: bool, |
| 146 |
|
| 147 |
#[arg(long)] |
| 148 |
path: Option<String>, |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
#[arg(short = 'L', value_name = "START,END:PATH", conflicts_with = "path")] |
| 153 |
lines: Option<String>, |
| 154 |
|
| 155 |
#[arg(long)] |
| 156 |
json: bool, |
| 157 |
}, |
| 158 |
|
| 159 |
Diff { |
| 160 |
|
| 161 |
change: Option<String>, |
| 162 |
|
| 163 |
#[arg(long)] |
| 164 |
json: bool, |
| 165 |
}, |
| 166 |
|
| 167 |
Cat { |
| 168 |
|
| 169 |
path: String, |
| 170 |
|
| 171 |
#[arg(short = 'r', long)] |
| 172 |
change: Option<String>, |
| 173 |
}, |
| 174 |
|
| 175 |
Root { |
| 176 |
|
| 177 |
#[arg(long)] |
| 178 |
json: bool, |
| 179 |
}, |
| 180 |
|
| 181 |
Version { |
| 182 |
|
| 183 |
#[arg(long)] |
| 184 |
json: bool, |
| 185 |
}, |
| 186 |
|
| 187 |
Discard { |
| 188 |
|
| 189 |
paths: Vec<String>, |
| 190 |
|
| 191 |
#[arg(long, value_delimiter = ',')] |
| 192 |
hunks: Vec<usize>, |
| 193 |
}, |
| 194 |
|
| 195 |
Hunks { |
| 196 |
|
| 197 |
#[arg(long)] |
| 198 |
json: bool, |
| 199 |
}, |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
Describe { |
| 204 |
|
| 205 |
#[arg(short, long)] |
| 206 |
message: Option<String>, |
| 207 |
|
| 208 |
change: Option<String>, |
| 209 |
|
| 210 |
#[arg(long, conflicts_with = "message")] |
| 211 |
json: bool, |
| 212 |
}, |
| 213 |
|
| 214 |
Amend { |
| 215 |
|
| 216 |
#[arg(short, long)] |
| 217 |
message: Option<String>, |
| 218 |
|
| 219 |
#[arg(long)] |
| 220 |
into: Option<String>, |
| 221 |
}, |
| 222 |
|
| 223 |
Split { |
| 224 |
|
| 225 |
change: String, |
| 226 |
|
| 227 |
paths: Vec<String>, |
| 228 |
}, |
| 229 |
|
| 230 |
Abandon { |
| 231 |
|
| 232 |
change: String, |
| 233 |
}, |
| 234 |
|
| 235 |
Show { |
| 236 |
|
| 237 |
change: String, |
| 238 |
|
| 239 |
#[arg(long)] |
| 240 |
json: bool, |
| 241 |
}, |
| 242 |
|
| 243 |
Checkout { |
| 244 |
|
| 245 |
changes: Vec<String>, |
| 246 |
|
| 247 |
#[arg(long)] |
| 248 |
discard: bool, |
| 249 |
|
| 250 |
|
| 251 |
#[arg(long, conflicts_with = "discard")] |
| 252 |
carry: bool, |
| 253 |
}, |
| 254 |
|
| 255 |
Resolve { |
| 256 |
|
| 257 |
#[arg(long)] |
| 258 |
json: bool, |
| 259 |
}, |
| 260 |
|
| 261 |
Undo, |
| 262 |
|
| 263 |
Checkpoint, |
| 264 |
|
| 265 |
Completions { |
| 266 |
|
| 267 |
shell: clap_complete::Shell, |
| 268 |
}, |
| 269 |
|
| 270 |
Man { |
| 271 |
|
| 272 |
#[arg(long)] |
| 273 |
dir: Option<PathBuf>, |
| 274 |
}, |
| 275 |
|
| 276 |
Doctor { |
| 277 |
|
| 278 |
#[arg(long)] |
| 279 |
offline: bool, |
| 280 |
|
| 281 |
#[arg(long)] |
| 282 |
json: bool, |
| 283 |
}, |
| 284 |
|
| 285 |
Fsck { |
| 286 |
|
| 287 |
#[arg(long)] |
| 288 |
json: bool, |
| 289 |
}, |
| 290 |
|
| 291 |
Gc { |
| 292 |
|
| 293 |
#[arg(long)] |
| 294 |
now: bool, |
| 295 |
}, |
| 296 |
|
| 297 |
#[command(name = "op")] |
| 298 |
Op { |
| 299 |
#[command(subcommand)] |
| 300 |
cmd: OpCmd, |
| 301 |
}, |
| 302 |
|
| 303 |
Lock { |
| 304 |
|
| 305 |
path: String, |
| 306 |
}, |
| 307 |
|
| 308 |
Unlock { |
| 309 |
|
| 310 |
path: String, |
| 311 |
}, |
| 312 |
|
| 313 |
Workspace { |
| 314 |
#[command(subcommand)] |
| 315 |
cmd: WorkspaceCmd, |
| 316 |
}, |
| 317 |
|
| 318 |
Bookmark { |
| 319 |
#[command(subcommand)] |
| 320 |
cmd: BookmarkCmd, |
| 321 |
}, |
| 322 |
|
| 323 |
Merge { |
| 324 |
|
| 325 |
bookmark: String, |
| 326 |
}, |
| 327 |
|
| 328 |
Submodule { |
| 329 |
#[command(subcommand)] |
| 330 |
cmd: SubmoduleCmd, |
| 331 |
}, |
| 332 |
|
| 333 |
Receipt { |
| 334 |
#[command(subcommand)] |
| 335 |
cmd: ReceiptCmd, |
| 336 |
}, |
| 337 |
|
| 338 |
Tag { |
| 339 |
#[command(subcommand)] |
| 340 |
cmd: TagCmd, |
| 341 |
}, |
| 342 |
|
| 343 |
Remote { |
| 344 |
#[command(subcommand)] |
| 345 |
cmd: RemoteCmd, |
| 346 |
}, |
| 347 |
|
| 348 |
Fetch { |
| 349 |
|
| 350 |
remote: Option<String>, |
| 351 |
|
| 352 |
#[arg(long)] |
| 353 |
json: bool, |
| 354 |
}, |
| 355 |
|
| 356 |
Pull { |
| 357 |
|
| 358 |
remote: Option<String>, |
| 359 |
|
| 360 |
#[arg(long)] |
| 361 |
json: bool, |
| 362 |
}, |
| 363 |
|
| 364 |
Push { |
| 365 |
|
| 366 |
remote: Option<String>, |
| 367 |
|
| 368 |
#[arg(long)] |
| 369 |
force: bool, |
| 370 |
|
| 371 |
#[arg(short = 'b', long)] |
| 372 |
bookmark: Option<String>, |
| 373 |
|
| 374 |
|
| 375 |
#[arg(long, value_name = "NAME", conflicts_with_all = ["bookmark", "force"])] |
| 376 |
delete: Option<String>, |
| 377 |
|
| 378 |
#[arg(long)] |
| 379 |
json: bool, |
| 380 |
}, |
| 381 |
|
| 382 |
Serve { |
| 383 |
|
| 384 |
#[arg(long, default_value = ".")] |
| 385 |
root: PathBuf, |
| 386 |
|
| 387 |
#[arg(long, default_value = "127.0.0.1:8890")] |
| 388 |
bind: String, |
| 389 |
|
| 390 |
#[arg(long = "token")] |
| 391 |
tokens: Vec<String>, |
| 392 |
|
| 393 |
#[arg(long, requires = "tls_key")] |
| 394 |
tls_cert: Option<PathBuf>, |
| 395 |
|
| 396 |
#[arg(long, requires = "tls_cert")] |
| 397 |
tls_key: Option<PathBuf>, |
| 398 |
}, |
| 399 |
|
| 400 |
Identity { |
| 401 |
#[command(subcommand)] |
| 402 |
cmd: IdentityCmd, |
| 403 |
}, |
| 404 |
|
| 405 |
Seal { |
| 406 |
|
| 407 |
changes: Vec<String>, |
| 408 |
|
| 409 |
#[arg(long, conflicts_with = "changes")] |
| 410 |
proposal: Option<String>, |
| 411 |
|
| 412 |
#[arg(long)] |
| 413 |
json: bool, |
| 414 |
}, |
| 415 |
|
| 416 |
Proposal { |
| 417 |
#[command(subcommand)] |
| 418 |
cmd: ProposalCmd, |
| 419 |
}, |
| 420 |
|
| 421 |
Verify { |
| 422 |
|
| 423 |
change: Option<String>, |
| 424 |
|
| 425 |
#[arg(long)] |
| 426 |
json: bool, |
| 427 |
}, |
| 428 |
|
| 429 |
Git { |
| 430 |
#[command(subcommand)] |
| 431 |
cmd: GitCmd, |
| 432 |
}, |
| 433 |
|
| 434 |
Policy { |
| 435 |
#[command(subcommand)] |
| 436 |
cmd: PolicyCmd, |
| 437 |
}, |
| 438 |
|
| 439 |
Config { |
| 440 |
|
| 441 |
key: String, |
| 442 |
|
| 443 |
value: String, |
| 444 |
|
| 445 |
#[arg(long)] |
| 446 |
user: bool, |
| 447 |
}, |
| 448 |
} |
| 449 |
|
| 450 |
#[derive(Subcommand)] |
| 451 |
enum OpCmd { |
| 452 |
|
| 453 |
Log { |
| 454 |
|
| 455 |
#[arg(long)] |
| 456 |
json: bool, |
| 457 |
}, |
| 458 |
} |
| 459 |
|
| 460 |
#[derive(Subcommand)] |
| 461 |
enum WorkspaceCmd { |
| 462 |
|
| 463 |
Add { |
| 464 |
|
| 465 |
path: PathBuf, |
| 466 |
|
| 467 |
changes: Vec<String>, |
| 468 |
}, |
| 469 |
|
| 470 |
List { |
| 471 |
|
| 472 |
#[arg(long)] |
| 473 |
json: bool, |
| 474 |
}, |
| 475 |
|
| 476 |
Forget { |
| 477 |
|
| 478 |
workspace: String, |
| 479 |
}, |
| 480 |
} |
| 481 |
|
| 482 |
#[derive(Subcommand)] |
| 483 |
enum BisectCmd { |
| 484 |
|
| 485 |
Start, |
| 486 |
|
| 487 |
Good { |
| 488 |
|
| 489 |
changes: Vec<String>, |
| 490 |
}, |
| 491 |
|
| 492 |
Bad { |
| 493 |
|
| 494 |
changes: Vec<String>, |
| 495 |
}, |
| 496 |
|
| 497 |
Skip, |
| 498 |
|
| 499 |
Run { |
| 500 |
|
| 501 |
#[arg(required = true, trailing_var_arg = true)] |
| 502 |
command: Vec<String>, |
| 503 |
}, |
| 504 |
|
| 505 |
Status { |
| 506 |
|
| 507 |
#[arg(long)] |
| 508 |
json: bool, |
| 509 |
}, |
| 510 |
|
| 511 |
Reset, |
| 512 |
} |
| 513 |
|
| 514 |
#[derive(Subcommand)] |
| 515 |
enum BookmarkCmd { |
| 516 |
|
| 517 |
Create { |
| 518 |
|
| 519 |
name: String, |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
changes: Vec<String>, |
| 525 |
|
| 526 |
|
| 527 |
#[arg(long, conflicts_with = "only")] |
| 528 |
upto: bool, |
| 529 |
|
| 530 |
#[arg(long)] |
| 531 |
only: bool, |
| 532 |
}, |
| 533 |
|
| 534 |
Set { |
| 535 |
|
| 536 |
name: String, |
| 537 |
|
| 538 |
changes: Vec<String>, |
| 539 |
}, |
| 540 |
|
| 541 |
Delete { |
| 542 |
|
| 543 |
name: String, |
| 544 |
}, |
| 545 |
|
| 546 |
List { |
| 547 |
|
| 548 |
#[arg(long)] |
| 549 |
json: bool, |
| 550 |
}, |
| 551 |
|
| 552 |
Switch { |
| 553 |
|
| 554 |
name: String, |
| 555 |
|
| 556 |
#[arg(long)] |
| 557 |
discard: bool, |
| 558 |
|
| 559 |
|
| 560 |
#[arg(long, conflicts_with = "discard")] |
| 561 |
carry: bool, |
| 562 |
}, |
| 563 |
} |
| 564 |
|
| 565 |
#[derive(Subcommand)] |
| 566 |
enum SubmoduleCmd { |
| 567 |
|
| 568 |
Add { |
| 569 |
|
| 570 |
url: String, |
| 571 |
|
| 572 |
path: String, |
| 573 |
|
| 574 |
#[arg(long)] |
| 575 |
bookmark: Option<String>, |
| 576 |
}, |
| 577 |
|
| 578 |
Update { |
| 579 |
|
| 580 |
#[arg(long)] |
| 581 |
init: bool, |
| 582 |
|
| 583 |
paths: Vec<String>, |
| 584 |
}, |
| 585 |
|
| 586 |
Status { |
| 587 |
|
| 588 |
#[arg(long)] |
| 589 |
json: bool, |
| 590 |
}, |
| 591 |
|
| 592 |
Remove { |
| 593 |
|
| 594 |
path: String, |
| 595 |
}, |
| 596 |
} |
| 597 |
|
| 598 |
#[derive(Subcommand)] |
| 599 |
enum ReceiptCmd { |
| 600 |
|
| 601 |
List { |
| 602 |
|
| 603 |
rev: Option<String>, |
| 604 |
|
| 605 |
#[arg(long)] |
| 606 |
json: bool, |
| 607 |
}, |
| 608 |
|
| 609 |
Show { |
| 610 |
|
| 611 |
receipt: String, |
| 612 |
|
| 613 |
#[arg(long)] |
| 614 |
rev: Option<String>, |
| 615 |
|
| 616 |
#[arg(long)] |
| 617 |
json: bool, |
| 618 |
}, |
| 619 |
|
| 620 |
Export { |
| 621 |
|
| 622 |
receipt: String, |
| 623 |
|
| 624 |
file: String, |
| 625 |
|
| 626 |
#[arg(long)] |
| 627 |
rev: Option<String>, |
| 628 |
}, |
| 629 |
|
| 630 |
Verify { |
| 631 |
|
| 632 |
file: String, |
| 633 |
|
| 634 |
#[arg(long)] |
| 635 |
json: bool, |
| 636 |
}, |
| 637 |
|
| 638 |
Import { |
| 639 |
|
| 640 |
file: String, |
| 641 |
}, |
| 642 |
} |
| 643 |
|
| 644 |
#[derive(Subcommand)] |
| 645 |
enum TagCmd { |
| 646 |
|
| 647 |
Create { |
| 648 |
|
| 649 |
name: String, |
| 650 |
|
| 651 |
changes: Vec<String>, |
| 652 |
|
| 653 |
#[arg(short, long, default_value = "")] |
| 654 |
message: String, |
| 655 |
}, |
| 656 |
|
| 657 |
List { |
| 658 |
|
| 659 |
#[arg(long)] |
| 660 |
json: bool, |
| 661 |
}, |
| 662 |
} |
| 663 |
|
| 664 |
#[derive(Subcommand)] |
| 665 |
enum RemoteCmd { |
| 666 |
|
| 667 |
Add { |
| 668 |
|
| 669 |
name: String, |
| 670 |
|
| 671 |
url: String, |
| 672 |
}, |
| 673 |
|
| 674 |
Remove { |
| 675 |
|
| 676 |
name: String, |
| 677 |
}, |
| 678 |
|
| 679 |
List { |
| 680 |
|
| 681 |
#[arg(long)] |
| 682 |
json: bool, |
| 683 |
}, |
| 684 |
} |
| 685 |
|
| 686 |
#[derive(Subcommand)] |
| 687 |
enum ProposalCmd { |
| 688 |
|
| 689 |
Show { |
| 690 |
|
| 691 |
url: String, |
| 692 |
|
| 693 |
#[arg(long)] |
| 694 |
json: bool, |
| 695 |
}, |
| 696 |
|
| 697 |
Land { |
| 698 |
|
| 699 |
url: String, |
| 700 |
|
| 701 |
#[arg(long)] |
| 702 |
force: bool, |
| 703 |
}, |
| 704 |
} |
| 705 |
|
| 706 |
#[derive(Subcommand)] |
| 707 |
enum IdentityCmd { |
| 708 |
|
| 709 |
Create { |
| 710 |
|
| 711 |
#[arg(long)] |
| 712 |
name: Option<String>, |
| 713 |
|
| 714 |
#[arg(long)] |
| 715 |
email: Option<String>, |
| 716 |
|
| 717 |
#[arg(long)] |
| 718 |
local: bool, |
| 719 |
|
| 720 |
#[arg(long)] |
| 721 |
expires: Option<u64>, |
| 722 |
}, |
| 723 |
|
| 724 |
Show, |
| 725 |
|
| 726 |
Export { |
| 727 |
|
| 728 |
path: Option<PathBuf>, |
| 729 |
}, |
| 730 |
|
| 731 |
SignChallenge { |
| 732 |
|
| 733 |
challenge: String, |
| 734 |
|
| 735 |
#[arg(long)] |
| 736 |
json: bool, |
| 737 |
}, |
| 738 |
|
| 739 |
Rotate, |
| 740 |
|
| 741 |
Renew { |
| 742 |
|
| 743 |
#[arg(long)] |
| 744 |
expires: u64, |
| 745 |
}, |
| 746 |
|
| 747 |
Revoke { |
| 748 |
|
| 749 |
key: Option<String>, |
| 750 |
|
| 751 |
#[arg(long, default_value = "")] |
| 752 |
reason: String, |
| 753 |
}, |
| 754 |
|
| 755 |
Delegate { |
| 756 |
#[command(subcommand)] |
| 757 |
cmd: DelegateCmd, |
| 758 |
}, |
| 759 |
} |
| 760 |
|
| 761 |
#[derive(Subcommand)] |
| 762 |
enum DelegateCmd { |
| 763 |
|
| 764 |
Add { |
| 765 |
|
| 766 |
identity_file: PathBuf, |
| 767 |
}, |
| 768 |
|
| 769 |
Remove { |
| 770 |
|
| 771 |
key: String, |
| 772 |
}, |
| 773 |
|
| 774 |
List, |
| 775 |
} |
| 776 |
|
| 777 |
#[derive(Subcommand)] |
| 778 |
enum GitCmd { |
| 779 |
|
| 780 |
Export { |
| 781 |
|
| 782 |
git_dir: PathBuf, |
| 783 |
|
| 784 |
#[arg(long)] |
| 785 |
branch: Option<String>, |
| 786 |
}, |
| 787 |
|
| 788 |
Fetch { |
| 789 |
|
| 790 |
url: String, |
| 791 |
|
| 792 |
#[arg(long, default_value = "main")] |
| 793 |
branch: String, |
| 794 |
}, |
| 795 |
|
| 796 |
Push { |
| 797 |
|
| 798 |
url: String, |
| 799 |
|
| 800 |
#[arg(long, default_value = "main")] |
| 801 |
branch: String, |
| 802 |
}, |
| 803 |
|
| 804 |
Verify { |
| 805 |
|
| 806 |
git_dir: PathBuf, |
| 807 |
|
| 808 |
#[arg(long, default_value = "main")] |
| 809 |
branch: String, |
| 810 |
|
| 811 |
#[arg(long, value_name = "N")] |
| 812 |
last: Option<usize>, |
| 813 |
|
| 814 |
#[arg(long, value_name = "N", default_value_t = 50)] |
| 815 |
max_differences: usize, |
| 816 |
}, |
| 817 |
|
| 818 |
Import { |
| 819 |
|
| 820 |
git_dir: PathBuf, |
| 821 |
|
| 822 |
dest: PathBuf, |
| 823 |
|
| 824 |
#[arg(long, default_value = "main")] |
| 825 |
branch: String, |
| 826 |
}, |
| 827 |
} |
| 828 |
|
| 829 |
#[derive(Subcommand)] |
| 830 |
enum PolicyCmd { |
| 831 |
|
| 832 |
Init, |
| 833 |
|
| 834 |
Show { |
| 835 |
|
| 836 |
#[arg(long)] |
| 837 |
json: bool, |
| 838 |
}, |
| 839 |
|
| 840 |
Grant { |
| 841 |
|
| 842 |
identity_file: PathBuf, |
| 843 |
|
| 844 |
#[arg(long)] |
| 845 |
pattern: Option<String>, |
| 846 |
|
| 847 |
#[arg(long)] |
| 848 |
out: Option<PathBuf>, |
| 849 |
}, |
| 850 |
|
| 851 |
Revoke { |
| 852 |
|
| 853 |
key: String, |
| 854 |
|
| 855 |
#[arg(long)] |
| 856 |
out: Option<PathBuf>, |
| 857 |
}, |
| 858 |
|
| 859 |
Root { |
| 860 |
#[command(subcommand)] |
| 861 |
cmd: RootCmd, |
| 862 |
}, |
| 863 |
|
| 864 |
Sign { |
| 865 |
|
| 866 |
proposal: PathBuf, |
| 867 |
|
| 868 |
#[arg(long)] |
| 869 |
out: Option<PathBuf>, |
| 870 |
}, |
| 871 |
} |
| 872 |
|
| 873 |
#[derive(Subcommand)] |
| 874 |
enum RootCmd { |
| 875 |
|
| 876 |
Add { |
| 877 |
|
| 878 |
identity_file: PathBuf, |
| 879 |
|
| 880 |
#[arg(long)] |
| 881 |
out: Option<PathBuf>, |
| 882 |
}, |
| 883 |
|
| 884 |
Remove { |
| 885 |
|
| 886 |
key: String, |
| 887 |
|
| 888 |
#[arg(long)] |
| 889 |
out: Option<PathBuf>, |
| 890 |
}, |
| 891 |
|
| 892 |
Threshold { |
| 893 |
|
| 894 |
n: u32, |
| 895 |
|
| 896 |
#[arg(long)] |
| 897 |
out: Option<PathBuf>, |
| 898 |
}, |
| 899 |
} |
| 900 |
|
| 901 |
|
| 902 |
fn open() -> Result<Repo> { |
| 903 |
Repo::open(&std::env::current_dir()?).context("opening repository") |
| 904 |
} |
| 905 |
|
| 906 |
|
| 907 |
fn man(dir: Option<PathBuf>) -> Result<i32> { |
| 908 |
use clap::CommandFactory; |
| 909 |
let cmd = Cli::command(); |
| 910 |
match dir { |
| 911 |
Some(dir) => { |
| 912 |
std::fs::create_dir_all(&dir)?; |
| 913 |
clap_mangen::generate_to(cmd, &dir)?; |
| 914 |
let pages = std::fs::read_dir(&dir)? |
| 915 |
.filter(|e| { |
| 916 |
e.as_ref() |
| 917 |
.is_ok_and(|e| e.path().extension().is_some_and(|x| x == "1")) |
| 918 |
}) |
| 919 |
.count(); |
| 920 |
println!( |
| 921 |
"{}", |
| 922 |
ui::done(format!("Wrote {pages} man pages to {}", dir.display())) |
| 923 |
); |
| 924 |
} |
| 925 |
None => clap_mangen::Man::new(cmd).render(&mut std::io::stdout())?, |
| 926 |
} |
| 927 |
Ok(0) |
| 928 |
} |
| 929 |
|
| 930 |
|
| 931 |
pub fn run() -> Result<i32> { |
| 932 |
let cli = Cli::parse(); |
| 933 |
ui::init(cli.plain); |
| 934 |
match cli.cmd { |
| 935 |
Cmd::Completions { shell } => { |
| 936 |
use clap::CommandFactory; |
| 937 |
clap_complete::generate(shell, &mut Cli::command(), "oxy", &mut std::io::stdout()); |
| 938 |
Ok(0) |
| 939 |
} |
| 940 |
Cmd::Man { dir } => man(dir), |
| 941 |
Cmd::Init { path, bare } => workspace::init(path, bare), |
| 942 |
Cmd::Status { json } => workspace::status(json), |
| 943 |
Cmd::Prompt { |
| 944 |
format, |
| 945 |
glyphs, |
| 946 |
color, |
| 947 |
} => workspace::prompt(&format, glyphs, color.as_deref()), |
| 948 |
Cmd::Commit { |
| 949 |
message, |
| 950 |
file, |
| 951 |
depends_on, |
| 952 |
paths, |
| 953 |
interactive, |
| 954 |
hunks, |
| 955 |
} => { |
| 956 |
let message = match (message, file) { |
| 957 |
(Some(m), _) => m, |
| 958 |
(None, Some(f)) if f.as_os_str() == "-" => { |
| 959 |
let mut s = String::new(); |
| 960 |
std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)?; |
| 961 |
s |
| 962 |
} |
| 963 |
(None, Some(f)) => std::fs::read_to_string(&f).map_err(|e| { |
| 964 |
anyhow::anyhow!("reading the message from {}: {e}", f.display()) |
| 965 |
})?, |
| 966 |
(None, None) => anyhow::bail!("a commit message is required (-m or -F)"), |
| 967 |
}; |
| 968 |
workspace::commit(&message, &depends_on, &paths, interactive, &hunks) |
| 969 |
} |
| 970 |
Cmd::Cat { path, change } => workspace::cat(&path, change.as_deref()), |
| 971 |
Cmd::Root { json } => workspace::root(json), |
| 972 |
Cmd::Version { json } => workspace::version(json), |
| 973 |
Cmd::Discard { paths, hunks } => workspace::discard(&paths, &hunks), |
| 974 |
Cmd::Hunks { json } => workspace::hunks(json), |
| 975 |
Cmd::Squash { change, into } => workspace::squash(&change, &into), |
| 976 |
Cmd::Rebase { change, onto } => workspace::rebase(&change, &onto), |
| 977 |
Cmd::Blame { path, json } => workspace::blame(&path, json), |
| 978 |
Cmd::Bisect { cmd } => match cmd { |
| 979 |
BisectCmd::Start => workspace::bisect_start(), |
| 980 |
BisectCmd::Good { changes } => workspace::bisect_mark(Some(true), &changes), |
| 981 |
BisectCmd::Bad { changes } => workspace::bisect_mark(Some(false), &changes), |
| 982 |
BisectCmd::Skip => workspace::bisect_mark(None, &[]), |
| 983 |
BisectCmd::Run { command } => workspace::bisect_run(&command), |
| 984 |
BisectCmd::Status { json } => workspace::bisect_status(json), |
| 985 |
BisectCmd::Reset => workspace::bisect_reset(), |
| 986 |
}, |
| 987 |
Cmd::Log { |
| 988 |
limit, |
| 989 |
verbose, |
| 990 |
path, |
| 991 |
lines, |
| 992 |
json, |
| 993 |
} => workspace::log(limit, verbose, path.as_deref(), lines.as_deref(), json), |
| 994 |
Cmd::Diff { change, json } => workspace::diff(change.as_deref(), json), |
| 995 |
Cmd::Describe { |
| 996 |
message, |
| 997 |
change, |
| 998 |
json, |
| 999 |
} => match message { |
| 1000 |
Some(m) => workspace::describe(&m, change.as_deref()), |
| 1001 |
None if change.is_some() => { |
| 1002 |
anyhow::bail!( |
| 1003 |
"naming works on the working copy; to change a head's message pass -m" |
| 1004 |
) |
| 1005 |
} |
| 1006 |
None => workspace::describe_name(json), |
| 1007 |
}, |
| 1008 |
Cmd::Amend { message, into } => workspace::amend(message.as_deref(), into.as_deref()), |
| 1009 |
Cmd::Split { change, paths } => workspace::split(&change, &paths), |
| 1010 |
Cmd::Abandon { change } => workspace::abandon(&change), |
| 1011 |
Cmd::Show { change, json } => workspace::show(&change, json), |
| 1012 |
Cmd::Checkout { |
| 1013 |
changes, |
| 1014 |
discard, |
| 1015 |
carry, |
| 1016 |
} => workspace::checkout(&changes, discard, carry), |
| 1017 |
Cmd::Resolve { json } => workspace::resolve(json), |
| 1018 |
Cmd::Undo => workspace::undo(), |
| 1019 |
Cmd::Gc { now } => workspace::gc(now), |
| 1020 |
Cmd::Fsck { json } => workspace::fsck(json), |
| 1021 |
Cmd::Doctor { offline, json } => workspace::doctor(offline, json), |
| 1022 |
Cmd::Checkpoint => workspace::checkpoint(), |
| 1023 |
Cmd::Op { |
| 1024 |
cmd: OpCmd::Log { json }, |
| 1025 |
} => workspace::op_log(json), |
| 1026 |
Cmd::Clone { |
| 1027 |
url, |
| 1028 |
dest, |
| 1029 |
max_blob, |
| 1030 |
sparse, |
| 1031 |
depth, |
| 1032 |
} => sync::clone(&url, dest, max_blob.as_deref(), &sparse, depth), |
| 1033 |
Cmd::Deepen { depth, remote } => sync::deepen(&remote, depth), |
| 1034 |
Cmd::Sparse { paths } => workspace::sparse(&paths), |
| 1035 |
Cmd::Lock { path } => workspace::lock(&path), |
| 1036 |
Cmd::Unlock { path } => workspace::unlock(&path), |
| 1037 |
Cmd::Workspace { cmd } => match cmd { |
| 1038 |
WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes), |
| 1039 |
WorkspaceCmd::List { json } => workspace::workspace_list(json), |
| 1040 |
WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace), |
| 1041 |
}, |
| 1042 |
Cmd::Bookmark { cmd } => match cmd { |
| 1043 |
BookmarkCmd::Create { |
| 1044 |
name, |
| 1045 |
changes, |
| 1046 |
upto, |
| 1047 |
only, |
| 1048 |
} => workspace::bookmark_create(&name, &changes, upto, only), |
| 1049 |
BookmarkCmd::Set { name, changes } => workspace::bookmark_set(&name, &changes), |
| 1050 |
BookmarkCmd::Delete { name } => workspace::bookmark_delete(&name), |
| 1051 |
BookmarkCmd::List { json } => workspace::bookmark_list(json), |
| 1052 |
BookmarkCmd::Switch { |
| 1053 |
name, |
| 1054 |
discard, |
| 1055 |
carry, |
| 1056 |
} => workspace::bookmark_switch(&name, discard, carry), |
| 1057 |
}, |
| 1058 |
Cmd::Merge { bookmark } => workspace::merge(&bookmark), |
| 1059 |
Cmd::Submodule { cmd } => match cmd { |
| 1060 |
SubmoduleCmd::Add { |
| 1061 |
url, |
| 1062 |
path, |
| 1063 |
bookmark, |
| 1064 |
} => sync::submodule_add(&url, &path, bookmark.as_deref()), |
| 1065 |
SubmoduleCmd::Update { init, paths } => sync::submodule_update(init, &paths), |
| 1066 |
SubmoduleCmd::Status { json } => sync::submodule_status(json), |
| 1067 |
SubmoduleCmd::Remove { path } => sync::submodule_remove(&path), |
| 1068 |
}, |
| 1069 |
Cmd::Receipt { cmd } => match cmd { |
| 1070 |
ReceiptCmd::List { rev, json } => receipt::list(rev.as_deref(), json), |
| 1071 |
ReceiptCmd::Show { |
| 1072 |
receipt: r, |
| 1073 |
rev, |
| 1074 |
json, |
| 1075 |
} => receipt::show(&r, rev.as_deref(), json), |
| 1076 |
ReceiptCmd::Export { |
| 1077 |
receipt: r, |
| 1078 |
file, |
| 1079 |
rev, |
| 1080 |
} => receipt::export(&r, &file, rev.as_deref()), |
| 1081 |
ReceiptCmd::Verify { file, json } => receipt::verify(&file, json), |
| 1082 |
ReceiptCmd::Import { file } => receipt::import(&file), |
| 1083 |
}, |
| 1084 |
Cmd::Tag { cmd } => match cmd { |
| 1085 |
TagCmd::Create { |
| 1086 |
name, |
| 1087 |
changes, |
| 1088 |
message, |
| 1089 |
} => workspace::tag_create(&name, &changes, &message), |
| 1090 |
TagCmd::List { json } => workspace::tag_list(json), |
| 1091 |
}, |
| 1092 |
Cmd::Remote { cmd } => match cmd { |
| 1093 |
RemoteCmd::Add { name, url } => sync::remote_add(&name, &url), |
| 1094 |
RemoteCmd::Remove { name } => sync::remote_remove(&name), |
| 1095 |
RemoteCmd::List { json } => sync::remote_list(json), |
| 1096 |
}, |
| 1097 |
Cmd::Fetch { remote, json } => sync::fetch(remote.as_deref(), json), |
| 1098 |
Cmd::Pull { remote, json } => sync::pull(remote.as_deref(), json), |
| 1099 |
Cmd::Push { |
| 1100 |
remote, |
| 1101 |
force, |
| 1102 |
bookmark, |
| 1103 |
delete, |
| 1104 |
json, |
| 1105 |
} => match delete { |
| 1106 |
Some(name) => sync::push_delete(remote.as_deref(), &name, json), |
| 1107 |
None => sync::push(remote.as_deref(), force, bookmark.as_deref(), json), |
| 1108 |
}, |
| 1109 |
Cmd::Serve { |
| 1110 |
root, |
| 1111 |
bind, |
| 1112 |
tokens, |
| 1113 |
tls_cert, |
| 1114 |
tls_key, |
| 1115 |
} => sync::serve(root, &bind, tokens, tls_cert.zip(tls_key)), |
| 1116 |
Cmd::Identity { cmd } => match cmd { |
| 1117 |
IdentityCmd::Create { |
| 1118 |
name, |
| 1119 |
email, |
| 1120 |
local, |
| 1121 |
expires, |
| 1122 |
} => identity::create(name, email, local, expires), |
| 1123 |
IdentityCmd::Show => identity::show(), |
| 1124 |
IdentityCmd::Export { path } => identity::export(path), |
| 1125 |
IdentityCmd::SignChallenge { challenge, json } => { |
| 1126 |
identity::sign_challenge(&challenge, json) |
| 1127 |
} |
| 1128 |
IdentityCmd::Rotate => identity::rotate(), |
| 1129 |
IdentityCmd::Renew { expires } => identity::renew(expires), |
| 1130 |
IdentityCmd::Revoke { key, reason } => identity::revoke(key.as_deref(), &reason), |
| 1131 |
IdentityCmd::Delegate { cmd } => match cmd { |
| 1132 |
DelegateCmd::Add { identity_file } => identity::delegate_add(&identity_file), |
| 1133 |
DelegateCmd::Remove { key } => identity::delegate_remove(&key), |
| 1134 |
DelegateCmd::List => identity::delegate_list(), |
| 1135 |
}, |
| 1136 |
}, |
| 1137 |
Cmd::Git { |
| 1138 |
cmd: GitCmd::Export { git_dir, branch }, |
| 1139 |
} => sync::git_export(&git_dir, branch.as_deref()), |
| 1140 |
Cmd::Git { |
| 1141 |
cmd: GitCmd::Fetch { url, branch }, |
| 1142 |
} => sync::git_fetch(&url, &branch), |
| 1143 |
Cmd::Git { |
| 1144 |
cmd: GitCmd::Push { url, branch }, |
| 1145 |
} => sync::git_push(&url, &branch), |
| 1146 |
Cmd::Git { |
| 1147 |
cmd: |
| 1148 |
GitCmd::Import { |
| 1149 |
git_dir, |
| 1150 |
dest, |
| 1151 |
branch, |
| 1152 |
}, |
| 1153 |
} => sync::git_import(&git_dir, &dest, &branch), |
| 1154 |
Cmd::Git { |
| 1155 |
cmd: |
| 1156 |
GitCmd::Verify { |
| 1157 |
git_dir, |
| 1158 |
branch, |
| 1159 |
last, |
| 1160 |
max_differences, |
| 1161 |
}, |
| 1162 |
} => sync::git_verify(&git_dir, &branch, last, max_differences), |
| 1163 |
Cmd::Policy { cmd } => match cmd { |
| 1164 |
PolicyCmd::Init => identity::policy_init(), |
| 1165 |
PolicyCmd::Show { json } => identity::policy_show(json), |
| 1166 |
PolicyCmd::Grant { |
| 1167 |
identity_file, |
| 1168 |
pattern, |
| 1169 |
out, |
| 1170 |
} => identity::policy_grant(&identity_file, pattern.as_deref(), out), |
| 1171 |
PolicyCmd::Revoke { key, out } => identity::policy_revoke(&key, out), |
| 1172 |
PolicyCmd::Root { cmd } => match cmd { |
| 1173 |
RootCmd::Add { identity_file, out } => { |
| 1174 |
identity::policy_root_add(&identity_file, out) |
| 1175 |
} |
| 1176 |
RootCmd::Remove { key, out } => identity::policy_root_remove(&key, out), |
| 1177 |
RootCmd::Threshold { n, out } => identity::policy_threshold(n, out), |
| 1178 |
}, |
| 1179 |
PolicyCmd::Sign { proposal, out } => identity::policy_sign(&proposal, out), |
| 1180 |
}, |
| 1181 |
Cmd::Seal { |
| 1182 |
changes, |
| 1183 |
proposal: Some(url), |
| 1184 |
json, |
| 1185 |
} if changes.is_empty() => proposal::seal(&url, json), |
| 1186 |
Cmd::Seal { changes, json, .. } => identity::seal(&changes, json), |
| 1187 |
Cmd::Proposal { cmd } => match cmd { |
| 1188 |
ProposalCmd::Show { url, json } => proposal::show(&url, json), |
| 1189 |
ProposalCmd::Land { url, force } => proposal::land(&url, force), |
| 1190 |
}, |
| 1191 |
Cmd::Verify { change, json } => identity::verify(change.as_deref(), json), |
| 1192 |
Cmd::Config { key, value, user } => identity::config(&key, &value, user), |
| 1193 |
} |
| 1194 |
} |
| 1195 |
|
| 1196 |
#[cfg(test)] |
| 1197 |
mod help_tests { |
| 1198 |
use super::Cli; |
| 1199 |
use clap::CommandFactory; |
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
#[test] |
| 1204 |
fn every_command_and_argument_has_help() { |
| 1205 |
fn walk(cmd: &clap::Command, path: &str, missing: &mut Vec<String>) { |
| 1206 |
let here = format!("{path} {}", cmd.get_name()).trim().to_string(); |
| 1207 |
if cmd.get_about().is_none() && path != "" { |
| 1208 |
missing.push(format!("{here} (command)")); |
| 1209 |
} |
| 1210 |
for a in cmd.get_arguments() { |
| 1211 |
let id = a.get_id().as_str(); |
| 1212 |
if id == "help" || id == "version" || a.is_global_set() && path != "" { |
| 1213 |
continue; |
| 1214 |
} |
| 1215 |
if a.get_help().is_none() && a.get_long_help().is_none() { |
| 1216 |
missing.push(format!("{here} {id}")); |
| 1217 |
} |
| 1218 |
} |
| 1219 |
for sub in cmd.get_subcommands() { |
| 1220 |
walk(sub, &here, missing); |
| 1221 |
} |
| 1222 |
} |
| 1223 |
let mut missing = Vec::new(); |
| 1224 |
walk(&Cli::command(), "", &mut missing); |
| 1225 |
assert!( |
| 1226 |
missing.is_empty(), |
| 1227 |
"{} without help:\n{}", |
| 1228 |
missing.len(), |
| 1229 |
missing.join("\n") |
| 1230 |
); |
| 1231 |
} |
| 1232 |
} |