Quellcode durchsuchen

fix(cli): list inside working dir with `--list-dirs` and no path passed

Before, it just displayed `.` as if `.` was passed explicitely on the cli.
ariasuni vor 9 Monaten
Ursprung
Commit
7910ef719c
1 geänderte Dateien mit 11 neuen und 1 gelöschten Zeilen
  1. 11 1
      src/main.rs

+ 11 - 1
src/main.rs

@@ -65,12 +65,15 @@ fn main() {
     let args: Vec<_> = env::args_os().skip(1).collect();
     match Options::parse(args.iter().map(std::convert::AsRef::as_ref), &LiveVars) {
         OptionsResult::Ok(options, mut input_paths) => {
+            let mut default_input_path = false;
+
             // List the current directory by default.
             // (This has to be done here, otherwise git_options won’t see it.)
             if input_paths.is_empty() {
                 match &options.stdin {
                     FilesInput::Args => {
                         input_paths = vec![OsStr::new(".")];
+                        default_input_path = true;
                     }
                     FilesInput::Stdin(separator) => {
                         stdin()
@@ -97,6 +100,7 @@ fn main() {
                 options,
                 writer,
                 input_paths,
+                default_input_path,
                 theme,
                 console_width,
                 git,
@@ -155,6 +159,10 @@ pub struct Exa<'args> {
     /// names (anything that isn’t an option).
     pub input_paths: Vec<&'args OsStr>,
 
+    /// If no path has been passed through with the command line, and the
+    /// `input_paths` field has been filled with "." by default
+    pub default_input_path: bool,
+
     /// The theme that has been configured from the command-line options and
     /// environment variables. If colours are disabled, this is a theme with
     /// every style set to the default.
@@ -277,7 +285,9 @@ impl<'args> Exa<'args> {
                 continue;
             }
 
-            if f.points_to_directory() && !self.options.dir_action.treat_dirs_as_files() {
+            if f.points_to_directory()
+                && (self.default_input_path || !self.options.dir_action.treat_dirs_as_files())
+            {
                 trace!("matching on to_dir");
                 match f.to_dir() {
                     Ok(d) => dirs.push(d),