mirror of
https://github.com/nushell/nushell
synced 2024-12-26 04:53:09 +00:00
Fix more Clippy warnings
cargo clippy -- -W clippy::correctness
This commit is contained in:
parent
dfa5173cf4
commit
683f4c35d9
21 changed files with 395 additions and 455 deletions
|
@ -52,8 +52,7 @@ pub fn build() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
if all_on && !flags.is_empty() {
|
if all_on && !flags.is_empty() {
|
||||||
println!(
|
println!(
|
||||||
"cargo:warning={}",
|
"cargo:warning=Both NUSHELL_ENABLE_ALL_FLAGS and NUSHELL_ENABLE_FLAGS were set. You don't need both."
|
||||||
"Both NUSHELL_ENABLE_ALL_FLAGS and NUSHELL_ENABLE_FLAGS were set. You don't need both."
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,12 @@ impl PrettyDebug for PositionalType {
|
||||||
fn pretty(&self) -> DebugDocBuilder {
|
fn pretty(&self) -> DebugDocBuilder {
|
||||||
match self {
|
match self {
|
||||||
PositionalType::Mandatory(string, shape) => {
|
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) => {
|
PositionalType::Optional(string, shape) => {
|
||||||
b::description(string)
|
b::description(string)
|
||||||
+ b::operator("?")
|
+ b::operator("?")
|
||||||
+ b::delimit("(", shape.pretty(), ")").as_kind().group()
|
+ b::delimit("(", shape.pretty(), ")").into_kind().group()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ struct DebugEntry<'a> {
|
||||||
|
|
||||||
impl<'a> PrettyDebug for DebugEntry<'a> {
|
impl<'a> PrettyDebug for DebugEntry<'a> {
|
||||||
fn pretty(&self) -> DebugDocBuilder {
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ impl DebugDocBuilder {
|
||||||
DebugDocBuilder::styled(string, ShellStyle::Value)
|
DebugDocBuilder::styled(string, ShellStyle::Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_value(self) -> DebugDocBuilder {
|
pub fn into_value(self) -> DebugDocBuilder {
|
||||||
self.inner
|
self.inner
|
||||||
.annotate(ShellAnnotation::style(ShellStyle::Value))
|
.annotate(ShellAnnotation::style(ShellStyle::Value))
|
||||||
.into()
|
.into()
|
||||||
|
@ -149,7 +149,7 @@ impl DebugDocBuilder {
|
||||||
DebugDocBuilder::styled(string, ShellStyle::Kind)
|
DebugDocBuilder::styled(string, ShellStyle::Kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_kind(self) -> DebugDocBuilder {
|
pub fn into_kind(self) -> DebugDocBuilder {
|
||||||
self.inner
|
self.inner
|
||||||
.annotate(ShellAnnotation::style(ShellStyle::Kind))
|
.annotate(ShellAnnotation::style(ShellStyle::Kind))
|
||||||
.into()
|
.into()
|
||||||
|
|
81
src/cli.rs
81
src/cli.rs
|
@ -60,16 +60,14 @@ fn load_plugin(path: &std::path::Path, context: &mut Context) -> Result<(), Shel
|
||||||
|
|
||||||
if context.get_command(&name).is_some() {
|
if context.get_command(&name).is_some() {
|
||||||
trace!("plugin {:?} already loaded.", &name);
|
trace!("plugin {:?} already loaded.", &name);
|
||||||
|
} else if params.is_filter {
|
||||||
|
context.add_commands(vec![whole_stream_command(PluginCommand::new(
|
||||||
|
name, fname, params,
|
||||||
|
))]);
|
||||||
} else {
|
} else {
|
||||||
if params.is_filter {
|
context.add_commands(vec![whole_stream_command(PluginSink::new(
|
||||||
context.add_commands(vec![whole_stream_command(
|
name, fname, params,
|
||||||
PluginCommand::new(name, fname, params),
|
))]);
|
||||||
)]);
|
|
||||||
} else {
|
|
||||||
context.add_commands(vec![whole_stream_command(PluginSink::new(
|
|
||||||
name, fname, params,
|
|
||||||
))]);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -482,21 +480,16 @@ fn set_env_from_config() {
|
||||||
|
|
||||||
let value = config.get("env");
|
let value = config.get("env");
|
||||||
|
|
||||||
match value {
|
if let Some(Value {
|
||||||
Some(Value {
|
value: UntaggedValue::Row(r),
|
||||||
value: UntaggedValue::Row(r),
|
..
|
||||||
..
|
}) = value
|
||||||
}) => {
|
{
|
||||||
for (k, v) in &r.entries {
|
for (k, v) in &r.entries {
|
||||||
match v.as_string() {
|
if let Ok(value_string) = v.as_string() {
|
||||||
Ok(value_string) => {
|
std::env::set_var(k, value_string);
|
||||||
std::env::set_var(k, value_string);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,33 +497,25 @@ fn set_env_from_config() {
|
||||||
// Override the path with what they give us from config
|
// Override the path with what they give us from config
|
||||||
let value = config.get("path");
|
let value = config.get("path");
|
||||||
|
|
||||||
match value {
|
if let Some(Value {
|
||||||
Some(value) => match value {
|
value: UntaggedValue::Table(table),
|
||||||
Value {
|
..
|
||||||
value: UntaggedValue::Table(table),
|
}) = value
|
||||||
..
|
{
|
||||||
} => {
|
let mut paths = vec![];
|
||||||
let mut paths = vec![];
|
|
||||||
for val in table {
|
for val in table {
|
||||||
let path_str = val.as_string();
|
let path_str = val.as_string();
|
||||||
match path_str {
|
|
||||||
Err(_) => {}
|
if let Ok(path_str) = path_str {
|
||||||
Ok(path_str) => {
|
paths.push(PathBuf::from(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(_) => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
}
|
||||||
},
|
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,7 @@ fn parse_separated_columns<'a>(
|
||||||
let headers = headers_raw
|
let headers = headers_raw
|
||||||
.split(&separator)
|
.split(&separator)
|
||||||
.map(str::trim)
|
.map(str::trim)
|
||||||
.map(|s| s.to_owned())
|
.map(str::to_owned)
|
||||||
.filter(|s| !s.is_empty())
|
.filter(|s| !s.is_empty())
|
||||||
.collect();
|
.collect();
|
||||||
collect(headers, lines, separator)
|
collect(headers, lines, separator)
|
||||||
|
|
|
@ -50,45 +50,43 @@ pub fn get_column_path(path: &ColumnPath, obj: &Value) -> Result<Value, ShellErr
|
||||||
obj,
|
obj,
|
||||||
path,
|
path,
|
||||||
Box::new(move |(obj_source, column_path_tried, error)| {
|
Box::new(move |(obj_source, column_path_tried, error)| {
|
||||||
match &obj_source.value {
|
if let UntaggedValue::Table(rows) = &obj_source.value {
|
||||||
UntaggedValue::Table(rows) => {
|
let total = rows.len();
|
||||||
let total = rows.len();
|
let end_tag = match fields
|
||||||
let end_tag = match fields
|
.members()
|
||||||
.members()
|
.iter()
|
||||||
.iter()
|
.nth_back(if fields.members().len() > 2 { 1 } else { 0 })
|
||||||
.nth_back(if fields.members().len() > 2 { 1 } else { 0 })
|
{
|
||||||
{
|
Some(last_field) => last_field.span,
|
||||||
Some(last_field) => last_field.span,
|
None => column_path_tried.span,
|
||||||
None => column_path_tried.span,
|
};
|
||||||
};
|
|
||||||
|
|
||||||
return ShellError::labeled_error_with_secondary(
|
let primary_label = format!(
|
||||||
"Row not found",
|
"There isn't a row indexed at {}",
|
||||||
format!(
|
column_path_tried.display()
|
||||||
"There isn't a row indexed at {}",
|
);
|
||||||
column_path_tried.display()
|
|
||||||
),
|
let secondary_label = if total == 1 {
|
||||||
column_path_tried.span,
|
"The table only has 1 row".to_owned()
|
||||||
if total == 1 {
|
} else {
|
||||||
"The table only has 1 row".to_owned()
|
format!("The table only has {} rows (0 to {})", total, total - 1)
|
||||||
} else {
|
};
|
||||||
format!("The table only has {} rows (0 to {})", total, total - 1)
|
|
||||||
},
|
return ShellError::labeled_error_with_secondary(
|
||||||
end_tag,
|
"Row not found",
|
||||||
);
|
primary_label,
|
||||||
}
|
column_path_tried.span,
|
||||||
_ => {}
|
secondary_label,
|
||||||
|
end_tag,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
match did_you_mean(&obj_source, column_path_tried) {
|
if let Some(suggestions) = did_you_mean(&obj_source, column_path_tried) {
|
||||||
Some(suggestions) => {
|
return ShellError::labeled_error(
|
||||||
return ShellError::labeled_error(
|
"Unknown column",
|
||||||
"Unknown column",
|
format!("did you mean '{}'?", suggestions[0].1),
|
||||||
format!("did you mean '{}'?", suggestions[0].1),
|
span_for_spanned_list(fields.members().iter().map(|p| p.span)),
|
||||||
span_for_spanned_list(fields.members().iter().map(|p| p.span)),
|
);
|
||||||
)
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error
|
error
|
||||||
|
|
|
@ -57,104 +57,100 @@ impl PerItemCommand for Help {
|
||||||
|
|
||||||
help.push_back(ReturnSuccess::value(short_desc.into_value()));
|
help.push_back(ReturnSuccess::value(short_desc.into_value()));
|
||||||
}
|
}
|
||||||
} else {
|
} else if let Some(command) = registry.get_command(document) {
|
||||||
if let Some(command) = registry.get_command(document) {
|
let mut long_desc = String::new();
|
||||||
let mut long_desc = String::new();
|
|
||||||
|
|
||||||
long_desc.push_str(&command.usage());
|
long_desc.push_str(&command.usage());
|
||||||
long_desc.push_str("\n");
|
long_desc.push_str("\n");
|
||||||
|
|
||||||
let signature = command.signature();
|
let signature = command.signature();
|
||||||
|
|
||||||
let mut one_liner = String::new();
|
let mut one_liner = String::new();
|
||||||
one_liner.push_str(&signature.name);
|
one_liner.push_str(&signature.name);
|
||||||
one_liner.push_str(" ");
|
one_liner.push_str(" ");
|
||||||
|
|
||||||
for positional in &signature.positional {
|
for positional in &signature.positional {
|
||||||
match &positional.0 {
|
match &positional.0 {
|
||||||
|
PositionalType::Mandatory(name, _m) => {
|
||||||
|
one_liner.push_str(&format!("<{}> ", name));
|
||||||
|
}
|
||||||
|
PositionalType::Optional(name, _o) => {
|
||||||
|
one_liner.push_str(&format!("({}) ", name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if signature.rest_positional.is_some() {
|
||||||
|
one_liner.push_str(" ...args");
|
||||||
|
}
|
||||||
|
|
||||||
|
if !signature.named.is_empty() {
|
||||||
|
one_liner.push_str("{flags} ");
|
||||||
|
}
|
||||||
|
|
||||||
|
long_desc.push_str(&format!("\nUsage:\n > {}\n", one_liner));
|
||||||
|
|
||||||
|
if !signature.positional.is_empty() || signature.rest_positional.is_some() {
|
||||||
|
long_desc.push_str("\nparameters:\n");
|
||||||
|
for positional in signature.positional {
|
||||||
|
match positional.0 {
|
||||||
PositionalType::Mandatory(name, _m) => {
|
PositionalType::Mandatory(name, _m) => {
|
||||||
one_liner.push_str(&format!("<{}> ", name));
|
long_desc.push_str(&format!(" <{}> {}\n", name, positional.1));
|
||||||
}
|
}
|
||||||
PositionalType::Optional(name, _o) => {
|
PositionalType::Optional(name, _o) => {
|
||||||
one_liner.push_str(&format!("({}) ", name));
|
long_desc.push_str(&format!(" ({}) {}\n", name, positional.1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if signature.rest_positional.is_some() {
|
if signature.rest_positional.is_some() {
|
||||||
one_liner.push_str(" ...args");
|
long_desc.push_str(&format!(
|
||||||
|
" ...args{} {}\n",
|
||||||
|
if signature.rest_positional.is_some() {
|
||||||
|
":"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
|
signature.rest_positional.unwrap().1
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !signature.named.is_empty() {
|
|
||||||
one_liner.push_str("{flags} ");
|
|
||||||
}
|
|
||||||
|
|
||||||
long_desc.push_str(&format!("\nUsage:\n > {}\n", one_liner));
|
|
||||||
|
|
||||||
if !signature.positional.is_empty() || signature.rest_positional.is_some() {
|
|
||||||
long_desc.push_str("\nparameters:\n");
|
|
||||||
for positional in signature.positional {
|
|
||||||
match positional.0 {
|
|
||||||
PositionalType::Mandatory(name, _m) => {
|
|
||||||
long_desc
|
|
||||||
.push_str(&format!(" <{}> {}\n", name, positional.1));
|
|
||||||
}
|
|
||||||
PositionalType::Optional(name, _o) => {
|
|
||||||
long_desc
|
|
||||||
.push_str(&format!(" ({}) {}\n", name, positional.1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if signature.rest_positional.is_some() {
|
|
||||||
long_desc.push_str(&format!(
|
|
||||||
" ...args{} {}\n",
|
|
||||||
if signature.rest_positional.is_some() {
|
|
||||||
":"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
signature.rest_positional.unwrap().1
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !signature.named.is_empty() {
|
|
||||||
long_desc.push_str("\nflags:\n");
|
|
||||||
for (flag, ty) in signature.named {
|
|
||||||
match ty.0 {
|
|
||||||
NamedType::Switch => {
|
|
||||||
long_desc.push_str(&format!(
|
|
||||||
" --{}{} {}\n",
|
|
||||||
flag,
|
|
||||||
if !ty.1.is_empty() { ":" } else { "" },
|
|
||||||
ty.1
|
|
||||||
));
|
|
||||||
}
|
|
||||||
NamedType::Mandatory(m) => {
|
|
||||||
long_desc.push_str(&format!(
|
|
||||||
" --{} <{}> (required parameter){} {}\n",
|
|
||||||
flag,
|
|
||||||
m.display(),
|
|
||||||
if !ty.1.is_empty() { ":" } else { "" },
|
|
||||||
ty.1
|
|
||||||
));
|
|
||||||
}
|
|
||||||
NamedType::Optional(o) => {
|
|
||||||
long_desc.push_str(&format!(
|
|
||||||
" --{} <{}>{} {}\n",
|
|
||||||
flag,
|
|
||||||
o.display(),
|
|
||||||
if !ty.1.is_empty() { ":" } else { "" },
|
|
||||||
ty.1
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
help.push_back(ReturnSuccess::value(
|
|
||||||
UntaggedValue::string(long_desc).into_value(tag.clone()),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
if !signature.named.is_empty() {
|
||||||
|
long_desc.push_str("\nflags:\n");
|
||||||
|
for (flag, ty) in signature.named {
|
||||||
|
match ty.0 {
|
||||||
|
NamedType::Switch => {
|
||||||
|
long_desc.push_str(&format!(
|
||||||
|
" --{}{} {}\n",
|
||||||
|
flag,
|
||||||
|
if !ty.1.is_empty() { ":" } else { "" },
|
||||||
|
ty.1
|
||||||
|
));
|
||||||
|
}
|
||||||
|
NamedType::Mandatory(m) => {
|
||||||
|
long_desc.push_str(&format!(
|
||||||
|
" --{} <{}> (required parameter){} {}\n",
|
||||||
|
flag,
|
||||||
|
m.display(),
|
||||||
|
if !ty.1.is_empty() { ":" } else { "" },
|
||||||
|
ty.1
|
||||||
|
));
|
||||||
|
}
|
||||||
|
NamedType::Optional(o) => {
|
||||||
|
long_desc.push_str(&format!(
|
||||||
|
" --{} <{}>{} {}\n",
|
||||||
|
flag,
|
||||||
|
o.display(),
|
||||||
|
if !ty.1.is_empty() { ":" } else { "" },
|
||||||
|
ty.1
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
help.push_back(ReturnSuccess::value(
|
||||||
|
UntaggedValue::string(long_desc).into_value(tag.clone()),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(help.to_output_stream())
|
Ok(help.to_output_stream())
|
||||||
|
|
|
@ -43,14 +43,13 @@ pub fn which(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStre
|
||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Primitive(Primitive::String(s)),
|
value: UntaggedValue::Primitive(Primitive::String(s)),
|
||||||
tag,
|
tag,
|
||||||
} => match which::which(&s) {
|
} => {
|
||||||
Ok(ok) => {
|
if let Ok(ok) = which::which(&s) {
|
||||||
which_out.push_back(
|
which_out.push_back(
|
||||||
UntaggedValue::Primitive(Primitive::Path(ok)).into_value(tag.clone()),
|
UntaggedValue::Primitive(Primitive::Path(ok)).into_value(tag.clone()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => {}
|
}
|
||||||
},
|
|
||||||
Value { tag, .. } => {
|
Value { tag, .. } => {
|
||||||
return Err(ShellError::labeled_error(
|
return Err(ShellError::labeled_error(
|
||||||
"Expected a filename to find",
|
"Expected a filename to find",
|
||||||
|
|
|
@ -132,15 +132,14 @@ pub(crate) fn get_data_by_member(value: &Value, name: &PathMember) -> Result<Val
|
||||||
let mut out = vec![];
|
let mut out = vec![];
|
||||||
|
|
||||||
for item in l {
|
for item in l {
|
||||||
match item {
|
if let Value {
|
||||||
Value {
|
value: UntaggedValue::Row(o),
|
||||||
value: UntaggedValue::Row(o),
|
..
|
||||||
..
|
} = item
|
||||||
} => match o.get_data_by_key(string[..].spanned(name.span)) {
|
{
|
||||||
Some(v) => out.push(v),
|
if let Some(v) = o.get_data_by_key(string[..].spanned(name.span)) {
|
||||||
None => {}
|
out.push(v)
|
||||||
},
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,16 +220,12 @@ pub fn insert_data_at_path(value: &Value, path: &str, new_value: Value) -> Optio
|
||||||
match current.entries.get_mut(split_path[idx]) {
|
match current.entries.get_mut(split_path[idx]) {
|
||||||
Some(next) => {
|
Some(next) => {
|
||||||
if idx == (split_path.len() - 2) {
|
if idx == (split_path.len() - 2) {
|
||||||
match &mut next.value {
|
if let UntaggedValue::Row(o) = &mut next.value {
|
||||||
UntaggedValue::Row(o) => {
|
o.entries.insert(
|
||||||
o.entries.insert(
|
split_path[idx + 1].to_string(),
|
||||||
split_path[idx + 1].to_string(),
|
new_value.value.clone().into_value(&value.tag),
|
||||||
new_value.value.clone().into_value(&value.tag),
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Some(new_obj.clone());
|
return Some(new_obj.clone());
|
||||||
} else {
|
} else {
|
||||||
match next.value {
|
match next.value {
|
||||||
|
@ -497,15 +492,14 @@ pub(crate) fn get_mut_data_by_member<'value>(
|
||||||
UntaggedValue::Table(l) => match &name.unspanned {
|
UntaggedValue::Table(l) => match &name.unspanned {
|
||||||
UnspannedPathMember::String(string) => {
|
UnspannedPathMember::String(string) => {
|
||||||
for item in l {
|
for item in l {
|
||||||
match item {
|
if let Value {
|
||||||
Value {
|
value: UntaggedValue::Row(o),
|
||||||
value: UntaggedValue::Row(o),
|
..
|
||||||
..
|
} = item
|
||||||
} => match o.get_mut_data_by_key(&string) {
|
{
|
||||||
Some(v) => return Some(v),
|
if let Some(v) = o.get_mut_data_by_key(&string) {
|
||||||
None => {}
|
return Some(v);
|
||||||
},
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
|
|
@ -135,7 +135,7 @@ impl PrettyDebug for TypeShape {
|
||||||
(b::key(match key {
|
(b::key(match key {
|
||||||
Column::String(string) => string.clone(),
|
Column::String(string) => string.clone(),
|
||||||
Column::Value => "<value>".to_string(),
|
Column::Value => "<value>".to_string(),
|
||||||
}) + b::delimit("(", ty.pretty(), ")").as_kind())
|
}) + b::delimit("(", ty.pretty(), ")").into_kind())
|
||||||
.nest()
|
.nest()
|
||||||
}),
|
}),
|
||||||
b::space(),
|
b::space(),
|
||||||
|
@ -197,7 +197,7 @@ impl<'a> PrettyDebug for DebugEntry<'a> {
|
||||||
(b::key(match self.key {
|
(b::key(match self.key {
|
||||||
Column::String(string) => string.clone(),
|
Column::String(string) => string.clone(),
|
||||||
Column::Value => "<value>".to_owned(),
|
Column::Value => "<value>".to_owned(),
|
||||||
}) + b::delimit("(", self.value.pretty(), ")").as_kind())
|
}) + b::delimit("(", self.value.pretty(), ")").into_kind())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ struct DebugEntry<'a> {
|
||||||
|
|
||||||
impl<'a> PrettyDebug for DebugEntry<'a> {
|
impl<'a> PrettyDebug for DebugEntry<'a> {
|
||||||
fn pretty(&self) -> DebugDocBuilder {
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,19 +47,16 @@ pub(crate) fn dir_entry_dict(
|
||||||
|
|
||||||
dict.insert_untagged("size", UntaggedValue::bytes(metadata.len() as u64));
|
dict.insert_untagged("size", UntaggedValue::bytes(metadata.len() as u64));
|
||||||
|
|
||||||
match metadata.created() {
|
if let Ok(c) = metadata.created() {
|
||||||
Ok(c) => dict.insert_untagged("created", UntaggedValue::system_date(c)),
|
dict.insert_untagged("created", UntaggedValue::system_date(c));
|
||||||
Err(_) => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match metadata.accessed() {
|
if let Ok(a) = metadata.accessed() {
|
||||||
Ok(a) => dict.insert_untagged("accessed", UntaggedValue::system_date(a)),
|
dict.insert_untagged("accessed", UntaggedValue::system_date(a));
|
||||||
Err(_) => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match metadata.modified() {
|
if let Ok(m) = metadata.modified() {
|
||||||
Ok(m) => dict.insert_untagged("modified", UntaggedValue::system_date(m)),
|
dict.insert_untagged("modified", UntaggedValue::system_date(m));
|
||||||
Err(_) => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(dict.into_value())
|
Ok(dict.into_value())
|
||||||
|
|
|
@ -41,14 +41,12 @@ impl<'de> ConfigDeserializer<'de> {
|
||||||
let positional = self.call.args.slice_from(self.position);
|
let positional = self.call.args.slice_from(self.position);
|
||||||
self.position += positional.len();
|
self.position += positional.len();
|
||||||
Some(UntaggedValue::Table(positional).into_untagged_value()) // TODO: correct tag
|
Some(UntaggedValue::Table(positional).into_untagged_value()) // TODO: correct tag
|
||||||
|
} else if self.call.args.has(name) {
|
||||||
|
self.call.args.get(name).cloned()
|
||||||
} else {
|
} else {
|
||||||
if self.call.args.has(name) {
|
let position = self.position;
|
||||||
self.call.args.get(name).cloned()
|
self.position += 1;
|
||||||
} else {
|
self.call.args.nth(position).cloned()
|
||||||
let position = self.position;
|
|
||||||
self.position += 1;
|
|
||||||
self.call.args.nth(position).cloned()
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
trace!("pushing {:?}", value);
|
trace!("pushing {:?}", value);
|
||||||
|
|
|
@ -161,13 +161,11 @@ fn evaluate_reference(
|
||||||
}
|
}
|
||||||
x if x == "nu:path" => {
|
x if x == "nu:path" => {
|
||||||
let mut table = vec![];
|
let mut table = vec![];
|
||||||
match std::env::var_os("PATH") {
|
let path = std::env::var_os("PATH");
|
||||||
Some(paths) => {
|
if let Some(paths) = path {
|
||||||
for path in std::env::split_paths(&paths) {
|
for path in std::env::split_paths(&paths) {
|
||||||
table.push(UntaggedValue::path(path).into_value(&tag));
|
table.push(UntaggedValue::path(path).into_value(&tag));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
Ok(UntaggedValue::table(&table).into_value(tag))
|
Ok(UntaggedValue::table(&table).into_value(tag))
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ fn values_to_entries(values: &[Value], headers: &mut Vec<String>, starting_idx:
|
||||||
entries
|
entries
|
||||||
}
|
}
|
||||||
|
|
||||||
fn max_per_column(headers: &Vec<String>, entries: &Entries, values_len: usize) -> Vec<usize> {
|
fn max_per_column(headers: &[String], entries: &Entries, values_len: usize) -> Vec<usize> {
|
||||||
let mut max_per_column = vec![];
|
let mut max_per_column = vec![];
|
||||||
|
|
||||||
for i in 0..headers.len() {
|
for i in 0..headers.len() {
|
||||||
|
@ -181,13 +181,13 @@ fn maybe_truncate_columns(headers: &mut Vec<String>, entries: &mut Entries, term
|
||||||
if max_num_of_columns < headers.len() {
|
if max_num_of_columns < headers.len() {
|
||||||
headers.truncate(max_num_of_columns);
|
headers.truncate(max_num_of_columns);
|
||||||
|
|
||||||
for entry in &mut entries.into_iter() {
|
for entry in entries.iter_mut() {
|
||||||
entry.truncate(max_num_of_columns);
|
entry.truncate(max_num_of_columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
headers.push("...".to_owned());
|
headers.push("...".to_owned());
|
||||||
|
|
||||||
for entry in &mut entries.into_iter() {
|
for entry in entries.iter_mut() {
|
||||||
entry.push(("...".to_owned(), "c")); // ellipsis is centred
|
entry.push(("...".to_owned(), "c")); // ellipsis is centred
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,24 +304,17 @@ fn wrap_cells(
|
||||||
max_naive_column_width: usize,
|
max_naive_column_width: usize,
|
||||||
max_column_width: usize,
|
max_column_width: usize,
|
||||||
) -> TableView {
|
) -> TableView {
|
||||||
{
|
for head in 0..headers.len() {
|
||||||
let entries = &mut entries;
|
if max_per_column[head] > max_naive_column_width {
|
||||||
|
headers[head] = fill(&headers[head], max_column_width);
|
||||||
|
|
||||||
for head in 0..headers.len() {
|
for entry in entries.iter_mut() {
|
||||||
if max_per_column[head] > max_naive_column_width {
|
entry[head].0 = fill(&entry[head].0, max_column_width);
|
||||||
headers[head] = fill(&headers[head], max_column_width);
|
|
||||||
|
|
||||||
for entry in &mut entries.into_iter() {
|
|
||||||
entry[head].0 = fill(&entry[head].0, max_column_width);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TableView {
|
TableView { headers, entries }
|
||||||
headers: headers,
|
|
||||||
entries: entries,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderView for TableView {
|
impl RenderView for TableView {
|
||||||
|
|
|
@ -87,38 +87,36 @@ impl Plugin for Format {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filter(&mut self, input: Value) -> Result<Vec<ReturnValue>, ShellError> {
|
fn filter(&mut self, input: Value) -> Result<Vec<ReturnValue>, ShellError> {
|
||||||
match &input {
|
if let Value {
|
||||||
Value {
|
value: UntaggedValue::Row(dict),
|
||||||
value: UntaggedValue::Row(dict),
|
..
|
||||||
..
|
} = &input
|
||||||
} => {
|
{
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
|
|
||||||
for command in &self.commands {
|
for command in &self.commands {
|
||||||
match command {
|
match command {
|
||||||
FormatCommand::Text(s) => {
|
FormatCommand::Text(s) => {
|
||||||
output.push_str(s);
|
output.push_str(s);
|
||||||
}
|
}
|
||||||
FormatCommand::Column(c) => {
|
FormatCommand::Column(c) => {
|
||||||
match dict.entries.get(c) {
|
match dict.entries.get(c) {
|
||||||
Some(c) => match c.as_string() {
|
Some(c) => match c.as_string() {
|
||||||
Ok(v) => output.push_str(&v),
|
Ok(v) => output.push_str(&v),
|
||||||
_ => return Ok(vec![]),
|
_ => return Ok(vec![]),
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
// This row doesn't match, so don't emit anything
|
// This row doesn't match, so don't emit anything
|
||||||
return Ok(vec![]);
|
return Ok(vec![]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(vec![ReturnSuccess::value(
|
|
||||||
UntaggedValue::string(output).into_untagged_value(),
|
|
||||||
)]);
|
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
|
return Ok(vec![ReturnSuccess::value(
|
||||||
|
UntaggedValue::string(output).into_untagged_value(),
|
||||||
|
)]);
|
||||||
}
|
}
|
||||||
Ok(vec![])
|
Ok(vec![])
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,11 +48,8 @@ fn column_names(commands: &[ParseCommand]) -> Vec<String> {
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
|
|
||||||
for command in commands {
|
for command in commands {
|
||||||
match command {
|
if let ParseCommand::Column(c) = command {
|
||||||
ParseCommand::Column(c) => {
|
output.push(c.clone());
|
||||||
output.push(c.clone());
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,9 +94,8 @@ impl Shell for FilesystemShell {
|
||||||
let cwd = self.path();
|
let cwd = self.path();
|
||||||
let mut full_path = PathBuf::from(self.path());
|
let mut full_path = PathBuf::from(self.path());
|
||||||
|
|
||||||
match &pattern {
|
if let Some(value) = &pattern {
|
||||||
Some(value) => full_path.push((*value).as_ref()),
|
full_path.push((*value).as_ref())
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let ctrl_c = context.ctrl_c.clone();
|
let ctrl_c = context.ctrl_c.clone();
|
||||||
|
@ -350,19 +349,17 @@ impl Shell for FilesystemShell {
|
||||||
let sources = sources.paths_applying_with(strategy)?;
|
let sources = sources.paths_applying_with(strategy)?;
|
||||||
|
|
||||||
for (ref src, ref dst) in sources {
|
for (ref src, ref dst) in sources {
|
||||||
if src.is_dir() {
|
if src.is_dir() && !dst.exists() {
|
||||||
if !dst.exists() {
|
match std::fs::create_dir_all(dst) {
|
||||||
match std::fs::create_dir_all(dst) {
|
Err(e) => {
|
||||||
Err(e) => {
|
return Err(ShellError::labeled_error(
|
||||||
return Err(ShellError::labeled_error(
|
e.to_string(),
|
||||||
e.to_string(),
|
e.to_string(),
|
||||||
e.to_string(),
|
name_tag,
|
||||||
name_tag,
|
));
|
||||||
));
|
}
|
||||||
}
|
Ok(o) => o,
|
||||||
Ok(o) => o,
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if src.is_file() {
|
if src.is_file() {
|
||||||
|
@ -424,19 +421,17 @@ impl Shell for FilesystemShell {
|
||||||
let sources = sources.paths_applying_with(strategy)?;
|
let sources = sources.paths_applying_with(strategy)?;
|
||||||
|
|
||||||
for (ref src, ref dst) in sources {
|
for (ref src, ref dst) in sources {
|
||||||
if src.is_dir() {
|
if src.is_dir() && !dst.exists() {
|
||||||
if !dst.exists() {
|
match std::fs::create_dir_all(dst) {
|
||||||
match std::fs::create_dir_all(dst) {
|
Err(e) => {
|
||||||
Err(e) => {
|
return Err(ShellError::labeled_error(
|
||||||
return Err(ShellError::labeled_error(
|
e.to_string(),
|
||||||
e.to_string(),
|
e.to_string(),
|
||||||
e.to_string(),
|
name_tag,
|
||||||
name_tag,
|
));
|
||||||
));
|
}
|
||||||
}
|
Ok(o) => o,
|
||||||
Ok(o) => o,
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if src.is_file() {
|
if src.is_file() {
|
||||||
|
@ -455,68 +450,66 @@ impl Shell for FilesystemShell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if destination.exists() {
|
||||||
if destination.exists() {
|
if !sources.iter().all(|x| match x {
|
||||||
if !sources.iter().all(|x| match x {
|
Ok(f) => f.is_file(),
|
||||||
Ok(f) => f.is_file(),
|
Err(_) => false,
|
||||||
Err(_) => false,
|
}) {
|
||||||
}) {
|
return Err(ShellError::labeled_error(
|
||||||
return Err(ShellError::labeled_error(
|
|
||||||
"Copy aborted (directories found). Recursive copying in patterns not supported yet (try copying the directory directly)",
|
"Copy aborted (directories found). Recursive copying in patterns not supported yet (try copying the directory directly)",
|
||||||
"Copy aborted (directories found). Recursive copying in patterns not supported yet (try copying the directory directly)",
|
"Copy aborted (directories found). Recursive copying in patterns not supported yet (try copying the directory directly)",
|
||||||
src.tag,
|
src.tag,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
for entry in sources {
|
for entry in sources {
|
||||||
if let Ok(entry) = entry {
|
if let Ok(entry) = entry {
|
||||||
let mut to = PathBuf::from(&destination);
|
let mut to = PathBuf::from(&destination);
|
||||||
|
|
||||||
match entry.file_name() {
|
match entry.file_name() {
|
||||||
Some(name) => to.push(name),
|
Some(name) => to.push(name),
|
||||||
None => {
|
|
||||||
return Err(ShellError::labeled_error(
|
|
||||||
"Copy aborted. Not a valid path",
|
|
||||||
"Copy aborted. Not a valid path",
|
|
||||||
name_tag,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if entry.is_file() {
|
|
||||||
match std::fs::copy(&entry, &to) {
|
|
||||||
Err(e) => {
|
|
||||||
return Err(ShellError::labeled_error(
|
|
||||||
e.to_string(),
|
|
||||||
e.to_string(),
|
|
||||||
src.tag,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Ok(o) => o,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let destination_file_name = {
|
|
||||||
match destination.file_name() {
|
|
||||||
Some(name) => PathBuf::from(name),
|
|
||||||
None => {
|
None => {
|
||||||
return Err(ShellError::labeled_error(
|
return Err(ShellError::labeled_error(
|
||||||
"Copy aborted. Not a valid destination",
|
"Copy aborted. Not a valid path",
|
||||||
"Copy aborted. Not a valid destination",
|
"Copy aborted. Not a valid path",
|
||||||
name_tag,
|
name_tag,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
return Err(ShellError::labeled_error(
|
if entry.is_file() {
|
||||||
format!("Copy aborted. (Does {:?} exist?)", destination_file_name),
|
match std::fs::copy(&entry, &to) {
|
||||||
format!("Copy aborted. (Does {:?} exist?)", destination_file_name),
|
Err(e) => {
|
||||||
dst.tag(),
|
return Err(ShellError::labeled_error(
|
||||||
));
|
e.to_string(),
|
||||||
|
e.to_string(),
|
||||||
|
src.tag,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(o) => o,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
let destination_file_name = {
|
||||||
|
match destination.file_name() {
|
||||||
|
Some(name) => PathBuf::from(name),
|
||||||
|
None => {
|
||||||
|
return Err(ShellError::labeled_error(
|
||||||
|
"Copy aborted. Not a valid destination",
|
||||||
|
"Copy aborted. Not a valid destination",
|
||||||
|
name_tag,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return Err(ShellError::labeled_error(
|
||||||
|
format!("Copy aborted. (Does {:?} exist?)", destination_file_name),
|
||||||
|
format!("Copy aborted. (Does {:?} exist?)", destination_file_name),
|
||||||
|
dst.tag(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(OutputStream::empty())
|
Ok(OutputStream::empty())
|
||||||
|
@ -545,15 +538,13 @@ impl Shell for FilesystemShell {
|
||||||
loc
|
loc
|
||||||
};
|
};
|
||||||
|
|
||||||
match std::fs::create_dir_all(create_at) {
|
let dir_res = std::fs::create_dir_all(create_at);
|
||||||
Err(reason) => {
|
if let Err(reason) = dir_res {
|
||||||
return Err(ShellError::labeled_error(
|
return Err(ShellError::labeled_error(
|
||||||
reason.to_string(),
|
reason.to_string(),
|
||||||
reason.to_string(),
|
reason.to_string(),
|
||||||
dir.tag(),
|
dir.tag(),
|
||||||
))
|
));
|
||||||
}
|
|
||||||
Ok(_) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -859,50 +850,90 @@ impl Shell for FilesystemShell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if destination.exists() {
|
||||||
if destination.exists() {
|
let is_file = |x: &Result<PathBuf, _>| {
|
||||||
let is_file = |x: &Result<PathBuf, _>| {
|
x.as_ref().map(|entry| entry.is_file()).unwrap_or_default()
|
||||||
x.as_ref().map(|entry| entry.is_file()).unwrap_or_default()
|
};
|
||||||
};
|
|
||||||
|
|
||||||
if !sources.iter().all(is_file) {
|
if !sources.iter().all(is_file) {
|
||||||
return Err(ShellError::labeled_error(
|
return Err(ShellError::labeled_error(
|
||||||
"Rename aborted (directories found). Renaming in patterns not supported yet (try moving the directory directly)",
|
"Rename aborted (directories found). Renaming in patterns not supported yet (try moving the directory directly)",
|
||||||
"Rename aborted (directories found). Renaming in patterns not supported yet (try moving the directory directly)",
|
"Rename aborted (directories found). Renaming in patterns not supported yet (try moving the directory directly)",
|
||||||
src.tag,
|
src.tag,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
for entry in sources {
|
for entry in sources {
|
||||||
if let Ok(entry) = entry {
|
if let Ok(entry) = entry {
|
||||||
let entry_file_name = match entry.file_name() {
|
let entry_file_name = match entry.file_name() {
|
||||||
Some(name) => name,
|
Some(name) => name,
|
||||||
None => {
|
None => {
|
||||||
return Err(ShellError::labeled_error(
|
return Err(ShellError::labeled_error(
|
||||||
"Rename aborted. Not a valid entry name",
|
"Rename aborted. Not a valid entry name",
|
||||||
"Rename aborted. Not a valid entry name",
|
"Rename aborted. Not a valid entry name",
|
||||||
name_tag,
|
name_tag,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut to = PathBuf::from(&destination);
|
let mut to = PathBuf::from(&destination);
|
||||||
to.push(entry_file_name);
|
to.push(entry_file_name);
|
||||||
|
|
||||||
if entry.is_file() {
|
if entry.is_file() {
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
{
|
{
|
||||||
match std::fs::rename(&entry, &to) {
|
match std::fs::rename(&entry, &to) {
|
||||||
|
Err(e) => {
|
||||||
|
return Err(ShellError::labeled_error(
|
||||||
|
format!(
|
||||||
|
"Rename {:?} to {:?} aborted. {:}",
|
||||||
|
entry_file_name,
|
||||||
|
destination_file_name,
|
||||||
|
e.to_string(),
|
||||||
|
),
|
||||||
|
format!(
|
||||||
|
"Rename {:?} to {:?} aborted. {:}",
|
||||||
|
entry_file_name,
|
||||||
|
destination_file_name,
|
||||||
|
e.to_string(),
|
||||||
|
),
|
||||||
|
name_tag,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(o) => o,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
match std::fs::copy(&entry, &to) {
|
||||||
|
Err(e) => {
|
||||||
|
return Err(ShellError::labeled_error(
|
||||||
|
format!(
|
||||||
|
"Rename {:?} to {:?} aborted. {:}",
|
||||||
|
entry_file_name,
|
||||||
|
destination_file_name,
|
||||||
|
e.to_string(),
|
||||||
|
),
|
||||||
|
format!(
|
||||||
|
"Rename {:?} to {:?} aborted. {:}",
|
||||||
|
entry_file_name,
|
||||||
|
destination_file_name,
|
||||||
|
e.to_string(),
|
||||||
|
),
|
||||||
|
name_tag,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(_) => match std::fs::remove_file(&entry) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Err(ShellError::labeled_error(
|
return Err(ShellError::labeled_error(
|
||||||
format!(
|
format!(
|
||||||
"Rename {:?} to {:?} aborted. {:}",
|
"Remove {:?} to {:?} aborted. {:}",
|
||||||
entry_file_name,
|
entry_file_name,
|
||||||
destination_file_name,
|
destination_file_name,
|
||||||
e.to_string(),
|
e.to_string(),
|
||||||
),
|
),
|
||||||
format!(
|
format!(
|
||||||
"Rename {:?} to {:?} aborted. {:}",
|
"Remove {:?} to {:?} aborted. {:}",
|
||||||
entry_file_name,
|
entry_file_name,
|
||||||
destination_file_name,
|
destination_file_name,
|
||||||
e.to_string(),
|
e.to_string(),
|
||||||
|
@ -911,60 +942,18 @@ impl Shell for FilesystemShell {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(o) => o,
|
Ok(o) => o,
|
||||||
};
|
},
|
||||||
}
|
};
|
||||||
#[cfg(windows)]
|
|
||||||
{
|
|
||||||
match std::fs::copy(&entry, &to) {
|
|
||||||
Err(e) => {
|
|
||||||
return Err(ShellError::labeled_error(
|
|
||||||
format!(
|
|
||||||
"Rename {:?} to {:?} aborted. {:}",
|
|
||||||
entry_file_name,
|
|
||||||
destination_file_name,
|
|
||||||
e.to_string(),
|
|
||||||
),
|
|
||||||
format!(
|
|
||||||
"Rename {:?} to {:?} aborted. {:}",
|
|
||||||
entry_file_name,
|
|
||||||
destination_file_name,
|
|
||||||
e.to_string(),
|
|
||||||
),
|
|
||||||
name_tag,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Ok(_) => match std::fs::remove_file(&entry) {
|
|
||||||
Err(e) => {
|
|
||||||
return Err(ShellError::labeled_error(
|
|
||||||
format!(
|
|
||||||
"Remove {:?} to {:?} aborted. {:}",
|
|
||||||
entry_file_name,
|
|
||||||
destination_file_name,
|
|
||||||
e.to_string(),
|
|
||||||
),
|
|
||||||
format!(
|
|
||||||
"Remove {:?} to {:?} aborted. {:}",
|
|
||||||
entry_file_name,
|
|
||||||
destination_file_name,
|
|
||||||
e.to_string(),
|
|
||||||
),
|
|
||||||
name_tag,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Ok(o) => o,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return Err(ShellError::labeled_error(
|
|
||||||
format!("Rename aborted. (Does {:?} exist?)", destination_file_name),
|
|
||||||
format!("Rename aborted. (Does {:?} exist?)", destination_file_name),
|
|
||||||
dst.tag(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return Err(ShellError::labeled_error(
|
||||||
|
format!("Rename aborted. (Does {:?} exist?)", destination_file_name),
|
||||||
|
format!("Rename aborted. (Does {:?} exist?)", destination_file_name),
|
||||||
|
dst.tag(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(OutputStream::empty())
|
Ok(OutputStream::empty())
|
||||||
|
|
|
@ -79,12 +79,12 @@ impl HelpShell {
|
||||||
for p in full_path.iter() {
|
for p in full_path.iter() {
|
||||||
match p {
|
match p {
|
||||||
x if x == sep => {}
|
x if x == sep => {}
|
||||||
step => match viewed.get_data_by_key(step.to_str().unwrap().spanned_unknown()) {
|
step => {
|
||||||
Some(v) => {
|
let value = viewed.get_data_by_key(step.to_str().unwrap().spanned_unknown());
|
||||||
|
if let Some(v) = value {
|
||||||
viewed = v.clone();
|
viewed = v.clone();
|
||||||
}
|
}
|
||||||
_ => {}
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match viewed {
|
match viewed {
|
||||||
|
|
|
@ -43,12 +43,12 @@ impl ValueShell {
|
||||||
for p in full_path.iter() {
|
for p in full_path.iter() {
|
||||||
match p {
|
match p {
|
||||||
x if x == sep => {}
|
x if x == sep => {}
|
||||||
step => match viewed.get_data_by_key(step.to_str().unwrap().spanned_unknown()) {
|
step => {
|
||||||
Some(v) => {
|
let value = viewed.get_data_by_key(step.to_str().unwrap().spanned_unknown());
|
||||||
|
if let Some(v) = value {
|
||||||
viewed = v.clone();
|
viewed = v.clone();
|
||||||
}
|
}
|
||||||
_ => {}
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match viewed {
|
match viewed {
|
||||||
|
@ -96,9 +96,8 @@ impl Shell for ValueShell {
|
||||||
let mut full_path = PathBuf::from(self.path());
|
let mut full_path = PathBuf::from(self.path());
|
||||||
let name_tag = context.name.clone();
|
let name_tag = context.name.clone();
|
||||||
|
|
||||||
match &target {
|
if let Some(value) = &target {
|
||||||
Some(value) => full_path.push(value.as_ref()),
|
full_path.push(value.as_ref());
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut value_system = ValueStructure::new();
|
let mut value_system = ValueStructure::new();
|
||||||
|
|
Loading…
Reference in a new issue