Skip to content

Commit ba25b29

Browse files
Don't hardcoded facet top-level directory
1 parent a1c4eb1 commit ba25b29

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
</h1>
99

1010
[![Coverage Status](https://coveralls.io/repos/github/facet-rs/facet/badge.svg?branch=main)](https://coveralls.io/github/facet-rs/facet?branch=main)
11-
[![crates.io](https://img.shields.io/crates/v/facet.svg)](https://crates.io/crates/facet)
12-
[![documentation](https://docs.rs/facet/badge.svg)](https://docs.rs/facet)
13-
[![MIT/Apache-2.0 licensed](https://img.shields.io/crates/l/facet.svg)](./LICENSE)
11+
[![crates.io](https://img.shields.io/crates/v/facet-dev.svg)](https://crates.io/crates/facet-dev)
12+
[![documentation](https://docs.rs/facet-dev/badge.svg)](https://docs.rs/facet-dev)
13+
[![MIT/Apache-2.0 licensed](https://img.shields.io/crates/l/facet-dev.svg)](./LICENSE)
1414
[![Discord](https://img.shields.io/discord/1379550208551026748?logo=discord&label=discord)](https://discord.gg/JhD7CwCJ8F)
1515

1616
_Logo by [Misiasart](https://misiasart.com/)_

src/main.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use log::{Level, LevelFilter, Log, Metadata, Record, debug, error, warn};
1+
use log::{debug, error, warn, Level, LevelFilter, Log, Metadata, Record};
22
use owo_colors::{OwoColorize, Style};
33
use std::os::unix::fs::PermissionsExt;
44
use std::sync::mpsc;
@@ -153,7 +153,34 @@ fn enqueue_readme_jobs(sender: std::sync::mpsc::Sender<Job>) {
153153

154154
// Also handle the workspace/top-level README, if any
155155
let workspace_template_path = workspace_dir.join(template_name);
156-
process_readme_template(&workspace_template_path, &workspace_dir, "facet");
156+
157+
// Get workspace name from cargo tree
158+
let workspace_name = match Command::new("cargo")
159+
.arg("tree")
160+
.stdout(Stdio::piped())
161+
.stderr(Stdio::piped())
162+
.spawn()
163+
.and_then(|child| {
164+
let output = child.wait_with_output()?;
165+
if output.status.success() {
166+
let stdout = String::from_utf8_lossy(&output.stdout);
167+
if let Some(first_line) = stdout.lines().next() {
168+
// Extract package name from "package-name v0.1.0 (/path/to/package)"
169+
if let Some(space_pos) = first_line.find(' ') {
170+
return Ok(first_line[..space_pos].to_string());
171+
}
172+
}
173+
}
174+
Err(std::io::Error::other("Failed to parse cargo tree output"))
175+
}) {
176+
Ok(name) => name,
177+
Err(e) => {
178+
warn!("Failed to get workspace name from cargo tree: {e}, falling back to 'facet'");
179+
"facet".to_string()
180+
}
181+
};
182+
183+
process_readme_template(&workspace_template_path, &workspace_dir, &workspace_name);
157184
}
158185

159186
fn enqueue_rustfmt_jobs(sender: std::sync::mpsc::Sender<Job>, staged_files: &StagedFiles) {

0 commit comments

Comments
 (0)