feat(worktree): add managed workspace cloning (#30117)
This commit is contained in:
parent
331bed2469
commit
5661af2034
23 changed files with 2374 additions and 28 deletions
13
packages/worktree/crates/cli/Cargo.toml
Normal file
13
packages/worktree/crates/cli/Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "worktree-cli"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[[bin]]
|
||||
name = "worktree"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
clap.workspace = true
|
||||
worktree = { path = "../core" }
|
||||
79
packages/worktree/crates/cli/src/main.rs
Normal file
79
packages/worktree/crates/cli/src/main.rs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
use clap::{Parser, Subcommand};
|
||||
use std::path::PathBuf;
|
||||
use worktree::{Create, Link, Manager};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "worktree")]
|
||||
struct Cli {
|
||||
#[arg(long, hide = true)]
|
||||
database: Option<PathBuf>,
|
||||
#[command(subcommand)]
|
||||
command: Command,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Command {
|
||||
Create {
|
||||
from: Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
name: Option<String>,
|
||||
#[arg(long)]
|
||||
into: Option<PathBuf>,
|
||||
},
|
||||
Remove {
|
||||
at: PathBuf,
|
||||
},
|
||||
Link {
|
||||
at: PathBuf,
|
||||
#[arg(long)]
|
||||
to: Option<PathBuf>,
|
||||
},
|
||||
Children {
|
||||
of: PathBuf,
|
||||
},
|
||||
Ancestors {
|
||||
of: PathBuf,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if let Err(error) = run() {
|
||||
eprintln!("worktree: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> worktree::Result<()> {
|
||||
let cli = Cli::parse();
|
||||
let mut manager = match cli.database {
|
||||
Some(path) => Manager::open(path)?,
|
||||
None => Manager::open_default()?,
|
||||
};
|
||||
match cli.command {
|
||||
Command::Create { from, name, into } => {
|
||||
println!(
|
||||
"{}",
|
||||
manager
|
||||
.create(Create {
|
||||
from: from.unwrap_or(std::env::current_dir()?),
|
||||
name,
|
||||
into,
|
||||
})?
|
||||
.display()
|
||||
);
|
||||
}
|
||||
Command::Remove { at } => manager.remove(at)?,
|
||||
Command::Link { at, to } => manager.link(Link { at, to })?,
|
||||
Command::Children { of } => {
|
||||
for path in manager.children(of)? {
|
||||
println!("{}", path.display());
|
||||
}
|
||||
}
|
||||
Command::Ancestors { of } => {
|
||||
for path in manager.ancestors(of)? {
|
||||
println!("{}", path.display());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue