Giter Club home page Giter Club logo

tree-cli's Introduction

tree-cli

CircleCI npm version downloads

List contents of directories in tree-like format.

Tree-cli is a recursive directory listing program that produces a depth indented listing of files. With no arguments, tree lists the files in the current directory. When directory arguments are given, tree lists all the files and/or directories found in the given directories each in turn. Upon completion of listing all files/directories found, tree returns the total number of files and/or directories listed.

example

cmd:

tree -l 2 -o output.txt

result:

/Applications/XAMPP/htdocs/node_playground/tree-cli
β”œβ”€β”€ README.md
β”œβ”€β”€ bin
|  └── tree
β”œβ”€β”€ node_modules
|  β”œβ”€β”€ bluebird
|  β”œβ”€β”€ chalk
|  β”œβ”€β”€ cli-spinner
|  β”œβ”€β”€ meow
|  └── object-assign
β”œβ”€β”€ package.json
└── tree.js

directory: 7 file: 4

install

npm install -g tree-cli

usage

Use the command tree or treee (to avoid confliction with system command).

NOTE: use treee instead of tree on windows system.

tree/treee

Use it as a node module to get the detailed tree data.

require('tree-cli')({
  base: '.',    // or any path you want to inspect.
  noreport: true
}).then(res => {
  // res.data is the data for the file tree.
  // res.report is the stringified scanning report.
  console.log(res.data, res.report);
});

You can find the type declaration for the exporting function and the type declaration of its' params and result in the 'types/index.d.ts' file. If you are using VSCode, you'll find the type hint during your typing.

Breaking change: In version before 0.6.0, the resovled result is the tree structure of the scanned directory. But in latest v0.6.0, the resolved result is changed to a object contains both the file tree structure and the scanned report. The structure of result would be:

{
  data: {
    // ...The file node tree.
  },
  report: '...',  // The final report.
}

use --help to list help info.

tree --help

specify the level of path (how deep to scan).

use -l levelNumber to specify the path level.

tree -l 2

output result to a file

use -o outputFilePath to specify the output file.

tree -l 2 -o out.txt

show directory only

use -d to show directories only.

tree -l 2 -o out.txt -d

other arguments

see Options.

FOR WINDOWS USERS

you should just use the treee command as tree has been already taken by windows system.

treee -l 2 -o out.txt -d

Options

  • --help: outputs a verbose usage listing.
  • --version: outputs the version of tree-cli.
  • --debug: show debug info.
  • --fullpath: prints the full path prefix for each file.
  • --ignore: ignores directory or file you specify - accepts arrays as comma-delimited strings: 'node_modules/, .git/, .gitignore'
  • --link: follows symbolic links if they point to directories, as if they were directories. Symbolic links that will result in recursion are avoided when detected.
  • --noreport: omits printing of the file and directory report at the end of the tree listing and omits printing the tree on console.
  • --base: specify a root directory. Relative path from cwd root and absolute path are both acceptable. This argument is optional.
  • -a: all files are printed. By default tree does not print hidden files (those beginning with a dot '.'). In no event does tree print the file system constructs '.' (current directory) and '..' (previous directory).
  • -d: list directories only.
  • -f: append a '/' for directories, a '=' for socket files and a '|' for FIFOs.
  • -i: makes tree not print the indentation lines, useful when used in conjunction with the -f option.
  • -l: max display depth of the directory tree.
  • -o: send output to filename.

tree-cli's People

Contributors

mrraindrop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tree-cli's Issues

Stringify output

Hello! Can you consider exporting the stringify function, or have some other wayto obtain the stringified output without having to shell out? e.g. accepting a buffer or stream to write into.

I am using this as a library (i.e. require-ing it) and am mainly interested in getting the string output, not the data structure itself.

--ignore does not work with nested folders

ignore command treee -l 10 --ignore "venv , app\tmp\__pycache__" not working , prints out everything. the folder structure works when only treee -l 10 --ignore venv is given.

constantly crashing on exception

This module is not working as supposed to, it crash and exit node application due to the error:
TypeError: Cannot read properties of undefined (reading 'sort')

tree.js:315:27

if (_flags.directoryFirst) {
          parent.children.sort(_comparePriority);
        }

the callback onError does nothing when exception occurred but instead it crash my application:

onError({path,err}){
       
}

tree-cli TODO

TODO:

  • bugfix
  • make it require-able
  • more command arguments for linux tree command
  • test cases

Suppress `console.log`

Can we have a way to suppress the console.log() output? As mentioned in #15, I am using this as a library to get the output.

Prebuilt binaries?

If someone wants to install tree-cli, they have to install npm, even if they have no need for that, besides installing tree-cli.

Would it be possible to provide prebuilt binaries?

Incorrect output with `--ignore`

When the last entry of the listing is filtered with --ignore , the actual non-filtered last output is displayed with β”œβ”€β”€ instead of └─

"Too many parameters" error on Windows

It doesn't seem to accept parameters when running on Windows:

> tree -L 2 -o out.txt
Too many parameters - 2

> tree -o tree.txt
Too many parameters - tree.txt

How to list ALL

It looks like you must specify the folder depth, any way to list all sub directories?

Debug log is printed by default

When I tree ./build, I get my log prepended by this:

[log] flags { debug: false,
  base: '.',
  indent: 2,
  fullpath: false,
  link: false,
  noreport: false,
  l: 1,
  o: 'tree_out',
  f: false }
[log] result:

I'd expect that not to be there when I'm not passing any debug flags.
My version of tree is 0.4.6, node version is 6.7.0.

The directory named "module" is missing

source directory structure

...
|-- build
|  |-- main
|  |-- module
...

tree-cli result

tree -l 2 -o tree.txt --ignore 'node_modules,coverage'

build/module directory is missing from the results.

feature_request(option): Markdown output

1. Summary

It would be nice, if would be possible print output to Markdown format.

2. Example data

Simple tree structure:

KiraTreeCLI/
β”œβ”€β”€ KiraDirectory/
β”‚   └── KiraSecondFile.txt
└── KiraFirstFile.txt

3. Expected result

# KiraTreeCLI

1. KiraFirstFile.txt

## KiraDirectory

1. KiraSecondFile.txt

4. Argumentation

I want to publish my big list of books, so that it can be conveniently referenced. For example, that would be possible show my Astronomy books to other users, I could share link https://kristinita.netlify.app/Special/Полная-библиография#Астрономия; Physics books β€” https://kristinita.netlify.app/Special/Полная-библиография#Π€ΠΈΠ·ΠΈΠΊΠ° and so on.

Yes, I know regular expressions. But currently, I have tree β†’ Markdown conversion difficulties, because I can’t do, that files would be higher than directories in output (KiraFirstFile.txt than KiraDirectory/).

5. Examples of expected behavior

5.1. Markdown format

It would be very nice, if tree-node-cli can print output in Markdown format directly. For example, if I will run command:

tree --markdown

I will get the expected result from section Β«Expected resultΒ»:

# KiraTreeCLI

1. KiraFirstFile.txt

## KiraDirectory

1. KiraSecondFile.txt

5.2. dirs-end

If you are for any reason will not do conversion to Markdown, it would be nice to have at least --dirs-end option. Files in this case will always be located above the directories.

  • Command:
tree --dirs-end
  • Result:
KiraTreeCLI/
β”œβ”€β”€ KiraFirstFile.txt
└── KiraDirectory/
    └── KiraSecondFile.txt

6. Not helped

I couldn’t find in Internet third-party tools for conversion filesystem tree structure to Markdown format.

7. Do not offer

I don’t need to convert filesystem tree structure to Markdown list; please, do not offer it. I need, that directories and subdirectories would be converted to Markdown headers; please, read section Β«ArgumentationΒ».

Thanks.

Available to be used as npm module

Are there any plans to make this available to use as a require-able node module? I'm looking for something similar to this for one of my projects and it'd be pretty awesome to be able to use in another node script :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.