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

Fix more Clippy warnings #1066

Merged
merged 1 commit into from
Dec 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions crates/nu-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ pub fn build() -> Result<(), Box<dyn std::error::Error>> {

if all_on && !flags.is_empty() {
println!(
"cargo:warning={}",
"Both NUSHELL_ENABLE_ALL_FLAGS and NUSHELL_ENABLE_FLAGS were set. You don't need both."
"cargo:warning=Both NUSHELL_ENABLE_ALL_FLAGS and NUSHELL_ENABLE_FLAGS were set. You don't need both."
);
}

Expand Down
4 changes: 2 additions & 2 deletions crates/nu-protocol/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ impl PrettyDebug for PositionalType {
fn pretty(&self) -> DebugDocBuilder {
match self {
PositionalType::Mandatory(string, shape) => {
b::description(string) + b::delimit("(", shape.pretty(), ")").as_kind().group()
b::description(string) + b::delimit("(", shape.pretty(), ")").into_kind().group()
}
PositionalType::Optional(string, shape) => {
b::description(string)
+ b::operator("?")
+ b::delimit("(", shape.pretty(), ")").as_kind().group()
+ b::delimit("(", shape.pretty(), ")").into_kind().group()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-protocol/src/value/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct DebugEntry<'a> {

impl<'a> PrettyDebug for DebugEntry<'a> {
fn pretty(&self) -> DebugDocBuilder {
(b::key(self.key.to_string()) + b::equals() + self.value.pretty().as_value()).group()
(b::key(self.key.to_string()) + b::equals() + self.value.pretty().into_value()).group()
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/nu-source/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl DebugDocBuilder {
DebugDocBuilder::styled(string, ShellStyle::Value)
}

pub fn as_value(self) -> DebugDocBuilder {
pub fn into_value(self) -> DebugDocBuilder {
self.inner
.annotate(ShellAnnotation::style(ShellStyle::Value))
.into()
Expand All @@ -149,7 +149,7 @@ impl DebugDocBuilder {
DebugDocBuilder::styled(string, ShellStyle::Kind)
}

pub fn as_kind(self) -> DebugDocBuilder {
pub fn into_kind(self) -> DebugDocBuilder {
self.inner
.annotate(ShellAnnotation::style(ShellStyle::Kind))
.into()
Expand Down
81 changes: 33 additions & 48 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,14 @@ fn load_plugin(path: &std::path::Path, context: &mut Context) -> Result<(), Shel

if context.get_command(&name).is_some() {
trace!("plugin {:?} already loaded.", &name);
} else if params.is_filter {
context.add_commands(vec![whole_stream_command(PluginCommand::new(
name, fname, params,
))]);
} else {
if params.is_filter {
context.add_commands(vec![whole_stream_command(
PluginCommand::new(name, fname, params),
)]);
} else {
context.add_commands(vec![whole_stream_command(PluginSink::new(
name, fname, params,
))]);
};
context.add_commands(vec![whole_stream_command(PluginSink::new(
name, fname, params,
))]);
}
Ok(())
}
Expand Down Expand Up @@ -482,55 +480,42 @@ fn set_env_from_config() {

let value = config.get("env");

match value {
Some(Value {
value: UntaggedValue::Row(r),
..
}) => {
for (k, v) in &r.entries {
match v.as_string() {
Ok(value_string) => {
std::env::set_var(k, value_string);
}
_ => {}
}
if let Some(Value {
value: UntaggedValue::Row(r),
..
}) = value
{
for (k, v) in &r.entries {
if let Ok(value_string) = v.as_string() {
std::env::set_var(k, value_string);
}
}
_ => {}
}
}

if config.contains_key("path") {
// Override the path with what they give us from config
let value = config.get("path");

match value {
Some(value) => match value {
Value {
value: UntaggedValue::Table(table),
..
} => {
let mut paths = vec![];
for val in table {
let path_str = val.as_string();
match path_str {
Err(_) => {}
Ok(path_str) => {
paths.push(PathBuf::from(path_str));
}
}
}
let path_os_string = std::env::join_paths(&paths);
match path_os_string {
Ok(path_os_string) => {
std::env::set_var("PATH", path_os_string);
}
Err(_) => {}
}
if let Some(Value {
value: UntaggedValue::Table(table),
..
}) = value
{
let mut paths = vec![];

for val in table {
let path_str = val.as_string();

if let Ok(path_str) = path_str {
paths.push(PathBuf::from(path_str));
}
_ => {}
},
None => {}
}

let path_os_string = std::env::join_paths(&paths);
if let Ok(path_os_string) = path_os_string {
std::env::set_var("PATH", path_os_string);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/from_ssv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn parse_separated_columns<'a>(
let headers = headers_raw
.split(&separator)
.map(str::trim)
.map(|s| s.to_owned())
.map(str::to_owned)
.filter(|s| !s.is_empty())
.collect();
collect(headers, lines, separator)
Expand Down
72 changes: 35 additions & 37 deletions src/commands/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,45 +50,43 @@ pub fn get_column_path(path: &ColumnPath, obj: &Value) -> Result<Value, ShellErr
obj,
path,
Box::new(move |(obj_source, column_path_tried, error)| {
match &obj_source.value {
UntaggedValue::Table(rows) => {
let total = rows.len();
let end_tag = match fields
.members()
.iter()
.nth_back(if fields.members().len() > 2 { 1 } else { 0 })
{
Some(last_field) => last_field.span,
None => column_path_tried.span,
};

return ShellError::labeled_error_with_secondary(
"Row not found",
format!(
"There isn't a row indexed at {}",
column_path_tried.display()
),
column_path_tried.span,
if total == 1 {
"The table only has 1 row".to_owned()
} else {
format!("The table only has {} rows (0 to {})", total, total - 1)
},
end_tag,
);
}
_ => {}
if let UntaggedValue::Table(rows) = &obj_source.value {
let total = rows.len();
let end_tag = match fields
.members()
.iter()
.nth_back(if fields.members().len() > 2 { 1 } else { 0 })
{
Some(last_field) => last_field.span,
None => column_path_tried.span,
};

let primary_label = format!(
"There isn't a row indexed at {}",
column_path_tried.display()
);

let secondary_label = if total == 1 {
"The table only has 1 row".to_owned()
} else {
format!("The table only has {} rows (0 to {})", total, total - 1)
};

return ShellError::labeled_error_with_secondary(
"Row not found",
primary_label,
column_path_tried.span,
secondary_label,
end_tag,
);
}

match did_you_mean(&obj_source, column_path_tried) {
Some(suggestions) => {
return ShellError::labeled_error(
"Unknown column",
format!("did you mean '{}'?", suggestions[0].1),
span_for_spanned_list(fields.members().iter().map(|p| p.span)),
)
}
None => {}
if let Some(suggestions) = did_you_mean(&obj_source, column_path_tried) {
return ShellError::labeled_error(
"Unknown column",
format!("did you mean '{}'?", suggestions[0].1),
span_for_spanned_list(fields.members().iter().map(|p| p.span)),
);
}

error
Expand Down