kondo icon indicating copy to clipboard operation
kondo copied to clipboard

CLI option to print artifact dirs in plaintext

Open tbillington opened this issue 5 years ago • 9 comments

Reddit user bcgroom mentioned a flag to output just a plain text line separated list of artifact directories. That way it could be passed/manipulated by other programs.

tbillington avatar Jan 28 '20 02:01 tbillington

implemented with -a CLI flag

tbillington avatar Feb 29 '20 00:02 tbillington

Hi @tbillington 👋 Thanks for this awesome tool :-)

Can we reopen this? I think the -a/--all flag doesn't quite cover the use case that bcgroom mentioned:

$ kondo --all ~/…
/Users/…/… Node project
  └─ node_modules (2.3MiB)
  deleted 2.3MiB

Projects cleaned: 1, Bytes deleted: 2.3MiB

True, it does output the directory path, but only in combination with the type, and with actually removing the data. It seems more like a --force mode.

However, for "pass[ing to] other programs" something more like a --dry-run or --list-paths option would be nice. I imagine that this would be useful for example to populate a backup exclusion list.

katrinleinweber avatar Jan 05 '22 14:01 katrinleinweber

It got removed in https://github.com/tbillington/kondo/commit/7e76b65c472202fb2141177ae55ec95c7222e0cc, so the -a referenced in this issue is a different flag to the one that currently exists.

I do think it's something that should exist though, I'll look at adding it back in. Kondo also used to support an "exec" where you could get kondo to spawn commands/processes for each project/artifact dir but it is harder to support properly than one might imagine so I removed it.

There is a question around the output. Do you only list artifact directories, do you also list the project folder, do you list the project type somewhere? With a JSON output all of that would be probably fine, but if it's just outputting plain text stream it might need to be restricted to just newline separated artifact dirs of all projects found.

Did you have any example use cases in mind to help guide an implementation?

Thanks for bringing this up btw 😃

tbillington avatar Jan 06 '22 01:01 tbillington

only list artifact directories, do you also list the project folder,

The former would be more useful, IMHO, because the artifact directory is the one that is emptied. If a project folder has multiple, they can always be grouped to highlight that fact.

… list the project type somewhere?

Why not, as long as a separator that wouldn't be a valid symbol in a path is used. Any kind of --dry-run or --list-paths option would be more important than the formatting details.

A usecase would be to build a list of exclude patterns, for example for BorgBackup. I mostly use tmignore, however.

katrinleinweber avatar Jan 10 '22 17:01 katrinleinweber

Looking forward to adding --recursive and --dry-run options

hustcer avatar Apr 01 '24 05:04 hustcer

@hustcer kondo is recursive by default. But yes dry run would be helpful. It's not 100% necessary because it won't do anything until you tell it what to do, so dry run is a little less necessary.

The alternate I had in mind was more of a "discovery" command that would list all the projects, types, and sizes without taking any action.

What would you use dry run for ?

tbillington avatar Apr 01 '24 11:04 tbillington

kondo is recursive by default.

I don't think so, or maybe a bug? Look at the image below: Screenshot 2024-04-01 at 19 53 03

What would you use dry run for ?

If the recursive works as expected, I want't to scan all the sub directories and to see if there is any dir need to be cleaned: I don't want to stop and make a choice for each inquiry.

The alternate I had in mind was more of a "discovery" command that would list all the projects, types, and sizes without taking any action.

Great, that should work for my case.

hustcer avatar Apr 01 '24 11:04 hustcer

@hustcer

Look at the image below:

I should have been more specific, kondo is fully recursive by default (uses walkdir under the hood), however it doesn't recurse inside a found project #29 #55 #117 . I am loosely working on a rework in the background to address it, perhaps see if the description here addresses your use case.

If the recursive works as expected, I want't to scan all the sub directories and to see if there is any dir need to be cleaned: I don't want to stop and make a choice for each inquiry.

To make sure I understand fully, instead of wanting to make a choice at each project, you want to do a dry run that lists everything, then (if you're okay with the output) run kondo again without dry run or interactive mode ?

Aside: there is the -a, --all flag currently which will automatically accept cleaning every found directory.

tbillington avatar Apr 02 '24 00:04 tbillington

To make sure I understand fully, instead of wanting to make a choice at each project, you want to do a dry run that lists everything, then (if you're okay with the output) run kondo again without dry run or interactive mode ?

Yes, exactly

I am loosely working on a rework in the background to address it, perhaps see if the https://github.com/tbillington/kondo/issues/111 addresses your use case.

I have read #111 carefully, I think this feature fulfills my needs, I have just subscribed that issue.

Thanks for the detailed response 👍

hustcer avatar Apr 02 '24 01:04 hustcer