Skip to content
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

Migrate to 2018 edition #292

Merged
merged 4 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ name = "cargo-edit"
readme = "README.md"
repository = "https://github.com/killercup/cargo-edit"
version = "0.3.1"
edition = "2018"

[[bin]]
name = "cargo-add"
Expand Down
Empty file added rustfmt.toml
Empty file.
5 changes: 3 additions & 2 deletions src/bin/add/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cargo_edit::{get_latest_dependency, CrateName};
use semver;
use std::path::PathBuf;

use errors::*;
use crate::errors::*;

#[derive(Debug, Deserialize)]
/// Docopts input args.
Expand Down Expand Up @@ -71,7 +71,8 @@ impl Args {
/// Build dependencies from arguments
pub fn parse_dependencies(&self) -> Result<Vec<Dependency>> {
if !self.arg_crates.is_empty() {
return self.arg_crates
return self
.arg_crates
.iter()
.map(|crate_name| {
Ok(
Expand Down
12 changes: 3 additions & 9 deletions src/bin/add/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,18 @@
unused_qualifications
)]

extern crate atty;
extern crate docopt;
#[macro_use]
extern crate error_chain;
extern crate semver;
#[macro_use]
extern crate serde_derive;
extern crate termcolor;

use crate::args::Args;
use cargo_edit::{Dependency, Manifest};
use std::io::Write;
use std::process;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};

extern crate cargo_edit;
use cargo_edit::{Dependency, Manifest};

mod args;
use args::Args;

mod errors {
error_chain! {
Expand All @@ -52,7 +46,7 @@ mod errors {
}
}
}
use errors::*;
use crate::errors::*;

static USAGE: &'static str = r#"
Usage:
Expand Down
2 changes: 1 addition & 1 deletion src/bin/rm/args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Handle `cargo rm` arguments

use errors::*;
use crate::errors::*;

#[derive(Debug, Deserialize)]
/// Docopts input args.
Expand Down
11 changes: 3 additions & 8 deletions src/bin/rm/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,18 @@
unused_qualifications
)]

extern crate atty;
extern crate docopt;
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate serde_derive;
extern crate termcolor;

use crate::args::Args;
use cargo_edit::Manifest;
use std::io::Write;
use std::process;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};

extern crate cargo_edit;
use cargo_edit::Manifest;

mod args;
use args::Args;

mod errors {
error_chain! {
Expand All @@ -39,7 +34,7 @@ mod errors {
}
}
}
use errors::*;
use crate::errors::*;

static USAGE: &'static str = r"
Usage:
Expand Down
29 changes: 15 additions & 14 deletions src/bin/upgrade/main.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
//! `cargo upgrade`
#![warn(
missing_docs, missing_debug_implementations, missing_copy_implementations, trivial_casts,
trivial_numeric_casts, unsafe_code, unstable_features, unused_import_braces,
missing_docs,
missing_debug_implementations,
missing_copy_implementations,
trivial_casts,
trivial_numeric_casts,
unsafe_code,
unstable_features,
unused_import_braces,
unused_qualifications
)]

extern crate cargo_metadata;
extern crate docopt;
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate serde_derive;
extern crate toml_edit;

use crate::errors::*;
use cargo_edit::{find, get_latest_dependency, CrateName, Dependency, LocalManifest};
use std::collections::HashMap;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process;

extern crate cargo_edit;
use cargo_edit::{find, get_latest_dependency, CrateName, Dependency, LocalManifest};

extern crate termcolor;
use termcolor::{BufferWriter, Color, ColorChoice, ColorSpec, WriteColor};

mod errors {
error_chain!{
error_chain! {
links {
CargoEditLib(::cargo_edit::Error, ::cargo_edit::ErrorKind);
CargoMetadata(::cargo_metadata::Error, ::cargo_metadata::ErrorKind);
}
}
}
use errors::*;

static USAGE: &'static str = r"
Upgrade dependencies as specified in the local manifest file (i.e. Cargo.toml).
Expand Down Expand Up @@ -119,8 +118,10 @@ impl Manifests {
.find(|p| p.manifest_path == resolved_manifest_path)
// If we have successfully got metadata, but our manifest path does not correspond to a
// package, we must have been called against a virtual manifest.
.chain_err(|| "Found virtual manifest, but this command requires running against an \
actual package in this workspace. Try adding `--all`.")?;
.chain_err(|| {
"Found virtual manifest, but this command requires running against an \
actual package in this workspace. Try adding `--all`."
})?;

Ok(Manifests(vec![(manifest, package.to_owned())]))
}
Expand Down
6 changes: 3 additions & 3 deletions src/crate_name.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Crate name parsing.
use semver;

use errors::*;
use Dependency;
use {get_crate_name_from_github, get_crate_name_from_gitlab, get_crate_name_from_path};
use crate::errors::*;
use crate::Dependency;
use crate::{get_crate_name_from_github, get_crate_name_from_gitlab, get_crate_name_from_path};

/// A crate specifier. This can be a plain name (e.g. `docopt`), a name and a versionreq (e.g.
/// `docopt@^0.8`), a URL, or a path.
Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error_chain!{
error_chain! {
errors {
/// Failed to fetch crate from crates.io
FetchVersionFailure {
Expand Down
16 changes: 10 additions & 6 deletions src/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::{Dependency, Manifest};
use env_proxy;
use regex::Regex;
use reqwest;
Expand All @@ -7,9 +8,8 @@ use std::env;
use std::io::Read;
use std::path::Path;
use std::time::Duration;
use {Dependency, Manifest};

use errors::*;
use crate::errors::*;

const REGISTRY_HOST: &str = "https://crates.io";

Expand Down Expand Up @@ -97,7 +97,8 @@ fn get_latest_stable_version_from_json() {
}
]
}"#,
).expect("crate version is correctly parsed");
)
.expect("crate version is correctly parsed");

assert_eq!(
read_latest_version(&versions, false)
Expand Down Expand Up @@ -125,7 +126,8 @@ fn get_latest_unstable_or_stable_version_from_json() {
}
]
}"#,
).expect("crate version is correctly parsed");
)
.expect("crate version is correctly parsed");

assert_eq!(
read_latest_version(&versions, true)
Expand Down Expand Up @@ -153,7 +155,8 @@ fn get_latest_version_from_json_test() {
}
]
}"#,
).expect("crate version is correctly parsed");
)
.expect("crate version is correctly parsed");

assert_eq!(
read_latest_version(&versions, false)
Expand Down Expand Up @@ -181,7 +184,8 @@ fn get_no_latest_version_from_json_when_all_are_yanked() {
}
]
}"#,
).expect("crate version is correctly parsed");
)
.expect("crate version is correctly parsed");

assert!(read_latest_version(&versions, false).is_err());
}
Expand Down
33 changes: 16 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
//! Show and Edit Cargo's Manifest Files
#![cfg_attr(test, allow(dead_code))]
#![warn(
missing_docs, missing_debug_implementations, missing_copy_implementations, trivial_casts,
trivial_numeric_casts, unsafe_code, unstable_features, unused_import_braces,
missing_docs,
missing_debug_implementations,
missing_copy_implementations,
trivial_casts,
trivial_numeric_casts,
unsafe_code,
unstable_features,
unused_import_braces,
unused_qualifications
)]

extern crate cargo_metadata;
extern crate env_proxy;
#[macro_use]
extern crate error_chain;
extern crate regex;
extern crate reqwest;
extern crate semver;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate termcolor;
extern crate toml_edit;

mod crate_name;
mod dependency;
mod errors;
mod fetch;
mod manifest;

pub use crate_name::CrateName;
pub use dependency::Dependency;
pub use errors::*;
pub use fetch::{get_crate_name_from_github, get_crate_name_from_gitlab, get_crate_name_from_path,
get_latest_dependency};
pub use manifest::{find, LocalManifest, Manifest};
pub use crate::crate_name::CrateName;
pub use crate::dependency::Dependency;
pub use crate::errors::*;
pub use crate::fetch::{
get_crate_name_from_github, get_crate_name_from_gitlab, get_crate_name_from_path,
get_latest_dependency,
};
pub use crate::manifest::{find, LocalManifest, Manifest};
41 changes: 18 additions & 23 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::{env, str};
use termcolor::{BufferWriter, Color, ColorChoice, ColorSpec, WriteColor};
use toml_edit;

use dependency::Dependency;
use errors::*;
use crate::dependency::Dependency;
use crate::errors::*;

const MANIFEST_FILENAME: &str = "Cargo.toml";

Expand Down Expand Up @@ -52,7 +52,8 @@ fn search(dir: &Path) -> Result<PathBuf> {
}

fn merge_inline_table(old_dep: &mut toml_edit::Item, new: &toml_edit::Item) {
for (k, v) in new.as_inline_table()
for (k, v) in new
.as_inline_table()
.expect("expected an inline table")
.iter()
{
Expand Down Expand Up @@ -127,7 +128,8 @@ fn print_upgrade_if_necessary(
&mut buffer,
"{} v{} -> v{}",
crate_name, old_version, new_version,
).chain_err(|| "Failed to write upgrade versions")?;
)
.chain_err(|| "Failed to write upgrade versions")?;
bufwtr
.print(&buffer)
.chain_err(|| "Failed to print upgrade message")?;
Expand Down Expand Up @@ -198,7 +200,8 @@ impl Manifest {
}

// ... and in `target.<target>.(build-/dev-)dependencies`.
let target_sections = self.data
let target_sections = self
.data
.as_table()
.get("target")
.and_then(toml_edit::Item::as_table_like)
Expand Down Expand Up @@ -294,8 +297,6 @@ impl Manifest {
/// # Examples
///
/// ```
/// # extern crate cargo_edit;
/// # extern crate toml_edit;
/// # fn main() {
/// use cargo_edit::{Dependency, Manifest};
/// use toml_edit;
Expand Down Expand Up @@ -411,7 +412,7 @@ impl LocalManifest {
#[cfg(test)]
mod tests {
use super::*;
use dependency::Dependency;
use crate::dependency::Dependency;
use toml_edit;

#[test]
Expand All @@ -422,11 +423,9 @@ mod tests {
let clone = manifest.clone();
let dep = Dependency::new("cargo-edit").set_version("0.1.0");
let _ = manifest.insert_into_table(&["dependencies".to_owned()], &dep);
assert!(
manifest
.remove_from_table("dependencies", &dep.name)
.is_ok()
);
assert!(manifest
.remove_from_table("dependencies", &dep.name)
.is_ok());
assert_eq!(manifest.data.to_string(), clone.data.to_string());
}

Expand Down Expand Up @@ -471,11 +470,9 @@ mod tests {
data: toml_edit::Document::new(),
};
let dep = Dependency::new("cargo-edit").set_version("0.1.0");
assert!(
manifest
.remove_from_table("dependencies", &dep.name)
.is_err()
);
assert!(manifest
.remove_from_table("dependencies", &dep.name)
.is_err());
}

#[test]
Expand All @@ -486,10 +483,8 @@ mod tests {
let dep = Dependency::new("cargo-edit").set_version("0.1.0");
let other_dep = Dependency::new("other-dep").set_version("0.1.0");
let _ = manifest.insert_into_table(&["dependencies".to_owned()], &other_dep);
assert!(
manifest
.remove_from_table("dependencies", &dep.name)
.is_err()
);
assert!(manifest
.remove_from_table("dependencies", &dep.name)
.is_err());
}
}
Loading