clap-utils: Fix signer resolution on Windows
This commit is contained in:
parent
91f2b6185e
commit
e320af99a0
|
@ -211,7 +211,17 @@ pub(crate) fn parse_signer_source<S: AsRef<str>>(
|
||||||
source: S,
|
source: S,
|
||||||
) -> Result<SignerSource, SignerSourceError> {
|
) -> Result<SignerSource, SignerSourceError> {
|
||||||
let source = source.as_ref();
|
let source = source.as_ref();
|
||||||
match uriparse::URIReference::try_from(source) {
|
let source = {
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
|
{
|
||||||
|
source.replace("\\", "/")
|
||||||
|
}
|
||||||
|
#[cfg(not(target_family = "windows"))]
|
||||||
|
{
|
||||||
|
source.to_string()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
match uriparse::URIReference::try_from(source.as_str()) {
|
||||||
Err(_) => Err(SignerSourceError::UnrecognizedSource),
|
Err(_) => Err(SignerSourceError::UnrecognizedSource),
|
||||||
Ok(uri) => {
|
Ok(uri) => {
|
||||||
if let Some(scheme) = uri.scheme() {
|
if let Some(scheme) = uri.scheme() {
|
||||||
|
@ -231,18 +241,24 @@ pub(crate) fn parse_signer_source<S: AsRef<str>>(
|
||||||
legacy: false,
|
legacy: false,
|
||||||
}),
|
}),
|
||||||
SIGNER_SOURCE_STDIN => Ok(SignerSource::new(SignerSourceKind::Stdin)),
|
SIGNER_SOURCE_STDIN => Ok(SignerSource::new(SignerSourceKind::Stdin)),
|
||||||
_ => Err(SignerSourceError::UnrecognizedSource),
|
_ => {
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
|
// On Windows, an absolute path's drive letter will be parsed as the URI
|
||||||
|
// scheme. Assume a filepath source in case of a single character shceme.
|
||||||
|
if scheme.len() == 1 {
|
||||||
|
return Ok(SignerSource::new(SignerSourceKind::Filepath(source)));
|
||||||
|
}
|
||||||
|
Err(SignerSourceError::UnrecognizedSource)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match source {
|
match source.as_str() {
|
||||||
STDOUT_OUTFILE_TOKEN => Ok(SignerSource::new(SignerSourceKind::Stdin)),
|
STDOUT_OUTFILE_TOKEN => Ok(SignerSource::new(SignerSourceKind::Stdin)),
|
||||||
ASK_KEYWORD => Ok(SignerSource::new_legacy(SignerSourceKind::Prompt)),
|
ASK_KEYWORD => Ok(SignerSource::new_legacy(SignerSourceKind::Prompt)),
|
||||||
_ => match Pubkey::from_str(source) {
|
_ => match Pubkey::from_str(source.as_str()) {
|
||||||
Ok(pubkey) => Ok(SignerSource::new(SignerSourceKind::Pubkey(pubkey))),
|
Ok(pubkey) => Ok(SignerSource::new(SignerSourceKind::Pubkey(pubkey))),
|
||||||
Err(_) => std::fs::metadata(source)
|
Err(_) => std::fs::metadata(source.as_str())
|
||||||
.map(|_| {
|
.map(|_| SignerSource::new(SignerSourceKind::Filepath(source)))
|
||||||
SignerSource::new(SignerSourceKind::Filepath(source.to_string()))
|
|
||||||
})
|
|
||||||
.map_err(|err| err.into()),
|
.map_err(|err| err.into()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue