Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search or count for multiple extensions #92

Open
victordomingos opened this issue Sep 18, 2018 · 8 comments
Open

Search or count for multiple extensions #92

victordomingos opened this issue Sep 18, 2018 · 8 comments

Comments

@victordomingos
Copy link
Owner

  • search or count for multiple extensions: count-files --multi-exensions txt py

Originally posted by @NataliaBondarenko in #84 (comment)

@victordomingos
Copy link
Owner Author

How can we configure argparse to read a variable number of parameters (file extensions)?

@NataliaBondarenko
Copy link
Collaborator

I think this can be done for the table: add another parameter.

def count_files_by_extension():
    counters = Counter()
    dirpath = os.path.expanduser(dirpath)

    def count_file_extensions(files: Iterable[str], no_feedback: bool = no_feedback):
        for f in files:
            extension = get_file_extension(f, case_sensitive=case_sensitive)
            # if extension-list:
            #    ext = extension if case_sensitive else extension.upper()
            #        if ext not in extension-list:
            #            continue
            ext = extension if case_sensitive else extension.upper()
            if ext not in ['PY', 'MD']:
                continue
            if extension == '.':
                extension = '[no extension]'
            counters[extension] += 1
            if not no_feedback:
                print("\r"+os.path.basename(f)[:TERM_WIDTH-1].ljust(TERM_WIDTH-1), end="")
. . .

or take a counter with all extensions and display only the required extensions

@NataliaBondarenko
Copy link
Collaborator

It is also possible to limit the number of extensions in the list.

parser.add_argument('--extension-list', nargs=5)

@victordomingos
Copy link
Owner Author

I am afraid that this kind of changes may turn our CLI user interface more difficult to use. Do you know of some other utility that implements arguments with a variable number of values/parameters like we are envisioning now, in a nice way?

@NataliaBondarenko
Copy link
Collaborator

there is one for PowerShell:
get_item

@victordomingos
Copy link
Owner Author

In this case, they use the -Path argument to help distinguish a path from a file extension. We would probably need to add it also (something like count-files -path PATH), instead of allowing a simple count-files PATH, right? Or is there any other option?

@NataliaBondarenko
Copy link
Collaborator

count-files -path PATH Yes, it is necessary to add - so it will be clearer.

@victordomingos
Copy link
Owner Author

Well, I really liked that way we were able to do a quick count by using count-files FOLDER_PATH. If feels strange being forced to add that -path.

Also, I would rather prefer a single-character shortcut. Since we already have a -p for preview, it could be -i (input), -s (source), -l (location).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants