def main():
try:
import setproctitle
setproctitle.setproctitle(name)
except ImportError:
pass
dialects = csv.list_dialects()
dialects.sort()
dialects.insert(0, 'sniff')
# CLI arguments
parser = argparse.ArgumentParser(prog=name, description=description)
parser.add_argument('-V', '--version', action='version', version="%(prog)s " + version)
parser.add_argument('-C', '--config', help='Use a different configuration file')
parser.add_argument('-s', '--section', help='Configuration file section', default='DEFAULT')
parser.add_argument('-c', '--channel', help='Send to this channel or @username')
parser.add_argument('-U', '--url', help='Mattermost webhook URL')
parser.add_argument('-u', '--username', help='Username')
parser.add_argument('-i', '--icon', help='Icon')
group = parser.add_mutually_exclusive_group()
group.add_argument('-t', '--tabular', metavar='DIALECT', const='sniff',
nargs='?', choices=dialects,
help='Parse input as CSV and format it as a table (DIALECT can be one of %(choices)s)')
group.add_argument('-y', '--syntax', default='auto')
parser.add_argument('-I', '--info', action='store_true',
help='Include file information in message')
parser.add_argument('-n', '--dry-run', '--just-print', action='store_true',
help="Don't send, just print the payload")
parser.add_argument('-f', '--file', default='-',
help="Read content from FILE. If - reads from standard input (DEFAULT: %(default)s)")
args = parser.parse_args()
if args.file == '-':
message = sys.stdin.read()
filename = None
else:
message = ''
filename = args.file
try:
payload = send(args.channel, message, filename, args.url,
args.username, args.icon, args.syntax, args.tabular,
args.info, args.dry_run, args.section, name,
args.config)
except (configparser.Error, TypeError, RuntimeError) as e:
sys.exit(str(e))
if args.dry_run:
print(payload)
评论列表
文章目录