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