Skip to content

Commit cae4203

Browse files
committed
formatting/new rust version changes
1 parent b04803d commit cae4203

File tree

8 files changed

+255
-415
lines changed

8 files changed

+255
-415
lines changed

Cargo.lock

Lines changed: 221 additions & 336 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/certs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rustls::{Certificate, PrivateKey};
2222
use rustls::{ClientConfig, ClientSession, Session};
2323
use untrusted::{Input, Reader};
2424

25-
use std::error::Error;
2625
use std::fs::File;
2726
use std::io::{self, BufReader, Read};
2827
use std::net::{IpAddr, TcpStream};
@@ -111,7 +110,7 @@ pub fn get_cert_from_pem(pem: &str) -> Option<Certificate> {
111110
Some(body) => match ::base64::decode(body.as_str()) {
112111
Ok(der_vec) => Some(Certificate(der_vec)),
113112
Err(e) => {
114-
println!("Failed to decode cert: {}", e.description());
113+
println!("Failed to decode cert: {}", e.to_string());
115114
None
116115
}
117116
},

src/cmd.rs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ use std;
4949
use std::cell::RefCell;
5050
use std::cmp;
5151
use std::collections::HashMap;
52-
use std::error::Error;
5352
use std::io::{self, stderr, BufRead, BufReader, Read, Write};
5453
use std::iter::Iterator;
5554
use std::path::PathBuf;
@@ -283,30 +282,26 @@ fn identity<T>(t: T) -> T {
283282

284283
/// a clap validator for u32
285284
fn valid_u32(s: String) -> Result<(), String> {
286-
s.parse::<u32>()
287-
.map(|_| ())
288-
.map_err(|e| e.description().to_owned())
285+
s.parse::<u32>().map(|_| ()).map_err(|e| e.to_string())
289286
}
290287

291288
/// a clap validator for duration
292289
fn valid_duration(s: String) -> Result<(), String> {
293290
parse_duration(s.as_str())
294291
.map(|_| ())
295-
.map_err(|e| e.description().to_owned())
292+
.map_err(|e| e.to_string())
296293
}
297294

298295
/// a clap validator for rfc3339 dates
299296
fn valid_date(s: String) -> Result<(), String> {
300297
DateTime::parse_from_rfc3339(s.as_str())
301298
.map(|_| ())
302-
.map_err(|e| e.description().to_owned())
299+
.map_err(|e| e.to_string())
303300
}
304301

305302
/// a clap validator for boolean
306303
fn valid_bool(s: String) -> Result<(), String> {
307-
s.parse::<bool>()
308-
.map(|_| ())
309-
.map_err(|e| e.description().to_owned())
304+
s.parse::<bool>().map(|_| ()).map_err(|e| e.to_string())
310305
}
311306

312307
/// Check if a pod has a waiting container
@@ -1209,15 +1204,15 @@ command!(
12091204
table.add_row(row!(
12101205
obj.name(),
12111206
obj.type_str(),
1212-
obj.namespace.as_ref().map(|n| n.as_str()).unwrap_or("")
1207+
obj.namespace.as_deref().unwrap_or("")
12131208
));
12141209
}
12151210
ObjectSelection::Range(range) => {
12161211
for obj in range.iter() {
12171212
table.add_row(row!(
12181213
obj.name(),
12191214
obj.type_str(),
1220-
obj.namespace.as_ref().map(|n| n.as_str()).unwrap_or("")
1215+
obj.namespace.as_deref().unwrap_or("")
12211216
));
12221217
}
12231218
}
@@ -1424,10 +1419,7 @@ fn do_logs(
14241419
fmtvars.insert("name".to_string(), obj.name());
14251420
fmtvars.insert(
14261421
"namespace".to_string(),
1427-
obj.namespace
1428-
.as_ref()
1429-
.map(|n| n.as_str())
1430-
.unwrap_or("[none]"),
1422+
obj.namespace.as_deref().unwrap_or("[none]"),
14311423
);
14321424
let ltime = Local::now().to_rfc3339();
14331425
fmtvars.insert("time".to_string(), &ltime);
@@ -1463,7 +1455,7 @@ fn do_logs(
14631455
writer,
14641456
"Could not get EDITOR environment \
14651457
variable: {}",
1466-
e.description()
1458+
e
14671459
);
14681460
return;
14691461
}
@@ -1472,7 +1464,7 @@ fn do_logs(
14721464
let tmpdir = match env.tempdir {
14731465
Ok(ref td) => td,
14741466
Err(ref e) => {
1475-
clickwriteln!(writer, "Failed to create tempdir: {}", e.description());
1467+
clickwriteln!(writer, "Failed to create tempdir: {}", e);
14761468
return;
14771469
}
14781470
};
@@ -1497,7 +1489,7 @@ fn do_logs(
14971489
cmd!(editor, file_path)
14981490
};
14991491
if let Err(e) = expr.start() {
1500-
clickwriteln!(writer, "Could not start editor: {}", e.description());
1492+
clickwriteln!(writer, "Could not start editor: {}", e);
15011493
}
15021494
} else {
15031495
let (sender, receiver) = channel();
@@ -1779,7 +1771,7 @@ fn do_exec(
17791771
targs.push(cmd);
17801772
clickwriteln!(writer, "Starting on {} in terminal", pod.name());
17811773
if let Err(e) = duct::cmd(targs[0], &targs[1..]).start() {
1782-
clickwriteln!(writer, "Could not launch in terminal: {}", e.description());
1774+
clickwriteln!(writer, "Could not launch in terminal: {}", e);
17831775
}
17841776
} else {
17851777
let mut command = Command::new("kubectl");
@@ -2992,7 +2984,7 @@ command!(
29922984
for part in parts {
29932985
if part != "" {
29942986
if let Err(e) = part.parse::<u32>() {
2995-
return Err(e.description().to_owned());
2987+
return Err(e.to_string());
29962988
}
29972989
}
29982990
}
@@ -3073,8 +3065,7 @@ Examples:
30733065
}
30743066
}
30753067
Err(e) => {
3076-
write!(stderr(), "Error reading child output: {}", e.description())
3077-
.unwrap_or(());
3068+
write!(stderr(), "Error reading child output: {}", e).unwrap_or(());
30783069
break;
30793070
}
30803071
}
@@ -3095,7 +3086,7 @@ Examples:
30953086
write!(
30963087
stderr(),
30973088
"Couldn't execute kubectl, not forwarding. Error is: {}",
3098-
e.description()
3089+
e
30993090
)
31003091
.unwrap_or(());
31013092
}
@@ -3146,10 +3137,7 @@ command!(
31463137
.arg(
31473138
Arg::with_name("index")
31483139
.help("Index (from 'port-forwards list') of port forward to take action on")
3149-
.validator(|s: String| s
3150-
.parse::<usize>()
3151-
.map(|_| ())
3152-
.map_err(|e| e.description().to_owned()))
3140+
.validator(|s: String| s.parse::<usize>().map(|_| ()).map_err(|e| e.to_string()))
31533141
.required(false)
31543142
.index(2)
31553143
)
@@ -3197,8 +3185,7 @@ command!(
31973185
clickwriteln!(writer, "Stopped");
31983186
}
31993187
Err(e) => {
3200-
write!(stderr(), "Failed to stop: {}", e.description())
3201-
.unwrap_or(());
3188+
write!(stderr(), "Failed to stop: {}", e).unwrap_or(());
32023189
}
32033190
}
32043191
} else {

src/command_processor.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustyline::Editor;
1010

1111
use env::Env;
1212

13-
use std::error::Error;
1413
use std::fs::{File, OpenOptions};
1514
use std::io::Write;
1615
use std::ops::Range;
@@ -260,7 +259,7 @@ impl CommandProcessor {
260259
RightExpr::None => {} // do nothing
261260
RightExpr::Pipe(cmd) => {
262261
if let Err(e) = writer.setup_pipe(cmd) {
263-
println!("{}", e.description());
262+
println!("{}", e);
264263
return writer.finish_output();
265264
}
266265
}
@@ -803,29 +802,29 @@ Other help topics (type 'help [TOPIC]' for details)
803802
let p = parse_line("test || this");
804803
assert!(p.is_err());
805804
assert_eq!(
806-
p.err().unwrap().description(),
807-
"Parse error at 5: unexpected ||"
805+
p.err().unwrap().to_string(),
806+
"Parse Error: Parse error at 5: unexpected ||"
808807
);
809808

810809
let p = parse_line("test >>> this");
811810
assert!(p.is_err());
812811
assert_eq!(
813-
p.err().unwrap().description(),
814-
"Parse error at 5: unexpected >>"
812+
p.err().unwrap().to_string(),
813+
"Parse Error: Parse error at 5: unexpected >>"
815814
);
816815

817816
let p = parse_line("test >>>> this");
818817
assert!(p.is_err());
819818
assert_eq!(
820-
p.err().unwrap().description(),
821-
"Parse error at 5: unexpected >>"
819+
p.err().unwrap().to_string(),
820+
"Parse Error: Parse error at 5: unexpected >>"
822821
);
823822

824823
let p = build_parser_expr("a * b", std::ops::Range { start: 2, end: 5 });
825824
assert!(p.is_err());
826825
assert_eq!(
827-
p.err().unwrap().description(),
828-
"Parse error at 2: unexpected separator"
826+
p.err().unwrap().to_string(),
827+
"Parse Error: Parse error at 2: unexpected separator"
829828
);
830829
}
831830

src/config/click.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use atomicwrites::{AllowOverwrite, AtomicFile};
1717
use rustyline::config as rustyconfig;
1818

19-
use std::error::Error;
2019
use std::fmt;
2120
use std::fs::File;
2221
use std::io::Read;
@@ -158,10 +157,7 @@ impl ClickConfig {
158157
let af = AtomicFile::new(path, AllowOverwrite);
159158
af.write(|mut f| serde_yaml::to_writer(&mut f, &self))
160159
.map_err(|e| {
161-
KubeError::ConfigFileError(format!(
162-
"Failed to write config file: {}",
163-
e.description()
164-
))
160+
KubeError::ConfigFileError(format!("Failed to write config file: {}", e))
165161
})?;
166162
Ok(())
167163
}

src/config/kube.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use std::collections::HashMap;
1919
use std::convert::From;
2020
use std::env;
21-
use std::error::Error;
2221
use std::fs::File;
2322
use std::io::{BufReader, Read};
2423

@@ -185,17 +184,13 @@ fn cert_key_from_data(
185184
let mut cert_enc = ::base64::decode(client_cert_data)?;
186185
cert_enc.retain(|&i| i != 0);
187186
let cert_pem = String::from_utf8(cert_enc).map_err(|e| {
188-
KubeError::ConfigFileError(format!(
189-
"Invalid utf8 data in certificate: {}",
190-
e.description()
191-
))
187+
KubeError::ConfigFileError(format!("Invalid utf8 data in certificate: {}", e))
192188
})?;
193189
let cert = get_cert_from_pem(cert_pem.as_str());
194190
let mut key_enc = ::base64::decode(key_data)?;
195191
key_enc.retain(|&i| i != 0);
196-
let key_str = String::from_utf8(key_enc).map_err(|e| {
197-
KubeError::ConfigFileError(format!("Invalid utf8 data in key: {}", e.description()))
198-
})?;
192+
let key_str = String::from_utf8(key_enc)
193+
.map_err(|e| KubeError::ConfigFileError(format!("Invalid utf8 data in key: {}", e)))?;
199194
let key = get_key_from_str(key_str.as_str());
200195
match (cert, key) {
201196
(Some(c), Some(k)) => Ok(ClientCertKey::with_cert_and_key(c, k)),
@@ -247,8 +242,7 @@ impl Config {
247242
println!(
248243
"Invalid server cert path for cluster {}: {}.\nAny contexts \
249244
using this cluster will be unavailable.",
250-
cluster.name,
251-
e.description()
245+
cluster.name, e
252246
);
253247
}
254248
}
@@ -259,7 +253,7 @@ impl Config {
259253
let cert_pem = String::from_utf8(cert).map_err(|e| {
260254
KubeError::ConfigFileError(format!(
261255
"Invalid utf8 data in certificate: {}",
262-
e.description()
256+
e
263257
))
264258
})?;
265259
cluster_map.insert(
@@ -268,10 +262,7 @@ impl Config {
268262
);
269263
}
270264
Err(e) => {
271-
println!(
272-
"Invalid certificate data, could not base64 decode: {}",
273-
e.description()
274-
);
265+
println!("Invalid certificate data, could not base64 decode: {}", e);
275266
}
276267
},
277268
(None, None) => {

src/error.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,6 @@ impl fmt::Display for KubeError {
9797
}
9898

9999
impl error::Error for KubeError {
100-
fn description(&self) -> &str {
101-
match *self {
102-
KubeError::ParseErr(ref s) => s,
103-
KubeError::Kube(ref err) => err.description(),
104-
KubeError::KubeServerError(ref s) => s,
105-
KubeError::ConfigFileError(ref s) => s,
106-
KubeError::DecodeError(ref err) => err.description(),
107-
KubeError::Io(ref err) => err.description(),
108-
KubeError::HyperParse(ref err) => err.description(),
109-
KubeError::HyperErr(ref err) => err.description(),
110-
KubeError::SerdeJson(ref err) => err.description(),
111-
KubeError::SerdeYaml(ref err) => err.description(),
112-
KubeError::JoinPathsError(ref err) => err.description(),
113-
}
114-
}
115-
116100
fn cause(&self) -> Option<&dyn error::Error> {
117101
match *self {
118102
KubeError::ParseErr(_) => None,

src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ mod duct_mock;
7575

7676
use clap::{App, Arg};
7777

78-
use std::error::Error;
7978
use std::path::PathBuf;
8079

8180
use command_processor::CommandProcessor;
@@ -172,7 +171,7 @@ fn main() {
172171
Err(e) => {
173172
println!(
174173
"Could not load kubernetes config. Cannot continue. Error was: {}",
175-
e.description()
174+
e
176175
);
177176
return;
178177
}

0 commit comments

Comments
 (0)