-
Notifications
You must be signed in to change notification settings - Fork 7
feat: implement support for --cwd flag
#32
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
a553020
27219fa
f01e8a9
4a5e830
e1e2c01
1d757cb
9241168
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ use serde::Deserialize; | |
| use serde_with::serde_as; | ||
| use std::{collections::BTreeMap, str::FromStr}; | ||
| use zpm_semver::{Range, Version}; | ||
| use zpm_utils::{ExplicitPath, FromFileString, Path, ToFileString}; | ||
| use zpm_utils::{ExplicitPath, FromFileString, Path, PathError, RawPath, ToFileString}; | ||
|
|
||
| use crate::{errors::Error, http::fetch, manifest::{PackageManagerReference, VersionPackageManagerReference}, yarn_enums::{ChannelSelector, Selector}}; | ||
|
|
||
|
|
@@ -105,29 +105,53 @@ pub fn get_bin_version() -> String { | |
| .to_string() | ||
| } | ||
|
|
||
| pub fn extract_bin_meta() -> BinMeta { | ||
| const CWD_FLAG: &str = "--cwd"; | ||
| const CWD_FLAG_EQUALS: &str = "--cwd="; | ||
|
|
||
| pub fn extract_bin_meta() -> Result<BinMeta, PathError> { | ||
| let mut cwd = None; | ||
|
|
||
| let mut args = std::env::args() | ||
| .skip(1) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| // TODO: Use clipanion to error on incorrect placement of `--cwd` argument. | ||
| if args.len() >= 2 && args[0] == CWD_FLAG { | ||
| let raw_path | ||
| = RawPath::from_str(&args[1])?; | ||
|
|
||
| cwd = Some(raw_path.path); | ||
| args.drain(..2); | ||
| } else if args.len() >= 1 && args[0].starts_with(CWD_FLAG_EQUALS) { | ||
| let raw_path | ||
| = RawPath::from_str(&args[0][CWD_FLAG_EQUALS.len()..])?; | ||
|
|
||
| cwd = Some(raw_path.path); | ||
| args.remove(0); | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Implicit Path Overrides Explicit
|
||
| if let Some(first_arg) = args.first() { | ||
| let explicit_path | ||
| = ExplicitPath::from_str(first_arg); | ||
|
|
||
| if let Ok(explicit_path) = explicit_path { | ||
| cwd = Some(explicit_path.raw_path.path); | ||
| args.remove(0); | ||
| match explicit_path { | ||
| Ok(explicit_path) => { | ||
| cwd = Some(explicit_path.raw_path.path); | ||
| args.remove(0); | ||
| }, | ||
| Err(PathError::InvalidExplicitPathParameter(_)) => { | ||
| // This is not a valid explicit path, so we don't modify `cwd`. | ||
| }, | ||
| Err(err) => return Err(err), | ||
| } | ||
| } | ||
|
|
||
| let version | ||
| = get_bin_version(); | ||
|
|
||
| BinMeta { | ||
| Ok(BinMeta { | ||
| cwd, | ||
| args, | ||
| version, | ||
| } | ||
| }) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.