Machine interface: --json on tag list and workspace list 1196b29b5fa9
- Author
- Andy McCall @andymccall <[email protected]>
- When
- · 2026-09-27 15:57 UTC
- Signature
- ✔ signed by Andy McCall
- Hash
1196b29b5fa9fdd7d4a3d06b34c9afa270d0c02d4a1fb810e958cedf20e9da7e- Depends on
- 132b884b9a8d 4e88e774777a c6aa5bd9d1c8 fce44ae9ad29
- Depended on by
- b63fc7a77fc6 d42369abf180 75167672ebcd
- In bookmarks
- agents-in-readme bare-hashes carried-not-removed carry-identical doctor-trust identical-sides keyless-tags main merge-remote-bookmark only-help-103 paths-for-resolutions-and-amend push-notes show-stat subrepo-pin-state switch-says
- In tags
- v0.1.0 v0.10.0 v0.11.0 v0.2.0 v0.3.0 v0.3.1 v0.4.0 v0.4.1 v0.4.2 v0.4.3 v0.4.4 v0.4.5 v0.4.6 v0.5.0 v0.5.1 v0.6.0 v0.7.0 v0.8.0 v0.9.0
- Edits
- 11 atoms, 0 tree operations, 3 files
Browse the tree at this change
modified src/cli/mod.rs +10 −4
| … | 326 unchanged lines |
||
| 327 | 327 | enum WorkspaceCmd { |
|
| 328 | 328 | /// Create a workspace at PATH checked out on CHANGE... (default: the bookmark heads) |
|
| 329 | 329 | Add { path: PathBuf, changes: Vec<String> }, |
|
| 330 | - | List, |
|
| 330 | + | List { |
|
| 331 | + | #[arg(long)] |
|
| 332 | + | json: bool, |
|
| 333 | + | }, |
|
| 331 | 334 | /// Stop tracking a workspace (by id prefix or path); its files stay |
|
| 332 | 335 | Forget { workspace: String }, |
|
| 333 | 336 | } |
|
| … | 79 unchanged lines |
||
| 413 | 416 | #[arg(short, long, default_value = "")] |
|
| 414 | 417 | message: String, |
|
| 415 | 418 | }, |
|
| 416 | - | List, |
|
| 419 | + | List { |
|
| 420 | + | #[arg(long)] |
|
| 421 | + | json: bool, |
|
| 422 | + | }, |
|
| 417 | 423 | } |
|
| 418 | 424 | ||
| 419 | 425 | #[derive(Subcommand)] |
|
| … | 199 unchanged lines |
||
| 619 | 625 | Cmd::Unlock { path } => workspace::unlock(&path), |
|
| 620 | 626 | Cmd::Workspace { cmd } => match cmd { |
|
| 621 | 627 | WorkspaceCmd::Add { path, changes } => workspace::workspace_add(&path, &changes), |
|
| 622 | - | WorkspaceCmd::List => workspace::workspace_list(), |
|
| 628 | + | WorkspaceCmd::List { json } => workspace::workspace_list(json), |
|
| 623 | 629 | WorkspaceCmd::Forget { workspace } => workspace::workspace_forget(&workspace), |
|
| 624 | 630 | }, |
|
| 625 | 631 | Cmd::Bookmark { cmd } => match cmd { |
|
| … | 12 unchanged lines |
||
| 638 | 644 | }, |
|
| 639 | 645 | Cmd::Tag { cmd } => match cmd { |
|
| 640 | 646 | TagCmd::Create { name, changes, message } => workspace::tag_create(&name, &changes, &message), |
|
| 641 | - | TagCmd::List => workspace::tag_list(), |
|
| 647 | + | TagCmd::List { json } => workspace::tag_list(json), |
|
| 642 | 648 | }, |
|
| 643 | 649 | Cmd::Remote { cmd } => match cmd { |
|
| 644 | 650 | RemoteCmd::Add { name, url } => sync::remote_add(&name, &url), |
|
| … | 40 unchanged lines |
modified src/cli/workspace.rs +31 −2
| … | 755 unchanged lines |
||
| 756 | 756 | Ok(0) |
|
| 757 | 757 | } |
|
| 758 | 758 | ||
| 759 | - | pub fn tag_list() -> Result<i32> { |
|
| 759 | + | pub fn tag_list(as_json: bool) -> Result<i32> { |
|
| 760 | 760 | let repo = open()?; |
|
| 761 | 761 | let tags = repo.tags()?; |
|
| 762 | + | if as_json { |
|
| 763 | + | println!( |
|
| 764 | + | "{}", |
|
| 765 | + | json::arr(tags.iter().map(|t| { |
|
| 766 | + | json::obj([ |
|
| 767 | + | ("name", json::s(&t.name)), |
|
| 768 | + | ("state", json::s(&t.state.to_hex())), |
|
| 769 | + | ("heads", json::hashes(&t.heads)), |
|
| 770 | + | ("message", json::s(&t.message)), |
|
| 771 | + | ("signer", json::opt(t.signer.as_ref(), |s| json::s(&s.to_string()))), |
|
| 772 | + | ]) |
|
| 773 | + | })) |
|
| 774 | + | ); |
|
| 775 | + | return Ok(0); |
|
| 776 | + | } |
|
| 762 | 777 | if tags.is_empty() { |
|
| 763 | 778 | println!("{}", ui::dim("No tags.")); |
|
| 764 | 779 | } |
|
| … | 28 unchanged lines |
||
| 793 | 808 | Ok(0) |
|
| 794 | 809 | } |
|
| 795 | 810 | ||
| 796 | - | pub fn workspace_list() -> Result<i32> { |
|
| 811 | + | pub fn workspace_list(as_json: bool) -> Result<i32> { |
|
| 797 | 812 | let repo = open()?; |
|
| 813 | + | if as_json { |
|
| 814 | + | println!( |
|
| 815 | + | "{}", |
|
| 816 | + | json::arr(repo.workspaces()?.iter().map(|w| { |
|
| 817 | + | json::obj([ |
|
| 818 | + | ("id", json::s(&w.id.to_hex())), |
|
| 819 | + | ("path", json::s(&w.path.to_string_lossy())), |
|
| 820 | + | ("current", json::b(w.current)), |
|
| 821 | + | ("working_copy", json::opt(w.working_copy, |h| json::s(&h.to_hex()))), |
|
| 822 | + | ]) |
|
| 823 | + | })) |
|
| 824 | + | ); |
|
| 825 | + | return Ok(0); |
|
| 826 | + | } |
|
| 798 | 827 | for w in repo.workspaces()? { |
|
| 799 | 828 | println!( |
|
| 800 | 829 | "{} {} {}{}", |
|
| … | 171 unchanged lines |
modified tests/cli_json.rs +5 −0
| … | 114 unchanged lines |
||
| 115 | 115 | assert_eq!(oxy(r, &home, &["policy", "init"]).0, 0); |
|
| 116 | 116 | let policy = json(r, &home, &["policy", "show", "--json"]); |
|
| 117 | 117 | assert_eq!(policy["roots"][0]["name"], "Ada"); |
|
| 118 | + | assert_eq!(oxy(r, &home, &["tag", "create", "v1", "-m", "first tag"]).0, 0); |
|
| 119 | + | let tags = json(r, &home, &["tag", "list", "--json"]); |
|
| 120 | + | assert_eq!((tags[0]["name"].as_str(), tags[0]["message"].as_str()), (Some("v1"), Some("first tag"))); |
|
| 121 | + | let ws = json(r, &home, &["workspace", "list", "--json"]); |
|
| 122 | + | assert_eq!((ws.as_array().unwrap().len(), ws[0]["current"].as_bool()), (1, Some(true))); |
|
| 118 | 123 | } |