Class: RikaCommand
- Inherits:
-
Object
- Object
- RikaCommand
- Defined in:
- lib/rika/cli/rika_command.rb
Overview
This command line application enables the parsing of documents on the command line. Syntax is:
rika [] <file or url> [...file or url...]
Run with -h or –help option for more details.
Defaults to outputting both content (text) and metadata, but the -t and -m flags can be used to enable or suppress either. Supports output formats of JSON, Pretty JSON, YAML, Awesome Print, to_s, and inspect (see Formatters class).
Constant Summary collapse
- FORMAT_DESCRIPTIONS =
Hash.new('Unknown').merge( 'a' => 'AwesomePrint', 'i' => 'inspect', 'j' => 'JSON', 'J' => 'Pretty JSON', 't' => 'to_s', 'y' => 'YAML' ).freeze
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#bad_targets ⇒ Object
readonly
Returns the value of attribute bad_targets.
-
#help_text ⇒ Object
readonly
Returns the value of attribute help_text.
-
#metadata_formatter ⇒ Object
readonly
Returns the value of attribute metadata_formatter.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
-
#text_formatter ⇒ Object
readonly
Returns the value of attribute text_formatter.
Class Method Summary collapse
-
.output_help_text(help_text, error_message = nil) ⇒ void
Outputs help text to stdout.
Instance Method Summary collapse
-
#call ⇒ Integer
Main method and entry point for this class’ work.
-
#initialize(args = ARGV) ⇒ RikaCommand
constructor
A new instance of RikaCommand.
Constructor Details
#initialize(args = ARGV) ⇒ RikaCommand
Returns a new instance of RikaCommand.
41 42 43 44 45 46 |
# File 'lib/rika/cli/rika_command.rb', line 41 def initialize(args = ARGV) # Dup the array in case it has been frozen. The array will be modified later when options are parsed # and removed, and when directories are removed, so this array should not be frozen. @args = args.dup @bad_targets = Hash.new { |hash, key| hash[key] = [] } end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
29 30 31 |
# File 'lib/rika/cli/rika_command.rb', line 29 def args @args end |
#bad_targets ⇒ Object (readonly)
Returns the value of attribute bad_targets.
29 30 31 |
# File 'lib/rika/cli/rika_command.rb', line 29 def bad_targets @bad_targets end |
#help_text ⇒ Object (readonly)
Returns the value of attribute help_text.
29 30 31 |
# File 'lib/rika/cli/rika_command.rb', line 29 def help_text @help_text end |
#metadata_formatter ⇒ Object (readonly)
Returns the value of attribute metadata_formatter.
29 30 31 |
# File 'lib/rika/cli/rika_command.rb', line 29 def end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
29 30 31 |
# File 'lib/rika/cli/rika_command.rb', line 29 def end |
#targets ⇒ Object (readonly)
Returns the value of attribute targets.
29 30 31 |
# File 'lib/rika/cli/rika_command.rb', line 29 def targets @targets end |
#text_formatter ⇒ Object (readonly)
Returns the value of attribute text_formatter.
29 30 31 |
# File 'lib/rika/cli/rika_command.rb', line 29 def text_formatter @text_formatter end |
Class Method Details
.output_help_text(help_text, error_message = nil) ⇒ void
This method returns an undefined value.
Outputs help text to stdout
35 36 37 38 |
# File 'lib/rika/cli/rika_command.rb', line 35 def self.output_help_text(help_text, = nil) $stderr.puts() if puts help_text end |
Instance Method Details
#call ⇒ Integer
Main method and entry point for this class’ work.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rika/cli/rika_command.rb', line 50 def call prepare report_and_exit_if_no_targets_specified if [:dry_run] display_dry_run_info return 0 end process_targets report_bad_targets bad_targets.values.flatten.empty? ? 0 : 1 end |