Skip to content

Commit

Permalink
fixup! Apply suggestions from code review - documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDenkoV committed Sep 13, 2023
1 parent 4d9ac0d commit 8e44109
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions scarb/src/core/manifest/toml_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,17 +749,17 @@ pub fn readme_for_package(
package_root: &Utf8Path,
readme: Option<&PathOrBool>,
) -> Result<Option<Utf8PathBuf>> {
match readme {
None => abs_canonical_path(
package_root,
default_readme_from_package_root(package_root.parent().unwrap()),
),
Some(value) => match value {
PathOrBool::Bool(false) => Ok(None),
PathOrBool::Bool(true) => abs_canonical_path(package_root, Some("README.md".into())),
PathOrBool::Path(p) => abs_canonical_path(package_root, Some(p)),
},
}
let file_name = match readme {
None => default_readme_from_package_root(package_root.parent().unwrap()),
Some(PathOrBool::Path(p)) => Some(p.as_path()),
Some(PathOrBool::Bool(true)) => {
default_readme_from_package_root(package_root.parent().unwrap())
.or_else(|| Some("README.md".into()))
}
Some(PathOrBool::Bool(false)) => None,
};

abs_canonical_path(package_root, file_name)
}

/// Creates the absolute canonical path of the README file and checks if it exists
Expand All @@ -781,12 +781,12 @@ fn abs_canonical_path(prefix: &Utf8Path, readme: Option<&Utf8Path>) -> Result<Op
}
}

const DEFAULT_README_FILES: [&str; 3] = ["README.md", "README.txt", "README"];
const DEFAULT_README_FILES: &[&str] = &["README.md", "README.txt", "README"];

/// Checks if a file with any of the default README file names exists in the package root.
/// If so, returns a `Utf8Path` with that name.
fn default_readme_from_package_root(package_root: &Utf8Path) -> Option<&Utf8Path> {
for &readme_filename in DEFAULT_README_FILES.iter() {
for &readme_filename in DEFAULT_README_FILES {
if package_root.join(readme_filename).is_file() {
return Some(readme_filename.into());
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/reference/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ readme = "README.md"
If no value is specified for this field, and a file named `README.md`, `README.txt` or `README` exists in the package root,
then the name of that file will be used.
You can suppress this behavior by setting this field to false.
If the field is set to true, a default value of `README.md` will be assumed.
If the field is set to true, a default value of `README.md` will be assumed, unless file named `README.txt` or `README` exists in the package root, in which case it will be used instead.

### `homepage`

Expand Down

0 comments on commit 8e44109

Please sign in to comment.