Skip to content

add list-files command #199

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

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Commands:
download Download last version of Mergin Maps project
download-file Download project file at specified version.
list-projects List projects on the server
list-files List files in a project
login Login to the service and see how to set the token...
pull Fetch changes from Mergin Maps repository
push Upload local changes into Mergin Maps repository
Expand Down
21 changes: 21 additions & 0 deletions mergin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,27 @@ def reset(ctx):
except Exception as e:
_print_unhandled_exception()

@cli.command()
@click.argument("project")
@click.option("--json", is_flag=True, default=False, help="Output in JSON format")
@click.pass_context
def list_files(ctx, project, json):
"""List files in a project."""

mc = ctx.obj["client"]
if mc is None:
return

project_info = mc.project_info(project)
project_files = project_info["files"]

if json:
print(project_files)
else:
click.echo("Fetched {} files .".format(len(project_files)))
for file in project_files:
click.echo(" {:40}\t{:6.1f} MB".format(file['path'], file["size"] / (1024 * 1024)))


if __name__ == "__main__":
cli()