Class: GmailCli::Shell
- Inherits:
-
Object
- Object
- GmailCli::Shell
- Defined in:
- lib/gmail_cli/shell.rb
Overview
class that groks the command line options and invokes the required task
Constant Summary collapse
- OPTIONS =
defines the valid command line options
%w(help verbose client_id:s client_secret:s)
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
holds the remaining command line arguments.
-
#options ⇒ Object
readonly
holds the parsed options.
Class Method Summary collapse
-
.usage ⇒ Object
prints usage/help information.
Instance Method Summary collapse
- #authorize ⇒ Object
-
#initialize(options, args) ⇒ Shell
constructor
initializes the shell with command line argments:.
-
#run ⇒ Object
Command: execute the task according to the options provided on initialisation.
-
#usage ⇒ Object
prints usage/help information.
Constructor Details
#initialize(options, args) ⇒ Shell
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
16 17 18 19 20 |
# File 'lib/gmail_cli/shell.rb', line 16 def initialize(,args) = (||{}).each{|k,v| {k => v} } @args = args GmailCli::Logger.set_log_mode([:verbose]) end |
Instance Attribute Details
#args ⇒ Object (readonly)
holds the remaining command line arguments
8 9 10 |
# File 'lib/gmail_cli/shell.rb', line 8 def args @args end |
#options ⇒ Object (readonly)
holds the parsed options
5 6 7 |
# File 'lib/gmail_cli/shell.rb', line 5 def end |
Class Method Details
.usage ⇒ Object
prints usage/help information
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gmail_cli/shell.rb', line 38 def usage $stderr.puts "\nGmailCli v\#{GmailCli::VERSION}\n===================================\n\nUsage:\n gmail_cli [options] [commands]\n\nOptions:\n -h | --help : shows command help\n -v | --verbose : run with verbose\n\n --client_id \"xxxx\" : OAuth2 client_id\n --client_secret \"yyy\" : OAuth2 client_secret\n\nCommands:\n authorize : perform Google OAuth2 client authorization\n\n\n" end |
Instance Method Details
#authorize ⇒ Object
67 68 69 |
# File 'lib/gmail_cli/shell.rb', line 67 def GmailCli::Oauth2Helper.() end |
#run ⇒ Object
Command: execute the task according to the options provided on initialisation
23 24 25 26 27 28 29 30 |
# File 'lib/gmail_cli/shell.rb', line 23 def run case when args.first =~ /authorize/i else usage end end |
#usage ⇒ Object
prints usage/help information
63 64 65 |
# File 'lib/gmail_cli/shell.rb', line 63 def usage self.class.usage end |