Class: Filepreviews::CLI
- Inherits:
-
Object
- Object
- Filepreviews::CLI
- Defined in:
- lib/filepreviews/cli.rb
Overview
A Simple class for the executable version of the gem
Constant Summary collapse
- BANNER =
"Usage: filepreviews [OPTION] [URL]\nDescription:\nFilepreviews.io - Thumbnails and metadata for almost any kind of file\n\nOptions:\n"
Instance Method Summary collapse
-
#initialize(args) ⇒ CLI
constructor
Passes arguments from ARGV and sets metadata flag.
-
#options(opts) ⇒ Object
Configures the arguments for the command.
-
#parse ⇒ Object
Parses options sent from command-line.
Constructor Details
#initialize(args) ⇒ CLI
Passes arguments from ARGV and sets metadata flag
16 17 18 |
# File 'lib/filepreviews/cli.rb', line 16 def initialize(args) @args, = args, false end |
Instance Method Details
#options(opts) ⇒ Object
Configures the arguments for the command
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 |
# File 'lib/filepreviews/cli.rb', line 22 def (opts) opts.version = Filepreviews::VERSION opts. = BANNER opts.set_program_name 'Filepreviews.io' opts.on('-k', '--api_key [key]', String, 'use API key from Filepreviews.io') do |api_key| Filepreviews.api_key = api_key end opts.on('-s', '--secret_key [key]', String, 'use Secret key from Filepreviews.io') do |secret_key| Filepreviews.secret_key = secret_key end opts.on('-m', '--metadata', 'load metadata response') do = true end opts.on_tail('-v', '--version', 'display the version of Filepreviews') do puts opts.version exit end opts.on_tail('-h', '--help', 'print this help') do puts opts.help exit end end |
#parse ⇒ Object
Parses options sent from command-line
53 54 55 56 57 58 59 60 |
# File 'lib/filepreviews/cli.rb', line 53 def parse opts = OptionParser.new(&method(:options)) opts.parse!(@args) return opts.help if @args.last.nil? file_preview = Filepreviews.generate(@args.last) ? file_preview.(js: true) : file_preview end |