Class: ActiveMailbox::CLI
- Inherits:
-
Object
- Object
- ActiveMailbox::CLI
- Defined in:
- lib/active_mailbox/cli.rb
Overview
This class facilites ActiveMailbox’s command line functions
Class Method Summary collapse
-
.parse(argv) ⇒ Object
Parse CLI arguments (ARGV).
-
.run!(argv) ⇒ Object
Invoke the CLI.
Class Method Details
.parse(argv) ⇒ Object
Parse CLI arguments (ARGV)
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/active_mailbox/cli.rb', line 30 def self.parse(argv) = {} ::OptionParser.new do |opts| opts. = "Usage: active_mailbox [OPTION] MAILBOX\n" opts.separator "" opts.separator "Mailbox Options:" opts.on('--context', 'Look for [MAILBOX] in [CONTEXT]') do |context| [:context] = conext end opts.on('--delete', 'Delete [MAILBOX] and all messages') do [:command] = :delete! end opts.on('--sort', 'Sort messages in [MAILBOX] (recursive)') do [:command] = :sort! end opts.separator "" opts.separator "Cleanup Options:" opts.on('--clean-ghosts', "Cleanup 'ghost' messages") do [:command] = :clean_ghosts! end opts.on('--clean-stale', 'Cleanup messages older than 30 days') do [:command] = :clean_stale! end opts.on('--clean-mp3s', 'Cleanup [MAILBOX]/.mp3 directory') do [:command] = :clean_mp3s! end opts.on('--purge', 'Remove all messages, but leave [MAILBOX] folders intact') do [:command] = :purge! end opts.separator "" opts.separator "Greeting Options:" opts.on('--delete-temp', 'Delete [MAILBOX]/temp.wav') do [:command] = :delete_temp_greeting! end opts.on('--delete-unavail', 'Delete [MAILBOX]/unavail.wav') do [:command] = :delete_unavail_greeting! end opts.on('--delete-busy', 'Delete [MAILBOX]/busy.wav') do [:command] = :delete_busy_greeting! end opts.separator "" opts.separator "General Options:" opts.on('-h', '--help', 'Show this message') do [:command] = :help puts opts exit end opts.on('-v', '--version', 'Show version') do [:command] = :version puts ActiveMailbox::Version exit end begin argv = ['-h'] if argv.empty? opts.parse!(argv) [:mailbox] = argv.shift rescue ::OptionParser::ParseError => err STDERR.puts err., "\n", opts exit(-1) end end end |
.run!(argv) ⇒ Object
Invoke the CLI
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/active_mailbox/cli.rb', line 12 def self.run!(argv) = ActiveMailbox::CLI.parse(argv) args = [[:mailbox]] args.unshift([:context]) if [:context] mailbox = ActiveMailbox::Mailbox.find(*args) if [:arg] mailbox.send([:command], [:arg]) else mailbox.send([:command]) end end |