add ls option --stop-on-error
This commit is contained in:
parent
01a96c14d4
commit
6b65efd8c7
1 changed files with 19 additions and 3 deletions
|
|
@ -148,6 +148,7 @@ def getargs():
|
|||
parser_ls.add_argument(
|
||||
"--match", choices=("regex", "glob", "fuzzy"), default="glob"
|
||||
)
|
||||
parser_ls.add_argument("--stop-on-error", action="store_true")
|
||||
|
||||
# Parse args.
|
||||
|
||||
|
|
@ -220,8 +221,9 @@ def cmd_rm(args):
|
|||
|
||||
metadex.close()
|
||||
|
||||
def cmd_ls(args) -> int:
|
||||
return_code = 0
|
||||
|
||||
def cmd_ls(args):
|
||||
metadex.init(args.db)
|
||||
|
||||
args.file = [f for f in args.file if f]
|
||||
|
|
@ -236,7 +238,10 @@ def cmd_ls(args):
|
|||
|
||||
for pathspec in args.file:
|
||||
|
||||
is_match = False
|
||||
for file in metadex.ls(pathspec, type=args.type, match=args.match):
|
||||
is_match = True
|
||||
|
||||
date = file.stat_modified.isoformat(sep=" ", timespec="seconds")
|
||||
size = utils.size_for_display(
|
||||
file.stat_bytes, precision=1, format="compact"
|
||||
|
|
@ -255,9 +260,19 @@ def cmd_ls(args):
|
|||
", ".join(keys),
|
||||
exc_info=err,
|
||||
)
|
||||
return 5
|
||||
return_code = 5
|
||||
return return_code
|
||||
print(out)
|
||||
|
||||
if not is_match:
|
||||
log.error("No match: %a", pathspec)
|
||||
return_code = 3
|
||||
|
||||
if args.stop_on_error:
|
||||
return return_code
|
||||
|
||||
return return_code
|
||||
|
||||
|
||||
def is_stdout_piped():
|
||||
s = os.fstat(sys.stdout.fileno())
|
||||
|
|
@ -295,7 +310,8 @@ def main():
|
|||
log.info(
|
||||
"If the hostname cannot be found automatically, try setting it using --hostname."
|
||||
)
|
||||
return 2
|
||||
return_code = 2
|
||||
return return_code
|
||||
|
||||
if config.dryrun:
|
||||
log.info(f"--- DRY RUN ---")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue