Class: Steamd::CliOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/steamd/cli_options.rb

Overview

Options that the CLI can take

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ CliOptions

Create a CliOptions object

Examples:

Using CliOptions

opts = CliOptions.new(ouput: './')

Parameters:

  • opts (Hash) (defaults to: {})

    options hash

Options Hash (opts):

  • :output (String)

    the output directory

  • :input (String)

    the output directory



13
14
15
16
17
18
# File 'lib/steamd/cli_options.rb', line 13

def initialize(opts = {})
  @options = opts
  @output  = opts[:output]
  @input   = opts[:input]
  self
end

Instance Method Details

#inputObject

Returns the absolute path of the input directory specified by the cli.

Throws an exception if the input is not a directory

Examples:

Getting the input path

opts = CliOptions.new(input: '/some/dir')
opts.input # => '/some/dir'


28
29
30
31
32
33
34
35
36
37
# File 'lib/steamd/cli_options.rb', line 28

def input
  o = if @input.nil?
        Steamd.language_dir
      else
        @input
      end

  raise 'input must be a directory' unless File.directory?(o)
  File.expand_path(o)
end

#outputObject

Returns the absolute path of the output directory specified by the cli.

Throws an exception if the output is not a directory

Examples:

Getting the output path

opts = CliOptions.new(output: '/some/dir')
opts.output # => '/some/dir'


47
48
49
50
51
52
53
54
55
56
# File 'lib/steamd/cli_options.rb', line 47

def output
  o = if @output.nil?
        './lib/steamd'
      else
        @output
      end

  raise 'output must be a directory' unless File.directory?(o)
  File.expand_path(o)
end