Sha256: 7f4335fc9b3af18055ccdf7681043325b6e7c2225e9718af86840aa14967af11

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

# class that groks the command line options and invokes the required task
class GmailCli::Shell

  # holds the parsed options
  attr_reader :options

  # holds the remaining command line arguments
  attr_reader :args

  # 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
  #
  def initialize(options,args)
    @options = (options||{}).each{|k,v| {k => v} }
    @args = args
    GmailCli::Logger.set_log_mode(options[:verbose])
  end

  # Command: execute the task according to the options provided on initialisation
  def run
    case
    when args.first =~ /authorize/i
      authorize
    else
      usage
    end
  end

  # defines the valid command line options
  OPTIONS = %w(help verbose client_id:s client_secret:s)

  class << self

    # prints usage/help information
    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
  end

  # prints usage/help information
  def usage
    self.class.usage
  end

  def authorize
    GmailCli::Oauth2Helper.authorize!(options)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gmail_cli-0.1.0 lib/gmail_cli/shell.rb
gmail_cli-0.0.1 lib/gmail_cli/shell.rb