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