Class: Tegawa::Cli::Application
- Inherits:
-
Object
- Object
- Tegawa::Cli::Application
- Defined in:
- lib/tegawa/cli.rb
Instance Attribute Summary collapse
-
#mail_server ⇒ Object
readonly
Returns the value of attribute mail_server.
Class Method Summary collapse
Instance Attribute Details
#mail_server ⇒ Object (readonly)
Returns the value of attribute mail_server.
13 14 15 |
# File 'lib/tegawa/cli.rb', line 13 def mail_server @mail_server end |
Class Method Details
.start ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tegawa/cli.rb', line 16 def start args = { port: 2525, addr: "127.0.0.1", # watch_dir: nil, log_file: STDOUT, channel: nil, token: nil } # opt_parser = OptionParser.new do |opts| opt_parser = OptionParser.new { |opts| opts. = "Usage: tegawa [options]\n\nTeGaWa stands for Telegram GateWay. This tool is supposed to be run\nas a daemon and accept local mail as well as watch a directory for\ntext files. It then forwards these mails and files to a Telegram\nchannel so you can easily stay informed about what is happening on\nyour systems.\n\nIt expects $TEGAWA_TOKEN to contain your telegram bot token and it\nneeds the channel_id to which it forwards the information.\n\n EOF\n\n opts.on(\"-cCHANNEL\", \"--channel=CHANNEL\", \"The id of the telegram channel that should get the forwarded messages. Make sure your bot is a member first.\") do |v|\n args[:channel] = v\n end\n opts.on(\"-pPORT\", \"--port=PORT\", \"Port on which the mailserver should listen. Default 2525.\") do |v|\n args[:port] = v.to_i\n end\n opts.on(\"-aADDR\", \"--addr=ADDR\", \"IP on which to listen for connections. Default 127.0.0.1.\") do |v|\n args[:addr] = v\n end\n opts.on(\"-lLOG\", \"--logfile=LOG\", \"Where to write logging output. Default is STDOUT.\") do |v|\n args[:log_file] = make_log_file(v)\n end\n opts.on(\"-wWATCH\", \"--watch=WATCH\", \"Which directory to watch for files to forward\") do |v|\n unless File.directory?(v)\n puts \"Watch dir not a directory.\"\n exit\n end\n args[:watch_dir] = v\n end\n opts.on(\"-h\", \"--help\", \"Prints this help\") do\n puts opts\n exit\n end\n opts.on(\"--version\", \"Show version\") do\n puts \"Telegram GateWay Version \#{Tegawa::VERSION}\"\n exit\n end\n }\n opt_parser.parse!(ARGV)\n\n args[:token] = ENV[\"TEGAWA_TOKEN\"]\n\n if args[:token].nil? || args[:channel].nil?\n puts \"Please set $TEGAWA_TOKEN to your telegram bot token and provide a --channel argument.\"\n exit\n end\n\n setup(args)\nend\n" |