Skip to content

Commit

Permalink
add test command
Browse files Browse the repository at this point in the history
  • Loading branch information
SerhoLiu committed Mar 26, 2017
1 parent 0b97de8 commit 5274b3d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions coscli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,19 @@ def cos_du(config, uri, s, human):
"%s%s" % (size, coeff),
COSUri.compose_uri(cos_uri.bucket, obj.path)
))


def cos_test(config, uri, d, e, f):
cos = COS(config.cos_config)
cos_uri = COSUri(uri)

file_exists = cos.file_exists(cos_uri.bucket, cos_uri.path)
if f:
return file_exists

dir_exists = cos.dir_exists(cos_uri.bucket, cos_uri.path)
if d:
return dir_exists

if e:
return file_exists or dir_exists
20 changes: 20 additions & 0 deletions coscli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,23 @@ def du_command(config, uri, s, human):
command.cos_du(config, uri, s, human)
except Exception as e:
handle_exception(e, config.debug)


@cli.command(name="test")
@click.argument("uri", nargs=1)
@click.option("-d", is_flag=True, help="Test the path is a directory")
@click.option("-e", is_flag=True, help="Test the path exists")
@click.option("-f", is_flag=True, help="Test the path is a file")
@pass_config
def test_command(config, uri, d, e, f):
"""
Test give path is exists
"""
if not (d or e or f):
raise SystemExit("error: test need flag -d/-e/-f")

try:
test = command.cos_test(config, uri, d, e, f)
sys.exit(0 if test else 1)
except Exception as e:
handle_exception(e, config.debug)

0 comments on commit 5274b3d

Please sign in to comment.