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. = <<-EOF Usage: tegawa [options] TeGaWa stands for Telegram GateWay. This tool is supposed to be run as a daemon and accept local mail as well as watch a directory for text files. It then forwards these mails and files to a Telegram channel so you can easily stay informed about what is happening on your systems. It expects $TEGAWA_TOKEN to contain your telegram bot token and it needs the channel_id to which it forwards the information. EOF 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| args[:channel] = v end opts.on("-pPORT", "--port=PORT", "Port on which the mailserver should listen. Default 2525.") do |v| args[:port] = v.to_i end opts.on("-aADDR", "--addr=ADDR", "IP on which to listen for connections. Default 127.0.0.1.") do |v| args[:addr] = v end opts.on("-lLOG", "--logfile=LOG", "Where to write logging output. Default is STDOUT.") do |v| args[:log_file] = make_log_file(v) end opts.on("-wWATCH", "--watch=WATCH", "Which directory to watch for files to forward") do |v| unless File.directory?(v) puts "Watch dir not a directory." exit end args[:watch_dir] = v end opts.on("-h", "--help", "Prints this help") do puts opts exit end opts.on("--version", "Show version") do puts "Telegram GateWay Version #{Tegawa::VERSION}" exit end } opt_parser.parse!(ARGV) args[:token] = ENV["TEGAWA_TOKEN"] if args[:token].nil? || args[:channel].nil? puts "Please set $TEGAWA_TOKEN to your telegram bot token and provide a --channel argument." exit end setup(args) end |