在任意树中运行git ls tree以方便使用

git-ls-anytree的Python项目详细描述


https://badge.fury.io/py/git-ls-anytree.svghttps://travis-ci.org/wizardsoftheweb/git-ls-anytree.svg?branch=masterhttps://coveralls.io/repos/github/wizardsoftheweb/git-ls-anytree/badge.svg?branch=master

^{tt1}$

git-ls-anytreegittree(ish)s提供类似tree的输出。

v1之前,当我添加更多选项并简化现有的内容时,api可能会略有变化。

Overview

git-ls-treeman)是查看树内容的一个很好的小工具(ish)。它的工作方式类似于ls,其中每一行包含您需要的所有信息,而这些行并没有真正连接起来。treeman)是一个极好的cli添加,它将可视上下文添加到目录信息中。anytreepackage)是一个伟大的python工具,它在抽象树上实现来自tree的视觉提示。

git-ls-anytree是我尝试将所有这些整洁的东西连接在一起的。我构建它主要是为了在python代码中使用,但是添加cli支持非常有趣。

Installation

$ pip install --user git-ls-anytree
# or whatever; the number of ways to install things is fairly large

Quick Examples

^{tt7}$ (baseline)

$ git ls-tree -rtl --abbrev HEAD
100644 blob b2b0820     184     .editorconfig
100644 blob 9744e3b    1291     .gitignore
100644 blob af55cdb     230     .travis.yml
100644 blob 93bb548     724     LICENSE.rst
100644 blob 5d22467     132     MANIFEST.in
100644 blob 1670bfb    1830     README.rst
040000 tree 4d2dd1d       -     git_ls_anytree
100644 blob 0c62199       6     git_ls_anytree/VERSION
100644 blob ee53f20     243     git_ls_anytree/__init__.py
100644 blob 626d501      33     git_ls_anytree/__main__.py
100644 blob 5cc512a     259     git_ls_anytree/__version__.py
100644 blob c23d837    2844     git_ls_anytree/cli_file.py
100644 blob a90da6c     356     git_ls_anytree/convert_path_to_list.py
100644 blob f6485bf    4235     git_ls_anytree/git_ls_tree.py
100644 blob a73aeb4    4584     git_ls_anytree/git_ls_tree_node.py
100644 blob b14931a     648     git_ls_anytree/local_exceptions.py
100644 blob 55f8a08     427     setup.cfg
100644 blob 823c34b     321     setup.py
040000 tree c8d53d3       -     tests
100644 blob a941a90     953     tests/test_cli.py
100644 blob eb2a9dd     609     tests/test_convert_path_to_list.py
100644 blob dc7c7a9   13337     tests/test_git_ls_tree.py
100644 blob b96675d    5709     tests/test_git_ls_tree_node.py
100644 blob 9a60bad     182     tests/test_main.py
100644 blob c5389bc     152     tox.ini

^{tt8}$ (default)

$ git ls-anytree HEAD --abbrev
mode    type    object   size   HEAD
100644  blob    b2b0820   184   ├── .editorconfig
100644  blob    9744e3b  1291   ├── .gitignore
100644  blob    af55cdb   230   ├── .travis.yml
100644  blob    93bb548   724   ├── LICENSE.rst
100644  blob    5d22467   132   ├── MANIFEST.in
100644  blob    1670bfb  1830   ├── README.rst
040000  tree    4d2dd1d     -   ├── git_ls_anytree
100644  blob    0c62199     6   │   ├── VERSION
100644  blob    ee53f20   243   │   ├── __init__.py
100644  blob    626d501    33   │   ├── __main__.py
100644  blob    5cc512a   259   │   ├── __version__.py
100644  blob    c23d837  2844   │   ├── cli_file.py
100644  blob    a90da6c   356   │   ├── convert_path_to_list.py
100644  blob    f6485bf  4235   │   ├── git_ls_tree.py
100644  blob    a73aeb4  4584   │   ├── git_ls_tree_node.py
100644  blob    b14931a   648   │   └── local_exceptions.py
100644  blob    55f8a08   427   ├── setup.cfg
100644  blob    823c34b   321   ├── setup.py
040000  tree    c8d53d3     -   ├── tests
100644  blob    a941a90   953   │   ├── test_cli.py
100644  blob    eb2a9dd   609   │   ├── test_convert_path_to_list.py
100644  blob    dc7c7a9 13337   │   ├── test_git_ls_tree.py
100644  blob    b96675d  5709   │   ├── test_git_ls_tree_node.py
100644  blob    9a60bad   182   │   └── test_main.py
100644  blob    c5389bc   152   └── tox.ini

^{tt8}$ (tree only)

$ git ls-anytree --name-only
HEAD
├── .editorconfig
├── .gitignore
├── .travis.yml
├── LICENSE.rst
├── MANIFEST.in
├── README.rst
├── git_ls_anytree
│   ├── VERSION
│   ├── __init__.py
│   ├── __main__.py
│   ├── __version__.py
│   ├── cli_file.py
│   ├── convert_path_to_list.py
│   ├── git_ls_tree.py
│   ├── git_ls_tree_node.py
│   └── local_exceptions.py
├── setup.cfg
├── setup.py
├── tests
│   ├── test_cli.py
│   ├── test_convert_path_to_list.py
│   ├── test_git_ls_tree.py
│   ├── test_git_ls_tree_node.py
│   └── test_main.py
└── tox.ini

Usage

CLI

通过pip安装应该将可执行文件添加到PATH(如果使用--user,则可能需要首先将$HOME/.local/bin添加到PATH

$ which git-ls-anytree
/home/user/.local/bin/git-ls-anytree

这应该用git注册,您可以用git help -a

$ git help -a | grep 'ls-anytree' > /dev/null || echo 'whoops'

这意味着您可以通过git-ls-anytreegit ls-anytree调用它。

目前,要访问帮助,您必须使用以下选项之一:

$ git ls-anytree -h
$ git-ls-anytree --help

包没有安装man页,因此运行git ls-anytree--help时,git找不到任何帮助。

Options
usage: git-ls-anytree [-h] [-v] [-w WORKING_DIRECTORY] [--name-only]
                  [--abbrev | --abbrev-n ABBREV] [-d] [-F] [--dirsfirst]
                  [tree-ish] [patterns [patterns ...]]

Python tool to pretty-print git-ls-tree

positional arguments:
  tree-ish              Reference to tree-ish. Defaults to HEAD
  patterns              Subtrees within the main tree-ish

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -w WORKING_DIRECTORY, --working-directory WORKING_DIRECTORY
                        The directory to use for the git commands. Defaults to
                        cwd (/mnt/c/Users/thecj/Code/@wizardsoftheweb/git_ls_a
                        nytree)

Inherited git-ls-tree arguments:
  --name-only, --name-status
                        Only print the tree structure per git-ls-tree
                        --name-(only|status)
  --abbrev              Equivalent to git-ls-tree --abbrev. Uses the default
                        git short hash of seven characters.
  --abbrev-n ABBREV     Sets the git object abbreviation per git-ls-tree
                        --abbrev=n
  -d, --trees-only      Only print trees per git-ls-tree -d

Inherited tree arguments:
  -F, --classify        Appends ( *@/) to filename per ls -F
  --dirsfirst           Displays directories (tree, commit) before files
                        (blob)

Due to known issues with nargs='?' consuming positionals under the right
circumstances, --abbrev[=n] was split into --abbrev, for the default, and
--abbrev-n INT, to specify a level.

^{tt10}$

查看cli_file.pysource)的最后一行,了解一个简单的用法示例:

...
args = parser.parse_args(passed_args)

full_tree = GitLsTree(
    tree_ish=args.tree_ish,
    patterns=args.patterns,
    trees_only=args.trees_only,
    working_dir=args.working_directory,
    abbrev=args.abbrev if hasattr(args, 'abbrev') else None,
    item_sort=args.item_sort
)
full_tree.pretty_print(
    name_only=args.name_only,
    classify=args.classify
)

稍后再来。

Roadmap

这些都是我想在标记v1之前完成的事情。

  • 生成并安装man
  • 编译文档
  • 测试文档
  • 清理tests
  • 编码气候,猎犬,某种自然的东西
  • 重构pylint重构问题

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何定制springdata存储库方法名称?   html有没有办法将java应用程序或JApplet嵌入到网站中?   Jackson ObjectMapper将java从字符串序列化为JSON作为namevalue   java刷新JTable?   用Java程序分发用JavaDB制作的数据库   java Android如何启动新活动   当集合大小超过500.000时,java的处理速度会显著降低   在java的分层目录中的多个目录中查找相同的文件   java如何将ArrayList数据插入数据库   java如何修改此代码,使其时间复杂度为o(logn)或o(n),而不是o(n^2)   java面板(SimplePanel)中仅显示图像的前1/3(大约),   jakarta ee Java Bean和企业Java Bean之间的区别?   创建AWS Cloudfront自签名URL(java sdk)时出现amazon web服务错误   基于Jersey和Jackson查询参数的java动态属性过滤