Skip to content

Commit

Permalink
Add --recursive option to fs ls command
Browse files Browse the repository at this point in the history
  • Loading branch information
justinTM authored Jul 8, 2022
1 parent 0b6a78e commit fcc1c8e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions databricks_cli/dbfs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
@click.option('-l', is_flag=True, default=False,
help="""Displays full information including size, file type
and modification time since Epoch in milliseconds.""")
@click.option('--recursive', is_flag=True, default=False,
help='Displays all subdirectories and files.')
@click.argument('dbfs_path', nargs=-1, type=DbfsPathClickType())
@debug_option
@profile_option
Expand All @@ -53,10 +55,20 @@ def ls_cli(api_client, l, absolute, dbfs_path): # NOQA
dbfs_path = dbfs_path[0]
else:
error_and_quit('ls can take a maximum of one path.')
files = DbfsApi(api_client).list_files(dbfs_path)
table = tabulate([f.to_row(is_long_form=l, is_absolute=absolute) for f in files],
tablefmt='plain')
click.echo(table)

def echo_path(files):
table = tabulate([f.to_row(is_long_form=l, is_absolute=absolute) for f in files],
tablefmt='plain')
click.echo(table)

def recursive_echo(this_dbfs_path):
files = DbfsApi(api_client).list_files(this_dbfs_path)
echo_path(files)
for f in files:
if f.is_dir:
recursive_echo(this_dbfs_path.join(f.basename))

recursive_echo(dbfs_path) if recursive else echo_path(dbfs_path)


@click.command(context_settings=CONTEXT_SETTINGS)
Expand Down

0 comments on commit fcc1c8e

Please sign in to comment.