1
0
mirror of https://github.com/arsenetar/send2trash.git synced 2026-02-10 23:01:38 +00:00

Create __main__.py (Fixes #15) (#38)

This adds a main method that mimics the behavior of `rm`. It can be called via `python -m send2trash somefile`.
This commit is contained in:
Matthew D. Scholefield
2020-05-27 06:52:00 -05:00
committed by GitHub
parent 66afce7252
commit 9ede898c3e
2 changed files with 65 additions and 0 deletions

33
send2trash/__main__.py Normal file
View File

@@ -0,0 +1,33 @@
# encoding: utf-8
# Copyright 2017 Virgil Dupras
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
# which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license
from __future__ import print_function
import sys
from argparse import ArgumentParser
from send2trash import send2trash
def main(args=None):
parser = ArgumentParser(description='Tool to send files to trash')
parser.add_argument('files', nargs='+')
parser.add_argument('-v', '--verbose', action='store_true', help='Print deleted files')
args = parser.parse_args(args)
for filename in args.files:
try:
send2trash(filename)
if args.verbose:
print('Trashed «' + filename + '»')
except OSError as e:
print(str(e), file=sys.stderr)
sys.exit(1)
if __name__ == '__main__':
main()