-
Notifications
You must be signed in to change notification settings - Fork 13
Add simplex install <dep> functionality
#110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
01259d0
feat: add `simplex install [dep]` functionality
LesterEvSe 9bc7664
update: `CHANGELOG.md`
LesterEvSe 30cbfce
refactor: change naming in `CHANGELOG.md`
LesterEvSe 6136d84
refactor: move `add_dependency_to` function to `DependencyConfig`
LesterEvSe 6f424a5
refactor: remove dead code
LesterEvSe f4b9d45
fix: bug with fixtures in `Simplex.toml`
LesterEvSe 1848327
refactor: `Cargo.toml` file
LesterEvSe a56384a
fix: restore `smplx-std` in `Cargo.toml`
LesterEvSe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| use std::fmt::Write; | ||
|
|
||
| use super::error::ConfigError; | ||
|
|
||
| pub struct DepSpec { | ||
| pub alias: String, | ||
| pub source: Source, | ||
| } | ||
|
|
||
| pub enum Source { | ||
| Git(String), | ||
| Path(String), | ||
| } | ||
|
|
||
| impl DepSpec { | ||
| /// Parses a raw CLI token into a [`DepSpec`]. | ||
| /// | ||
| /// Accepted forms: | ||
| /// - `<source>`: The alias is derived from the last path segment of the source, | ||
| /// with a trailing `.git` stripped. | ||
| /// - `<alias>=<source>`: Both parts must be non-empty. | ||
| /// | ||
| /// The source is then classified as [`Source::Git`] or [`Source::Path`] based on | ||
| /// its scheme or `.git` suffix. | ||
| /// | ||
| /// # Errors | ||
| /// - `ConfigError::MalformedDep`: If `raw` contains `=` but either side is empty, | ||
| /// or if the alias cannot be derived from the source (e.g. the source contains | ||
| /// no non-empty path segment). | ||
| pub fn parse_dep(raw: &str) -> Result<DepSpec, ConfigError> { | ||
| let (alias, source_str) = match raw.split_once('=') { | ||
| Some((a, s)) if !a.is_empty() && !s.is_empty() => (a.to_owned(), s), | ||
| Some(_) => return Err(ConfigError::MalformedDep(raw.to_owned())), | ||
| None => (Self::derive_alias(raw)?, raw), | ||
| }; | ||
|
|
||
| let source = Self::classify_source(source_str); | ||
|
|
||
| Ok(DepSpec { alias, source }) | ||
| } | ||
|
|
||
| /// Formats a batch of dependency specs as a bracketed, one-per-line list. | ||
| #[must_use] | ||
| pub fn format_batch(specs: &[DepSpec]) -> String { | ||
| if specs.is_empty() { | ||
| return "[]".to_owned(); | ||
| } | ||
|
|
||
| let mut out = String::from("["); | ||
|
|
||
| for (index, spec) in specs.iter().enumerate() { | ||
| if index > 0 { | ||
| out.push(','); | ||
| } | ||
|
|
||
| let source = match &spec.source { | ||
| Source::Git(url) => url.as_str(), | ||
| Source::Path(p) => p.as_str(), | ||
| }; | ||
| let _ = write!(out, "\n {} = {}", spec.alias, source); | ||
| } | ||
|
|
||
| out.push_str("\n]"); | ||
|
|
||
| out | ||
| } | ||
|
|
||
| /// Derives a default alias from a source string by taking its last non-empty | ||
| /// path segment and stripping a trailing `.git`. | ||
| /// | ||
| /// # Errors | ||
| /// - `ConfigError::MalformedDep`: If `source` contains no non-empty path segment | ||
| /// (e.g. an empty string or one consisting only of separators). | ||
| fn derive_alias(source: &str) -> Result<String, ConfigError> { | ||
| let last = source | ||
| .rsplit(['/', '\\']) | ||
| .find(|s| !s.is_empty()) | ||
| .ok_or_else(|| ConfigError::MalformedDep(source.to_owned()))?; | ||
|
|
||
| Ok(last.trim_end_matches(".git").to_owned()) | ||
| } | ||
|
|
||
| /// Classifies a source string as [`Source::Git`] if it carries a recognised | ||
| /// scheme (`http`, `https`, `git`, `ssh`) or ends in `.git`, otherwise as | ||
| /// [`Source::Path`]. The `.git` check is case-insensitive. | ||
| fn classify_source(s: &str) -> Source { | ||
| let git_ext = std::path::Path::new(s) | ||
| .extension() | ||
| .is_some_and(|ext| ext.eq_ignore_ascii_case("git")); | ||
|
|
||
| if s.starts_with("http://") | ||
| || s.starts_with("https://") | ||
| || s.starts_with("git://") | ||
| || s.starts_with("ssh://") | ||
| || git_ext | ||
| { | ||
| Source::Git(s.to_owned()) | ||
| } else { | ||
| Source::Path(s.to_owned()) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| pub mod core; | ||
| pub mod dep_spec; | ||
| pub mod error; | ||
|
|
||
| pub use core::{CONFIG_FILENAME, Config, INIT_CONFIG}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.