Skip to content

Commit 23075d1

Browse files
committed
remove rustfmt.toml + apply rustfmt
1 parent a54692d commit 23075d1

File tree

8 files changed

+222
-173
lines changed

8 files changed

+222
-173
lines changed

rustfmt.toml

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/app.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
use crate::dotfiles::Dotfiles;
2+
use crate::errors::Result;
3+
use crate::util;
4+
use dirs;
5+
use regex::Regex;
16
use std::borrow::Borrow;
27
use std::env;
38
use std::path::Path;
4-
use crate::dotfiles::Dotfiles;
5-
use crate::util;
6-
use crate::errors::Result;
79
use url::Url;
8-
use regex::Regex;
9-
use dirs;
1010

1111
#[cfg(windows)]
1212
use crate::windows;
@@ -22,19 +22,21 @@ impl App {
2222
let dotdir = init_envs()?;
2323
let dotfiles = Dotfiles::new(Path::new(&dotdir).to_path_buf());
2424
Ok(App {
25-
dotfiles: dotfiles,
26-
dry_run: dry_run,
27-
verbose: verbose,
28-
})
25+
dotfiles: dotfiles,
26+
dry_run: dry_run,
27+
verbose: verbose,
28+
})
2929
}
3030

3131
pub fn command_clone(&self, query: &str) -> Result<i32> {
3232
let url = resolve_url(query)?;
3333
let dotdir = self.dotfiles.root_dir().to_string_lossy();
34-
util::wait_exec("git",
35-
&["clone", url.as_str(), dotdir.borrow()],
36-
None,
37-
self.dry_run)
34+
util::wait_exec(
35+
"git",
36+
&["clone", url.as_str(), dotdir.borrow()],
37+
None,
38+
self.dry_run,
39+
)
3840
.map_err(Into::into)
3941
}
4042

@@ -80,7 +82,6 @@ impl App {
8082
}
8183
}
8284

83-
8485
#[cfg(windows)]
8586
fn check_symlink_privilege() {
8687
use windows::ElevationType;
@@ -103,7 +104,6 @@ fn check_symlink_privilege() {
103104
#[inline]
104105
pub fn check_symlink_privilege() {}
105106

106-
107107
fn init_envs() -> Result<String> {
108108
if env::var("HOME").is_err() {
109109
env::set_var("HOME", dirs::home_dir().unwrap());
@@ -127,24 +127,26 @@ fn resolve_url(s: &str) -> Result<Url> {
127127
"http" | "https" | "ssh" | "git" | "file" => Url::parse(s).map_err(Into::into),
128128
scheme => Err(format!("'{}' is invalid scheme", scheme).into()),
129129
}
130-
131130
} else if let Some(cap) = re_scplike.captures(s) {
132-
let username = cap.get(1)
133-
.and_then(|s| if s.as_str() != "" {
134-
Some(s.as_str())
135-
} else {
136-
None
137-
})
138-
.unwrap_or("git@");
131+
let username = cap
132+
.get(1)
133+
.and_then(|s| {
134+
if s.as_str() != "" {
135+
Some(s.as_str())
136+
} else {
137+
None
138+
}
139+
})
140+
.unwrap_or("git@");
139141
let host = cap.get(2).unwrap().as_str();
140142
let path = cap.get(3).unwrap().as_str();
141143

142144
Url::parse(&format!("ssh://{}{}/{}.git", username, host, path)).map_err(Into::into)
143-
144145
} else {
145-
let username = s.splitn(2, "/")
146-
.next()
147-
.ok_or("'username' is unknown".to_owned())?;
146+
let username = s
147+
.splitn(2, "/")
148+
.next()
149+
.ok_or("'username' is unknown".to_owned())?;
148150
let reponame = s.splitn(2, "/").skip(1).next().unwrap_or("dotfiles");
149151
Url::parse(&format!("https://github.com/{}/{}.git", username, reponame)).map_err(Into::into)
150152
}

src/dotfiles.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ fn new_entry(root_dir: &Path, key: &str, val: &str) -> Entry {
5050
Entry::new(&src, &dst)
5151
}
5252

53-
fn read_entries_from_key(buf: &mut Vec<Entry>, entries: &toml::value::Table, root_dir: &Path, key: &str) {
53+
fn read_entries_from_key(
54+
buf: &mut Vec<Entry>,
55+
entries: &toml::value::Table,
56+
root_dir: &Path,
57+
key: &str,
58+
) {
5459
if let Some(entries_table) = entries.get(key).and_then(|value| value.as_table()) {
5560
for (ref key, ref val) in entries_table.iter() {
5661
if let Some(val) = val.as_str() {

src/entry.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::io;
1+
use crate::util;
2+
use ansi_term;
23
use std::fs;
4+
use std::io;
35
use std::path::{Path, PathBuf};
4-
use ansi_term;
5-
use crate::util;
66

77
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
88
pub enum EntryStatus {
@@ -12,7 +12,6 @@ pub enum EntryStatus {
1212
WrongLinkPath,
1313
}
1414

15-
1615
#[derive(Debug, Clone)]
1716
pub struct Entry {
1817
src: PathBuf,
@@ -44,23 +43,27 @@ impl Entry {
4443
pub fn check(&self, verbose: bool) -> Result<bool, io::Error> {
4544
let status = self.status()?;
4645
if status != EntryStatus::Healthy {
47-
println!("{} {} ({:?})",
48-
ansi_term::Style::new()
49-
.bold()
50-
.fg(ansi_term::Colour::Red)
51-
.paint("✘"),
52-
self.dst.display(),
53-
status);
46+
println!(
47+
"{} {} ({:?})",
48+
ansi_term::Style::new()
49+
.bold()
50+
.fg(ansi_term::Colour::Red)
51+
.paint("✘"),
52+
self.dst.display(),
53+
status
54+
);
5455
return Ok(false);
5556
}
5657
if verbose {
57-
println!("{} {}\n => {}",
58-
ansi_term::Style::new()
59-
.bold()
60-
.fg(ansi_term::Colour::Green)
61-
.paint("✓"),
62-
self.dst.display(),
63-
self.src.display());
58+
println!(
59+
"{} {}\n => {}",
60+
ansi_term::Style::new()
61+
.bold()
62+
.fg(ansi_term::Colour::Green)
63+
.paint("✓"),
64+
self.dst.display(),
65+
self.src.display()
66+
);
6467
}
6568
Ok(true)
6669
}
@@ -72,9 +75,11 @@ impl Entry {
7275

7376
if self.dst.exists() && !util::is_symlink(&self.dst)? {
7477
let origpath = orig_path(&self.dst);
75-
println!("file {} has already existed. It will be renamed to {}",
76-
self.dst.display(),
77-
origpath.display());
78+
println!(
79+
"file {} has already existed. It will be renamed to {}",
80+
self.dst.display(),
81+
origpath.display()
82+
);
7883
fs::rename(&self.dst, origpath)?;
7984
}
8085

@@ -103,7 +108,6 @@ impl Entry {
103108
}
104109
}
105110

106-
107111
fn orig_path<P: AsRef<Path>>(path: P) -> PathBuf {
108112
let origpath = format!("{}.bk", path.as_ref().to_str().unwrap());
109113
Path::new(&origpath).to_path_buf()

src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ extern crate shellexpand;
33
extern crate toml;
44
#[macro_use]
55
extern crate error_chain;
6-
extern crate url;
76
extern crate regex;
7+
extern crate url;
88

9-
#[cfg(windows)]
10-
extern crate winapi;
119
#[cfg(windows)]
1210
extern crate advapi32;
1311
#[cfg(windows)]
1412
extern crate kernel32;
13+
#[cfg(windows)]
14+
extern crate winapi;
1515

1616
pub mod app;
1717
mod dotfiles;
@@ -21,12 +21,12 @@ pub mod util;
2121
mod windows;
2222

2323
mod errors {
24-
error_chain!{
25-
foreign_links {
26-
Io(::std::io::Error);
27-
UrlParse(::url::ParseError);
24+
error_chain! {
25+
foreign_links {
26+
Io(::std::io::Error);
27+
UrlParse(::url::ParseError);
28+
}
2829
}
29-
}
3030
}
3131
pub use crate::errors::*;
3232

src/main.rs

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
extern crate dot;
21
extern crate clap;
2+
extern crate dot;
33

4-
use clap::{Arg, AppSettings, SubCommand};
4+
use clap::{AppSettings, Arg, SubCommand};
55
use dot::App;
66

77
pub fn main() {
@@ -40,9 +40,11 @@ pub fn run() -> dot::Result<i32> {
4040

4141
("completion", Some(args)) => {
4242
let shell = args.value_of("shell").unwrap();
43-
cli().gen_completions_to(env!("CARGO_PKG_NAME"),
44-
shell.parse::<clap::Shell>().unwrap(),
45-
&mut std::io::stdout());
43+
cli().gen_completions_to(
44+
env!("CARGO_PKG_NAME"),
45+
shell.parse::<clap::Shell>().unwrap(),
46+
&mut std::io::stdout(),
47+
);
4648
Ok(0)
4749
}
4850

@@ -57,35 +59,63 @@ fn cli() -> clap::App<'static, 'static> {
5759
.author(env!("CARGO_PKG_AUTHORS"))
5860
.setting(AppSettings::VersionlessSubcommands)
5961
.setting(AppSettings::SubcommandRequiredElseHelp)
60-
.arg(Arg::with_name("verbose")
61-
.help("Use verbose output")
62-
.long("verbose")
63-
.short("v"))
64-
.arg(Arg::with_name("dry-run")
65-
.help("do not actually perform I/O operations")
66-
.long("dry-run")
67-
.short("n"))
68-
.subcommand(SubCommand::with_name("check").about("Check the files are correctly linked to the right places"))
69-
.subcommand(SubCommand::with_name("link").about("Create all of the symbolic links into home directory"))
70-
.subcommand(SubCommand::with_name("clean").about("Remote all of registered links from home directory"))
71-
.subcommand(SubCommand::with_name("root").about("Show the location of dotfiles repository and exit"))
72-
.subcommand(SubCommand::with_name("clone")
73-
.about("Clone dotfiles repository from remote")
74-
.arg(Arg::with_name("url")
75-
.help("URL of remote repository")
76-
.required(true)
77-
.takes_value(true)))
78-
.subcommand(SubCommand::with_name("init")
79-
.about("Clone dotfiles repository from remote & make links")
80-
.arg(Arg::with_name("url")
81-
.help("URL of remote repository")
82-
.required(true)
83-
.takes_value(true)))
84-
.subcommand(SubCommand::with_name("completion")
85-
.about("Generate completion scripts")
86-
.setting(AppSettings::ArgRequiredElseHelp)
87-
.arg(Arg::with_name("shell")
88-
.help("target shell")
89-
.required(true)
90-
.possible_values(&["bash", "fish", "zsh", "powershell"])))
62+
.arg(
63+
Arg::with_name("verbose")
64+
.help("Use verbose output")
65+
.long("verbose")
66+
.short("v"),
67+
)
68+
.arg(
69+
Arg::with_name("dry-run")
70+
.help("do not actually perform I/O operations")
71+
.long("dry-run")
72+
.short("n"),
73+
)
74+
.subcommand(
75+
SubCommand::with_name("check")
76+
.about("Check the files are correctly linked to the right places"),
77+
)
78+
.subcommand(
79+
SubCommand::with_name("link")
80+
.about("Create all of the symbolic links into home directory"),
81+
)
82+
.subcommand(
83+
SubCommand::with_name("clean")
84+
.about("Remote all of registered links from home directory"),
85+
)
86+
.subcommand(
87+
SubCommand::with_name("root")
88+
.about("Show the location of dotfiles repository and exit"),
89+
)
90+
.subcommand(
91+
SubCommand::with_name("clone")
92+
.about("Clone dotfiles repository from remote")
93+
.arg(
94+
Arg::with_name("url")
95+
.help("URL of remote repository")
96+
.required(true)
97+
.takes_value(true),
98+
),
99+
)
100+
.subcommand(
101+
SubCommand::with_name("init")
102+
.about("Clone dotfiles repository from remote & make links")
103+
.arg(
104+
Arg::with_name("url")
105+
.help("URL of remote repository")
106+
.required(true)
107+
.takes_value(true),
108+
),
109+
)
110+
.subcommand(
111+
SubCommand::with_name("completion")
112+
.about("Generate completion scripts")
113+
.setting(AppSettings::ArgRequiredElseHelp)
114+
.arg(
115+
Arg::with_name("shell")
116+
.help("target shell")
117+
.required(true)
118+
.possible_values(&["bash", "fish", "zsh", "powershell"]),
119+
),
120+
)
91121
}

0 commit comments

Comments
 (0)