Class: RST::RstCommand

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

Overview

Interprets and runs options and commands. See [EXAMPLES.md](../file.examples.html)

Examples:

runner = RstCommand.new(ARGV)
puts runner.run

Constant Summary collapse

DEFAULT_OPTIONS =

Default options are always present, even if the user will not provide them. They can be overwritten, though.

See Also:

  • #parse_options
{ name: 'unnamed', from: 'today', to: 'today', show_empty: false }

PUBLIC INTERFACE collapse

PUBLIC INTERFACE collapse

Constructor Details

#initialize(args) ⇒ RstCommand

Initialize the Command-runner with arguments and parse them.

Examples:

app = RstCommand.new(ARGV)
app.run()


47
48
49
50
51
52
53
54
# File 'lib/rst.rb', line 47

def initialize(args)
  @options = {}
  load_defaults
  parse_options(args)
  _command = args.shift
  @command = _command if _command
  @files = args
end

Instance Attribute Details

#commandObject (readonly)

the first argument of ARGV is the command. It’s extracted in run_command

See Also:

  • #run_command


41
42
43
# File 'lib/rst.rb', line 41

def command
  @command
end

#optionsObject (readonly)

the hash stores options parsed in mehtod parse_options.

See Also:

  • #parse_options


37
38
39
# File 'lib/rst.rb', line 37

def options
  @options
end

Instance Method Details

#runString

Call ‘run_options’ and ‘run_command’, reject empty returns and join

output with CR

Returns:



59
60
61
# File 'lib/rst.rb', line 59

def run
  [run_options, run_command].compact.reject{|l| l.strip == '' }.join("\n")
end