Skip to content

Commit

Permalink
Rename protocol to proto
Browse files Browse the repository at this point in the history
This affects both the command line option as well as the config file.
  • Loading branch information
rossmacarthur committed Apr 27, 2020
1 parent a7fe5ec commit ce4d8e2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ tag = "1.9.0"
#### Cloning with Git or SSH protocols

GitHub and Gist sources are cloned using HTTPS by default. You can specify that
Git or SSH should be used by setting the `protocol` field to the protocol type.
Git or SSH should be used by setting the `proto` field to the protocol type.
This must be one of `git`, `https`, or `ssh`.

```toml
[plugins.pure]
github = "sindresorhus/pure"
protocol = "ssh"
proto = "ssh"
```

For a plain Git source you should specify the URL with a `git://` or `ssh://`
Expand Down
28 changes: 14 additions & 14 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct Add {

/// The Git protocol for a Gist or GitHub plugin.
#[structopt(long, value_name = "PROTO", conflicts_with_all = &["git", "remote", "local"])]
protocol: Option<GitProtocol>,
proto: Option<GitProtocol>,

/// Checkout the tip of a branch.
#[structopt(
Expand Down Expand Up @@ -210,7 +210,7 @@ impl Plugin {
github,
remote,
local,
protocol,
proto,
branch,
rev,
tag,
Expand Down Expand Up @@ -238,7 +238,7 @@ impl Plugin {
remote,
local,
inline: None,
protocol,
proto,
reference,
directory,
uses,
Expand Down Expand Up @@ -520,7 +520,7 @@ OPTIONS:
--github <REPO> Add a clonable GitHub repository
--remote <URL> Add a downloadable file
--local <DIR> Add a local directory
--protocol <PROTO> The Git protocol for a Gist or GitHub plugin
--proto <PROTO> The Git protocol for a Gist or GitHub plugin
--branch <BRANCH> Checkout the tip of a branch
--rev <SHA> Checkout a specific commit
--tag <TAG> Checkout a specific tag
Expand Down Expand Up @@ -579,7 +579,7 @@ ARGS:
github: None,
remote: None,
local: None,
protocol: None,
proto: None,
branch: None,
rev: Some("ad149784a1538291f2477fb774eeeed4f4d29e45".into()),
tag: None,
Expand All @@ -601,7 +601,7 @@ ARGS:
"579d02802b1cc17baed07753d09f5009",
"--tag",
"0.1.0",
"--protocol",
"--proto",
"ssh",
"--directory",
"missing",
Expand All @@ -620,7 +620,7 @@ ARGS:
github: None,
remote: None,
local: None,
protocol: Some("ssh".parse().unwrap()),
proto: Some("ssh".parse().unwrap()),
branch: None,
rev: None,
tag: Some("0.1.0".into()),
Expand All @@ -642,7 +642,7 @@ ARGS:
"rossmacarthur/sheldon-test",
"--branch",
"feature",
"--protocol",
"--proto",
"https",
"--directory",
"missing",
Expand All @@ -661,7 +661,7 @@ ARGS:
github: Some("rossmacarthur/sheldon-test".parse().unwrap()),
remote: None,
local: None,
protocol: Some("https".parse().unwrap()),
proto: Some("https".parse().unwrap()),
branch: Some("feature".into()),
rev: None,
tag: None,
Expand Down Expand Up @@ -696,7 +696,7 @@ ARGS:
github: None,
remote: Some("https://raw.githubusercontent.com/rossmacarthur/sheldon-test/master/test.plugin.zsh".parse().unwrap()),
local: None,
protocol: None,
proto: None,
branch: None,
rev: None,
tag: None,
Expand Down Expand Up @@ -731,7 +731,7 @@ ARGS:
github: None,
remote: None,
local: Some("~/.dotfiles/zsh/pure".into()),
protocol: None,
proto: None,
branch: None,
rev: None,
tag: None,
Expand Down Expand Up @@ -802,7 +802,7 @@ ARGS:
"test",
"--git",
"https://github.com/rossmacarthur/sheldon-test",
"--protocol",
"--proto",
"ssh",
])
.kind,
Expand All @@ -819,7 +819,7 @@ ARGS:
"test",
"--remote",
"https://raw.githubusercontent.com/rossmacarthur/sheldon-test/master/test.plugin.zsh",
"--protocol",
"--proto",
"ssh",
])
.kind,
Expand All @@ -836,7 +836,7 @@ ARGS:
"test",
"--local",
"~/.dotfiles/zsh/pure",
"--protocol",
"--proto",
"ssh",
])
.kind,
Expand Down
27 changes: 14 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ pub struct RawPlugin {
/// An inline script.
pub inline: Option<String>,
/// What protocol to use when cloning a repository.
pub protocol: Option<GitProtocol>,
#[serde(alias = "protocol")]
pub proto: Option<GitProtocol>,
/// The Git reference to checkout.
#[serde(flatten)]
pub reference: Option<GitReference>,
Expand Down Expand Up @@ -523,7 +524,7 @@ impl RawPlugin {
remote,
local,
inline,
protocol,
proto,
reference,
directory,
uses,
Expand All @@ -542,7 +543,7 @@ impl RawPlugin {
(None, Some(repository), None, None, None, None) => {
let url_str = format!(
"{}{}/{}",
protocol.unwrap_or(GitProtocol::Https).prefix(),
proto.unwrap_or(GitProtocol::Https).prefix(),
GIST_HOST,
repository.identifier
);
Expand All @@ -554,7 +555,7 @@ impl RawPlugin {
(None, None, Some(repository), None, None, None) => {
let url_str = format!(
"{}{}/{}",
protocol.unwrap_or(GitProtocol::Https).prefix(),
proto.unwrap_or(GitProtocol::Https).prefix(),
GITHUB_HOST,
repository
);
Expand Down Expand Up @@ -587,8 +588,8 @@ impl RawPlugin {
"the `branch`, `tag`, and `rev` fields are not supported by this plugin \
type"
);
} else if protocol.is_some() && !is_gist_or_github {
bail!("the `protocol` field is not supported by this plugin type");
} else if proto.is_some() && !is_gist_or_github {
bail!("the `proto` field is not supported by this plugin type");
}

validate_template_names(&apply, templates)?;
Expand All @@ -603,7 +604,7 @@ impl RawPlugin {
}
TempSource::Inline(raw) => {
let unsupported = [
("`protocol` field is", protocol.is_some()),
("`proto` field is", proto.is_some()),
("`branch`, `tag`, and `rev` fields are", is_reference_some),
("`directory` field is", directory.is_some()),
("`use` field is", uses.is_some()),
Expand Down Expand Up @@ -944,7 +945,7 @@ mod tests {
.parse()
.unwrap(),
),
protocol: Some(GitProtocol::Git),
proto: Some(GitProtocol::Git),
..Default::default()
};
assert_eq!(
Expand Down Expand Up @@ -997,7 +998,7 @@ mod tests {
.parse()
.unwrap(),
),
protocol: Some(GitProtocol::Ssh),
proto: Some(GitProtocol::Ssh),
..Default::default()
};
assert_eq!(
Expand All @@ -1024,7 +1025,7 @@ mod tests {
owner: "rossmacarthur".to_string(),
name: "sheldon-test".to_string(),
}),
protocol: Some(GitProtocol::Git),
proto: Some(GitProtocol::Git),
..Default::default()
};
assert_eq!(
Expand Down Expand Up @@ -1077,7 +1078,7 @@ mod tests {
owner: "rossmacarthur".to_string(),
name: "sheldon-test".to_string(),
}),
protocol: Some(GitProtocol::Ssh),
proto: Some(GitProtocol::Ssh),
..Default::default()
};
assert_eq!(
Expand Down Expand Up @@ -1139,15 +1140,15 @@ mod tests {
)
.unwrap(),
),
protocol: Some(GitProtocol::Https),
proto: Some(GitProtocol::Https),
..Default::default()
};
let error = raw_plugin
.normalize("test".to_string(), &IndexMap::new())
.unwrap_err();
assert_eq!(
error.to_string(),
"the `protocol` field is not supported by this plugin type"
"the `proto` field is not supported by this plugin type"
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/cases/github_git
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# plugins.toml
[plugins.test]
github = "rossmacarthur/sheldon-test"
protocol = "git"
proto = "git"

# plugins.lock
version = "<version>"
Expand Down

0 comments on commit ce4d8e2

Please sign in to comment.