| 114 | } |
| 115 | |
| 116 | pub fn fetch(&self) -> anyhow::Result<()> { |
| 117 | if self.path.exists() { |
| 118 | return Ok(()); |
| 119 | } |
| 120 | fs::create_dir_all(&self.path).with_context(|| { |
| 121 | format!( |
| 122 | "Failed to create standard library version directory {}", |
| 123 | self.version |
| 124 | ) |
| 125 | })?; |
| 126 | if !Command::new("git") |
| 127 | .args([ |
| 128 | "clone", |
| 129 | "--depth=1", |
| 130 | "https://github.com/goboscript/std", |
| 131 | "--branch", |
| 132 | &format!("v{}", self.version), |
| 133 | self.path.to_str().unwrap(), |
| 134 | ]) |
| 135 | .stdout(Stdio::null()) |
| 136 | .stderr(Stdio::null()) |
| 137 | .status() |
| 138 | .with_context(|| format!("Failed to clone standard library version {}", self.version))? |
| 139 | .success() |
| 140 | { |
| 141 | bail!("Failed to clone standard library version {}", self.version); |
| 142 | } |
| 143 | fs::remove_dir_all(self.path.join(".git")).with_context(|| { |
| 144 | format!( |
| 145 | "Failed to remove .git directory from standard library version {}", |
| 146 | self.version |
| 147 | ) |
| 148 | })?; |
| 149 | Ok(()) |
| 150 | } |
| 151 | } |