Class: Gista::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/gista/options.rb

Overview

Parse options given on the command line into an options hash suitable for a GistRequest object.

This provides the default options:

  • Gists are private by default
  • When reading from STDIN, the file is titled 'untitled'

When any options are left after parsing all the flags, they are treated as filenames. They will be added to the options as files in the Gist. When no arguments are left, input is read from STDIN and its contents will be added to the options hash as a single file.

This also provides the --help and --version options for the command-line client.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Options

Returns a new instance of Options.



25
26
27
28
29
# File 'lib/gista/options.rb', line 25

def initialize(args)
  @args = args
  @options = { public: false }
  @stdin_filename = 'untitled'
end

Instance Attribute Details

#argsArray (readonly)

Command line options, flags and filenames

Returns:

  • (Array)


23
24
25
# File 'lib/gista/options.rb', line 23

def args
  @args
end

Instance Method Details

#optionsHash

Returns:

  • (Hash)


32
33
34
35
36
# File 'lib/gista/options.rb', line 32

def options
  parse_options
  parse_files
  @options
end