Change f/full flag to l/long for ls and ps commands (#2283)

* Change `f`/`full` flag to `l`/`long` for `ls` and `ps` commands

* Fix a few more `--full` instances
This commit is contained in:
Joseph T. Lyons 2020-08-01 14:30:45 -04:00 committed by GitHub
parent 4ef15b5f80
commit 9fb6f5cd09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 34 additions and 33 deletions

View File

@ -49,7 +49,7 @@ impl WholeStreamCommand for Compact {
}, },
Example { Example {
description: "Filter out all directory entries having no 'target'", description: "Filter out all directory entries having no 'target'",
example: "ls -af | compact target", example: "ls -la | compact target",
result: None, result: None,
}, },
] ]

View File

@ -45,7 +45,7 @@ impl WholeStreamCommand for Default {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Give a default 'target' to all file entries", description: "Give a default 'target' to all file entries",
example: "ls -af | default target 'nothing'", example: "ls -la | default target 'nothing'",
result: None, result: None,
}] }]
} }

View File

@ -11,7 +11,7 @@ pub struct Ls;
pub struct LsArgs { pub struct LsArgs {
pub path: Option<Tagged<PathBuf>>, pub path: Option<Tagged<PathBuf>>,
pub all: bool, pub all: bool,
pub full: bool, pub long: bool,
#[serde(rename = "short-names")] #[serde(rename = "short-names")]
pub short_names: bool, pub short_names: bool,
#[serde(rename = "with-symlink-targets")] #[serde(rename = "with-symlink-targets")]
@ -33,25 +33,26 @@ impl WholeStreamCommand for Ls {
SyntaxShape::Pattern, SyntaxShape::Pattern,
"a path to get the directory contents from", "a path to get the directory contents from",
) )
.switch("all", "also show hidden files", Some('a')) .switch("all", "Show hidden files", Some('a'))
.switch( .switch(
"full", "long",
"list all available columns for each entry", "List all available columns for each entry",
Some('f'), Some('l'),
) )
.switch( .switch(
"short-names", "short-names",
"only print the file names and not the path", "Only print the file names and not the path",
Some('s'), Some('s'),
) )
.switch( .switch(
// Delete this
"with-symlink-targets", "with-symlink-targets",
"display the paths to the target files that symlinks point to", "Display the paths to the target files that symlinks point to",
Some('w'), Some('w'),
) )
.switch( .switch(
"du", "du",
"display the apparent directory size in place of the directory metadata size", "Display the apparent directory size in place of the directory metadata size",
Some('d'), Some('d'),
) )
} }

View File

@ -37,7 +37,7 @@ pub(crate) fn dir_entry_dict(
filename: &std::path::Path, filename: &std::path::Path,
metadata: Option<&std::fs::Metadata>, metadata: Option<&std::fs::Metadata>,
tag: impl Into<Tag>, tag: impl Into<Tag>,
full: bool, long: bool,
short_name: bool, short_name: bool,
with_symlink_targets: bool, with_symlink_targets: bool,
du: bool, du: bool,
@ -46,7 +46,7 @@ pub(crate) fn dir_entry_dict(
let tag = tag.into(); let tag = tag.into();
let mut dict = TaggedDictBuilder::new(&tag); let mut dict = TaggedDictBuilder::new(&tag);
// Insert all columns first to maintain proper table alignment if we can't find (or are not allowed to view) any information // Insert all columns first to maintain proper table alignment if we can't find (or are not allowed to view) any information
if full { if long {
#[cfg(windows)] #[cfg(windows)]
{ {
for column in [ for column in [
@ -97,7 +97,7 @@ pub(crate) fn dir_entry_dict(
dict.insert_untagged("type", get_file_type(md)); dict.insert_untagged("type", get_file_type(md));
} }
if full || with_symlink_targets { if long || with_symlink_targets {
if let Some(md) = metadata { if let Some(md) = metadata {
if md.file_type().is_symlink() { if md.file_type().is_symlink() {
let symlink_target_untagged_value: UntaggedValue; let symlink_target_untagged_value: UntaggedValue;
@ -113,7 +113,7 @@ pub(crate) fn dir_entry_dict(
} }
} }
if full { if long {
if let Some(md) = metadata { if let Some(md) = metadata {
dict.insert_untagged( dict.insert_untagged(
"readonly", "readonly",
@ -181,7 +181,7 @@ pub(crate) fn dir_entry_dict(
} }
if let Some(md) = metadata { if let Some(md) = metadata {
if full { if long {
if let Ok(c) = md.created() { if let Ok(c) = md.created() {
dict.insert_untagged("created", UntaggedValue::system_date(c)); dict.insert_untagged("created", UntaggedValue::system_date(c));
} }

View File

@ -95,7 +95,7 @@ impl Shell for FilesystemShell {
LsArgs { LsArgs {
path, path,
all, all,
full, long,
short_names, short_names,
with_symlink_targets, with_symlink_targets,
du, du,
@ -164,7 +164,7 @@ impl Shell for FilesystemShell {
&path, &path,
metadata.as_ref(), metadata.as_ref(),
name_tag.clone(), name_tag.clone(),
full, long,
short_names, short_names,
with_symlink_targets, with_symlink_targets,
du, du,

View File

@ -180,10 +180,10 @@ fn list_all_columns() {
); );
let expected = ["name", "type", "target", "size", "modified"].join(""); let expected = ["name", "type", "target", "size", "modified"].join("");
assert_eq!(actual.out, expected, "column names are incorrect for ls -w"); assert_eq!(actual.out, expected, "column names are incorrect for ls -w");
// Full // Long
let actual = nu!( let actual = nu!(
cwd: dirs.test(), cwd: dirs.test(),
"ls -f | get | to md" "ls -l | get | to md"
); );
let expected = { let expected = {
#[cfg(unix)] #[cfg(unix)]
@ -206,7 +206,7 @@ fn list_all_columns() {
}; };
assert_eq!( assert_eq!(
actual.out, expected, actual.out, expected,
"column names are incorrect for ls full" "column names are incorrect for ls long"
); );
}, },
); );

View File

@ -805,8 +805,8 @@ mod test {
} }
} }
/// Match the available flags in a signature with what the user provided. This will check both long-form flags (--full) and shorthand flags (-f) /// Match the available flags in a signature with what the user provided. This will check both long-form flags (--long) and shorthand flags (-l)
/// This also allows users to provide a group of shorthand flags (-af) that correspond to multiple shorthand flags at once. /// This also allows users to provide a group of shorthand flags (-la) that correspond to multiple shorthand flags at once.
fn get_flags_from_flag( fn get_flags_from_flag(
signature: &nu_protocol::Signature, signature: &nu_protocol::Signature,
cmd: &Spanned<String>, cmd: &Spanned<String>,

View File

@ -10,15 +10,15 @@ impl Plugin for Ps {
Ok(Signature::build("ps") Ok(Signature::build("ps")
.desc("View information about system processes.") .desc("View information about system processes.")
.switch( .switch(
"full", "long",
"list all available columns for each entry", "list all available columns for each entry",
Some('f'), Some('l'),
) )
.filter()) .filter())
} }
fn begin_filter(&mut self, callinfo: CallInfo) -> Result<Vec<ReturnValue>, ShellError> { fn begin_filter(&mut self, callinfo: CallInfo) -> Result<Vec<ReturnValue>, ShellError> {
Ok(block_on(ps(callinfo.name_tag, callinfo.args.has("full")))? Ok(block_on(ps(callinfo.name_tag, callinfo.args.has("long")))?
.into_iter() .into_iter()
.map(ReturnSuccess::value) .map(ReturnSuccess::value)
.collect()) .collect())

View File

@ -28,7 +28,7 @@ async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio, proc
Ok((process, usage_2 - usage_1, memory)) Ok((process, usage_2 - usage_1, memory))
} }
pub async fn ps(tag: Tag, full: bool) -> Result<Vec<Value>, ShellError> { pub async fn ps(tag: Tag, long: bool) -> Result<Vec<Value>, ShellError> {
let processes = process::processes() let processes = process::processes()
.await .await
.map_err(|_| { .map_err(|_| {
@ -67,7 +67,7 @@ pub async fn ps(tag: Tag, full: bool) -> Result<Vec<Value>, ShellError> {
"virtual", "virtual",
UntaggedValue::filesize(memory.vms().get::<information::byte>()), UntaggedValue::filesize(memory.vms().get::<information::byte>()),
); );
if full { if long {
if let Ok(parent_pid) = process.parent_pid().await { if let Ok(parent_pid) = process.parent_pid().await {
dict.insert_untagged("parent", UntaggedValue::int(parent_pid)) dict.insert_untagged("parent", UntaggedValue::int(parent_pid))
} }

View File

@ -81,7 +81,7 @@ We can also set the name of the second column or sort the table:
Of course, histogram operations are not restricted to just analyzing numbers in files, you can also analyze your directories Of course, histogram operations are not restricted to just analyzing numbers in files, you can also analyze your directories
```shell ```shell
> ls -fa | histogram type | sort-by count > ls -la | histogram type | sort-by count
───┬─────────┬───────┬────────────────────────────────────────────────────────────────────────────────────────────────────── ───┬─────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
# │ type │ count │ frequency # │ type │ count │ frequency
───┼─────────┼───────┼────────────────────────────────────────────────────────────────────────────────────────────────────── ───┼─────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────

View File

@ -12,6 +12,6 @@ Displays the last 100 commands.
... ...
97 │ date 97 │ date
98 │ ls 98 │ ls
99 │ ls -fa 99 │ ls -la
─────┴──────────────────────────────────────────────────────────────────────── ─────┴────────────────────────────────────────────────────────────────────────
``` ```

View File

@ -35,7 +35,7 @@ Dates can also be compared using the duration types. For example, `where accesse
## Boolean check ## Boolean check
Where with the form `| where readonly` is used to check boolean values. For example, the command `ls --full | where readonly` will list only those files that are readonly. Where with the form `| where readonly` is used to check boolean values. For example, the command `ls --long | where readonly` will list only those files that are readonly.
## Usage ## Usage
@ -76,7 +76,7 @@ Where with the form `| where readonly` is used to check boolean values. For exam
``` ```
```shell ```shell
> ls -f | where accessed <= 1w > ls -l | where accessed <= 1w
───┬────────────────────┬──────┬────────┬──────────┬───────────┬─────────────┬───────┬──────────┬──────────────┬─────────────┬───────────── ───┬────────────────────┬──────┬────────┬──────────┬───────────┬─────────────┬───────┬──────────┬──────────────┬─────────────┬─────────────
# │ name │ type │ target │ readonly │ mode │ uid │ group │ size │ created │ accessed │ modified # │ name │ type │ target │ readonly │ mode │ uid │ group │ size │ created │ accessed │ modified
───┼────────────────────┼──────┼────────┼──────────┼───────────┼─────────────┼───────┼──────────┼──────────────┼─────────────┼───────────── ───┼────────────────────┼──────┼────────┼──────────┼───────────┼─────────────┼───────┼──────────┼──────────────┼─────────────┼─────────────

View File

@ -3,7 +3,7 @@ header_align = "l"
header_color = "c" header_color = "c"
header_bold = true header_bold = true
nonzero_exit_errors = true nonzero_exit_errors = true
startup = ["alias la [path] {ls --full $path}", "alias nudown [] {fetch https://api.github.com/repos/nushell/nushell/releases | get assets | select name download_count}"] startup = ["alias la [path] {ls --long $path}", "alias nudown [] {fetch https://api.github.com/repos/nushell/nushell/releases | get assets | select name download_count}"]
table_mode = "other" table_mode = "other"
plugin_dirs = ["D:\\Src\\GitHub\\nu-plugin-lib\\samples\\Nu.Plugin.Len\\bin\\Debug\\netcoreapp3.1"] plugin_dirs = ["D:\\Src\\GitHub\\nu-plugin-lib\\samples\\Nu.Plugin.Len\\bin\\Debug\\netcoreapp3.1"]
pivot_mode = "auto" pivot_mode = "auto"