Skip to content

Commit fcc1c8e

Browse files
authored
Add --recursive option to fs ls command
1 parent 0b6a78e commit fcc1c8e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

databricks_cli/dbfs/cli.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
@click.option('-l', is_flag=True, default=False,
3939
help="""Displays full information including size, file type
4040
and modification time since Epoch in milliseconds.""")
41+
@click.option('--recursive', is_flag=True, default=False,
42+
help='Displays all subdirectories and files.')
4143
@click.argument('dbfs_path', nargs=-1, type=DbfsPathClickType())
4244
@debug_option
4345
@profile_option
@@ -53,10 +55,20 @@ def ls_cli(api_client, l, absolute, dbfs_path): # NOQA
5355
dbfs_path = dbfs_path[0]
5456
else:
5557
error_and_quit('ls can take a maximum of one path.')
56-
files = DbfsApi(api_client).list_files(dbfs_path)
57-
table = tabulate([f.to_row(is_long_form=l, is_absolute=absolute) for f in files],
58-
tablefmt='plain')
59-
click.echo(table)
58+
59+
def echo_path(files):
60+
table = tabulate([f.to_row(is_long_form=l, is_absolute=absolute) for f in files],
61+
tablefmt='plain')
62+
click.echo(table)
63+
64+
def recursive_echo(this_dbfs_path):
65+
files = DbfsApi(api_client).list_files(this_dbfs_path)
66+
echo_path(files)
67+
for f in files:
68+
if f.is_dir:
69+
recursive_echo(this_dbfs_path.join(f.basename))
70+
71+
recursive_echo(dbfs_path) if recursive else echo_path(dbfs_path)
6072

6173

6274
@click.command(context_settings=CONTEXT_SETTINGS)

0 commit comments

Comments
 (0)