mirror of
https://github.com/AleoHQ/leo.git
synced 2024-09-22 12:39:52 +03:00
Separate the update_manifest feature into remote and package features
This commit is contained in:
parent
515dc8204b
commit
5f5c887846
@ -44,4 +44,6 @@ version = "1.3.0"
|
||||
|
||||
[features]
|
||||
default = [ ]
|
||||
update_manifest = [ ]
|
||||
update_manifest = [ "update_remote", "update_project" ]
|
||||
update_remote = [ ]
|
||||
update_project = [ ]
|
@ -133,24 +133,34 @@ impl TryFrom<&PathBuf> for Manifest {
|
||||
// Read each individual line of the toml file
|
||||
for line in buffer.lines() {
|
||||
// Determine if the old remote format is being used
|
||||
if line.starts_with("remote") {
|
||||
let remote = line
|
||||
.split("=") // Split the line as 'remote' = '"{author}/{package_name}"'
|
||||
.collect::<Vec<&str>>()[1]; // Fetch just '"{author}/{package_name}"'
|
||||
old_remote_format = Some(remote);
|
||||
continue;
|
||||
}
|
||||
#[cfg(feature = "update_remote")]
|
||||
{
|
||||
if line.starts_with("remote") {
|
||||
let remote = line
|
||||
.split("=") // Split the line as 'remote' = '"{author}/{package_name}"'
|
||||
.collect::<Vec<&str>>()[1]; // Fetch just '"{author}/{package_name}"'
|
||||
old_remote_format = Some(remote);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Determine if the new remote format is being used
|
||||
if line.starts_with("[remote]") {
|
||||
new_remote_format_exists = true;
|
||||
// Determine if the new remote format is being used
|
||||
if line.starts_with("[remote]") {
|
||||
new_remote_format_exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If the old project format is being being used, update the toml file
|
||||
// to use the new format instead.
|
||||
if line.starts_with("[package]") {
|
||||
new_toml += "[project]";
|
||||
} else {
|
||||
#[cfg(feature = "update_project")]
|
||||
{
|
||||
if line.starts_with("[package]") {
|
||||
new_toml += "[project]";
|
||||
} else {
|
||||
new_toml += line;
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "update_project"))]
|
||||
{
|
||||
new_toml += line;
|
||||
}
|
||||
|
||||
@ -183,14 +193,10 @@ author = "{author}"
|
||||
}
|
||||
|
||||
// Rewrite the toml file if it has been updated
|
||||
#[cfg(feature = "update_manifest")]
|
||||
{
|
||||
if buffer != new_toml {
|
||||
let mut file =
|
||||
File::create(&path).map_err(|error| ManifestError::Creating(MANIFEST_FILENAME, error))?;
|
||||
file.write_all(new_toml.as_bytes())
|
||||
.map_err(|error| ManifestError::Writing(MANIFEST_FILENAME, error))?;
|
||||
}
|
||||
if buffer != new_toml {
|
||||
let mut file = File::create(&path).map_err(|error| ManifestError::Creating(MANIFEST_FILENAME, error))?;
|
||||
file.write_all(new_toml.as_bytes())
|
||||
.map_err(|error| ManifestError::Writing(MANIFEST_FILENAME, error))?;
|
||||
}
|
||||
|
||||
// Read the toml file
|
||||
|
Loading…
Reference in New Issue
Block a user