Skip to content

Commit

Permalink
(#2) add a "manifest" command that emits JSON records
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshKarpel committed Feb 26, 2020
1 parent 333a773 commit 2ffbc8a
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions globus.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import datetime
import functools
import pprint
import json

import click
from click_didyoumean import DYMGroup
Expand Down Expand Up @@ -39,7 +40,11 @@

@click.group(context_settings=CONTEXT_SETTINGS, cls=DYMGroup)
@click.option(
"--verbose", "-v", count=True, default=0, help="Show log messages as the CLI runs."
"--verbose",
"-v",
count=True,
default=0,
help="Show log messages as the CLI runs. Pass more times for more verbosity.",
)
@click.pass_context
def cli(context, verbose):
Expand Down Expand Up @@ -282,6 +287,37 @@ def ls(settings, endpoint, path):
)


@cli.command()
@endpoint_arg("endpoint")
@click.option(
"--path",
type=str,
default="~/",
help="The path to list the contents of. Defaults to '~/'.",
)
@click.option(
"--verbose/--compact",
default=True,
help="Whether the JSON representation should be verbose or compact. The default is verbose.",
)
@click.pass_obj
def manifest(settings, endpoint, path, verbose):
"""
Print a JSON manifest of directory contents on an endpoint.
"""
if verbose:
json_dumps_kwargs = dict(indent=2)
else:
json_dumps_kwargs = dict(indent=None, separators=(",", ":"))

tc = get_transfer_client_or_exit(settings[AUTH].get(REFRESH_TOKEN))

activate_endpoint_or_exit(tc, endpoint)

entries = list(tc.operation_ls(endpoint, path=path))
click.echo(json.dumps(entries, **json_dumps_kwargs))


@cli.command()
@endpoint_arg("endpoint")
@click.pass_obj
Expand Down Expand Up @@ -604,7 +640,7 @@ def activate_endpoint_manually(transfer_client, endpoint):
click.echo(
f"Endpoint requires manual activation, please open the following URL in a browser to activate the endpoint: https://app.globus.org/file-manager?{query_string}"
)
click.confirm("Press ENTER after activating the endpoint...")
click.confirm("Press ENTER after activating the endpoint...", show_default=False)
return EndpointInfo.get(transfer_client, endpoint).is_active


Expand Down

0 comments on commit 2ffbc8a

Please sign in to comment.