mirror of
https://github.com/pesde-pkg/pesde.git
synced 2024-12-12 11:00:36 +00:00
feat: add version management flag
This commit is contained in:
parent
821cc989ef
commit
2b6a731ea9
7 changed files with 49 additions and 42 deletions
|
@ -30,6 +30,7 @@ bin = [
|
|||
]
|
||||
wally-compat = ["zip", "serde_json"]
|
||||
patches = ["git2"]
|
||||
version-management = ["bin"]
|
||||
|
||||
[[bin]]
|
||||
name = "pesde"
|
||||
|
|
|
@ -14,7 +14,9 @@ mod patch;
|
|||
mod patch_commit;
|
||||
mod publish;
|
||||
mod run;
|
||||
#[cfg(feature = "version-management")]
|
||||
mod self_install;
|
||||
#[cfg(feature = "version-management")]
|
||||
mod self_upgrade;
|
||||
mod update;
|
||||
|
||||
|
@ -41,6 +43,7 @@ pub enum Subcommand {
|
|||
Publish(publish::PublishCommand),
|
||||
|
||||
/// Installs the pesde binary and scripts
|
||||
#[cfg(feature = "version-management")]
|
||||
SelfInstall(self_install::SelfInstallCommand),
|
||||
|
||||
/// Sets up a patching environment for a package
|
||||
|
@ -52,6 +55,7 @@ pub enum Subcommand {
|
|||
PatchCommit(patch_commit::PatchCommitCommand),
|
||||
|
||||
/// Installs the latest version of pesde
|
||||
#[cfg(feature = "version-management")]
|
||||
SelfUpgrade(self_upgrade::SelfUpgradeCommand),
|
||||
|
||||
/// Adds a dependency to the project
|
||||
|
@ -82,11 +86,13 @@ impl Subcommand {
|
|||
Subcommand::Run(run) => run.run(project),
|
||||
Subcommand::Install(install) => install.run(project, multi, reqwest),
|
||||
Subcommand::Publish(publish) => publish.run(project, reqwest),
|
||||
#[cfg(feature = "version-management")]
|
||||
Subcommand::SelfInstall(self_install) => self_install.run(),
|
||||
#[cfg(feature = "patches")]
|
||||
Subcommand::Patch(patch) => patch.run(project, reqwest),
|
||||
#[cfg(feature = "patches")]
|
||||
Subcommand::PatchCommit(patch_commit) => patch_commit.run(project),
|
||||
#[cfg(feature = "version-management")]
|
||||
Subcommand::SelfUpgrade(self_upgrade) => self_upgrade.run(reqwest),
|
||||
Subcommand::Add(add) => add.run(project),
|
||||
Subcommand::Update(update) => update.run(project, multi, reqwest),
|
||||
|
|
|
@ -24,6 +24,7 @@ pub mod commands;
|
|||
pub mod config;
|
||||
pub mod files;
|
||||
pub mod repos;
|
||||
#[cfg(feature = "version-management")]
|
||||
pub mod version;
|
||||
|
||||
pub const HOME_DIR: &str = concat!(".", env!("CARGO_PKG_NAME"));
|
||||
|
@ -119,6 +120,7 @@ impl<V: FromStr<Err = E>, E: Into<anyhow::Error>, N: FromStr<Err = F>, F: Into<a
|
|||
}
|
||||
|
||||
impl VersionedPackageName {
|
||||
#[cfg(feature = "patches")]
|
||||
fn get(self, graph: &DownloadedGraph) -> anyhow::Result<(PackageNames, VersionId)> {
|
||||
let version_id = match self.1 {
|
||||
Some(version) => version,
|
||||
|
|
|
@ -157,10 +157,6 @@ pub fn get_or_download_version(
|
|||
reqwest: &reqwest::blocking::Client,
|
||||
version: &Version,
|
||||
) -> anyhow::Result<Option<PathBuf>> {
|
||||
#[cfg(debug_assertions)]
|
||||
// possible hard to debug issues with the versioning system overtaking the debug build
|
||||
return Ok(None);
|
||||
|
||||
let path = home_dir()?.join("versions");
|
||||
create_dir_all(&path).context("failed to create versions directory")?;
|
||||
|
||||
|
@ -196,9 +192,6 @@ pub fn get_or_download_version(
|
|||
}
|
||||
|
||||
pub fn max_installed_version() -> anyhow::Result<Version> {
|
||||
#[cfg(debug_assertions)]
|
||||
return Ok(current_version());
|
||||
|
||||
let versions_dir = home_dir()?.join("versions");
|
||||
create_dir_all(&versions_dir).context("failed to create versions directory")?;
|
||||
|
||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -193,8 +193,9 @@ impl Project {
|
|||
let dir = dir.as_ref().to_path_buf();
|
||||
let manifest = std::fs::read_to_string(dir.join(MANIFEST_FILE_NAME))
|
||||
.map_err(|e| errors::WorkspaceMembersError::ManifestMissing(dir.to_path_buf(), e))?;
|
||||
let manifest = toml::from_str::<Manifest>(&manifest)
|
||||
.map_err(|e| errors::WorkspaceMembersError::ManifestDeser(dir.to_path_buf(), e))?;
|
||||
let manifest = toml::from_str::<Manifest>(&manifest).map_err(|e| {
|
||||
errors::WorkspaceMembersError::ManifestDeser(dir.to_path_buf(), Box::new(e))
|
||||
})?;
|
||||
|
||||
let members = manifest
|
||||
.workspace_members
|
||||
|
@ -211,8 +212,9 @@ impl Project {
|
|||
.map(|path| {
|
||||
let manifest = std::fs::read_to_string(path.join(MANIFEST_FILE_NAME))
|
||||
.map_err(|e| errors::WorkspaceMembersError::ManifestMissing(path.clone(), e))?;
|
||||
let manifest = toml::from_str::<Manifest>(&manifest)
|
||||
.map_err(|e| errors::WorkspaceMembersError::ManifestDeser(path.clone(), e))?;
|
||||
let manifest = toml::from_str::<Manifest>(&manifest).map_err(|e| {
|
||||
errors::WorkspaceMembersError::ManifestDeser(path.clone(), Box::new(e))
|
||||
})?;
|
||||
Ok((path, manifest))
|
||||
})
|
||||
.collect::<Result<_, _>>()
|
||||
|
@ -273,7 +275,7 @@ pub mod errors {
|
|||
|
||||
/// An error occurred deserializing the manifest file
|
||||
#[error("error deserializing manifest file at {0}")]
|
||||
ManifestDeser(PathBuf, #[source] toml::de::Error),
|
||||
ManifestDeser(PathBuf, #[source] Box<toml::de::Error>),
|
||||
|
||||
/// An error occurred interacting with the filesystem
|
||||
#[error("error interacting with the filesystem")]
|
||||
|
|
61
src/main.rs
61
src/main.rs
|
@ -10,13 +10,12 @@ use std::{
|
|||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
#[cfg(feature = "version-management")]
|
||||
use crate::cli::version::{
|
||||
check_for_updates, current_version, get_or_download_version, max_installed_version,
|
||||
};
|
||||
use crate::cli::{
|
||||
auth::get_token,
|
||||
config::read_config,
|
||||
home_dir,
|
||||
repos::update_repo_dependencies,
|
||||
version::{check_for_updates, current_version, get_or_download_version, max_installed_version},
|
||||
HOME_DIR,
|
||||
auth::get_token, config::read_config, home_dir, repos::update_repo_dependencies, HOME_DIR,
|
||||
};
|
||||
|
||||
mod cli;
|
||||
|
@ -233,35 +232,39 @@ fn run() -> anyhow::Result<()> {
|
|||
.build()?
|
||||
};
|
||||
|
||||
let target_version = project
|
||||
.deser_manifest()
|
||||
.ok()
|
||||
.and_then(|manifest| manifest.pesde_version);
|
||||
#[cfg(feature = "version-management")]
|
||||
{
|
||||
let target_version = project
|
||||
.deser_manifest()
|
||||
.ok()
|
||||
.and_then(|manifest| manifest.pesde_version);
|
||||
|
||||
// store the current version in case it needs to be used later
|
||||
get_or_download_version(&reqwest, ¤t_version())?;
|
||||
// store the current version in case it needs to be used later
|
||||
get_or_download_version(&reqwest, ¤t_version())?;
|
||||
|
||||
let exe_path = if let Some(version) = target_version {
|
||||
Some(get_or_download_version(&reqwest, &version)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let exe_path = if let Some(exe_path) = exe_path {
|
||||
exe_path
|
||||
} else {
|
||||
get_or_download_version(&reqwest, &max_installed_version()?)?
|
||||
};
|
||||
let exe_path = if let Some(version) = target_version {
|
||||
Some(get_or_download_version(&reqwest, &version)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let exe_path = if let Some(exe_path) = exe_path {
|
||||
exe_path
|
||||
} else {
|
||||
get_or_download_version(&reqwest, &max_installed_version()?)?
|
||||
};
|
||||
|
||||
if let Some(exe_path) = exe_path {
|
||||
let status = std::process::Command::new(exe_path)
|
||||
.args(std::env::args_os().skip(1))
|
||||
.status()
|
||||
.expect("failed to run new version");
|
||||
if let Some(exe_path) = exe_path {
|
||||
let status = std::process::Command::new(exe_path)
|
||||
.args(std::env::args_os().skip(1))
|
||||
.status()
|
||||
.expect("failed to run new version");
|
||||
|
||||
std::process::exit(status.code().unwrap());
|
||||
std::process::exit(status.code().unwrap());
|
||||
}
|
||||
|
||||
display_err(check_for_updates(&reqwest), " while checking for updates");
|
||||
}
|
||||
|
||||
display_err(check_for_updates(&reqwest), " while checking for updates");
|
||||
display_err(
|
||||
update_repo_dependencies(&project),
|
||||
" while updating repository dependencies",
|
||||
|
|
|
@ -11,7 +11,7 @@ pub trait GitBasedSource {
|
|||
fn repo_url(&self) -> &gix::Url;
|
||||
|
||||
/// Gets the tree of the repository
|
||||
fn tree<'a>(&'a self, repo: &'a gix::Repository) -> Result<gix::Tree, errors::TreeError> {
|
||||
fn tree<'a>(&'a self, repo: &'a gix::Repository) -> Result<gix::Tree<'a>, errors::TreeError> {
|
||||
// this is a bare repo, so this is the actual path
|
||||
let path = repo.path().to_path_buf();
|
||||
|
||||
|
|
Loading…
Reference in a new issue