class GmailCli::Shell

class that groks the command line options and invokes the required task

Constants

OPTIONS

defines the valid command line options

Attributes

args[R]

holds the remaining command line arguments

options[R]

holds the parsed options

Public Class Methods

new(options,args) click to toggle source

initializes the shell with command line argments:

options is expected to be the hash structure as provided by GetOptions.new(..)

args is the remaining command line arguments

# File lib/gmail_cli/shell.rb, line 16
def initialize(options,args)
  @options = (options||{}).each{|k,v| {k => v} }
  @args = args
  GmailCli::Logger.set_log_mode(options[:verbose])
end
usage() click to toggle source

prints usage/help information

# File lib/gmail_cli/shell.rb, line 38
    def usage
      $stderr.puts <<-EOS

GmailCli v#{GmailCli::VERSION}
===================================

Usage:
  gmail_cli [options] [commands]

Options:
  -h  | --help           : shows command help
  -v  | --verbose        : run with verbose

  --client_id "xxxx"     : OAuth2 client_id
  --client_secret "yyy"  : OAuth2 client_secret

Commands:
  authorize              : perform Google OAuth2 client authorization


EOS
    end

Public Instance Methods

authorize() click to toggle source
# File lib/gmail_cli/shell.rb, line 67
def authorize
  GmailCli::Oauth2Helper.authorize!(options)
end
run() click to toggle source

Command: execute the task according to the options provided on initialisation

# File lib/gmail_cli/shell.rb, line 23
def run
  case
  when args.first =~ /authorize/i
    authorize
  else
    usage
  end
end
usage() click to toggle source

prints usage/help information

# File lib/gmail_cli/shell.rb, line 63
def usage
  self.class.usage
end