Skip to content

Commit b6d3841

Browse files
authored
Merge pull request #178 from ia7ck/bundle-remote
git clone して bundle できるようにする
2 parents 85892e1 + f2e28ee commit b6d3841

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

tool/bundle/src/main.rs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ use serde::Deserialize;
1010
fn main() -> Result<()> {
1111
let args = Args::parse();
1212

13-
let bundled_code = bundle_crate(&args.crate_name, Path::new(&args.workspace))
13+
let workspace_path = if args.remote {
14+
download_remote_repository()?
15+
} else {
16+
args.workspace.into()
17+
};
18+
19+
let bundled_code = bundle_crate(&args.crate_name, &workspace_path)
1420
.with_context(|| format!("Failed to bundle crate '{}'", args.crate_name))?;
1521

1622
if args.skip_compile {
@@ -58,14 +64,51 @@ struct Args {
5864
crate_name: String,
5965

6066
/// Path to the workspace root
61-
#[clap(short, long, default_value = ".")]
67+
#[clap(short, long, default_value = ".", conflicts_with = "remote")]
6268
workspace: String,
6369

70+
/// Use remote repository (https://github.com/ia7ck/rust-competitive-programming)
71+
#[clap(long, conflicts_with = "workspace")]
72+
remote: bool,
73+
6474
/// Skip compilation check
6575
#[clap(long)]
6676
skip_compile: bool,
6777
}
6878

79+
fn download_remote_repository() -> Result<std::path::PathBuf> {
80+
eprintln!("📥 Cloning remote repository...");
81+
82+
let temp_dir = std::env::temp_dir().join(format!(
83+
"rust-competitive-programming-{}",
84+
std::process::id()
85+
));
86+
87+
if temp_dir.exists() {
88+
fs::remove_dir_all(&temp_dir).context("Failed to remove existing temp directory")?;
89+
}
90+
91+
let output = Command::new("git")
92+
.args([
93+
"clone",
94+
"--depth",
95+
"1",
96+
"https://github.com/ia7ck/rust-competitive-programming.git",
97+
])
98+
.arg(&temp_dir)
99+
.output()
100+
.context("Failed to run git clone. Make sure git is installed and available in PATH.")?;
101+
102+
if !output.status.success() {
103+
let stderr = String::from_utf8_lossy(&output.stderr);
104+
anyhow::bail!("Git clone failed:\n{}", stderr);
105+
}
106+
107+
eprintln!("✅ Repository cloned to temporary directory");
108+
109+
Ok(temp_dir)
110+
}
111+
69112
struct CrateInfo {
70113
content: String,
71114
dependencies: Vec<String>,

0 commit comments

Comments
 (0)