Class: RCite::CLI::CiteCommand
- Inherits:
-
Command
- Object
- Command
- RCite::CLI::CiteCommand
- Defined in:
- lib/rcite/cli/cmd_cite.rb
Overview
Command that creates a citation of a text. This provides the command line interface to Processor#cite.
Class Method Summary (collapse)
-
+ (Object) name
This command's name.
Instance Method Summary (collapse)
-
- (CiteCommand) initialize
constructor
Creates an instance of this command.
-
- (String) run!
Cites the text specified on the command line.
-
- (void) setup_slop
Creates this command's
Slopinstance and sets up the options this command accepts. -
- (void) validate_opts
Validates the options passed to
rcite cite.
Methods inherited from Command
Constructor Details
- (CiteCommand) initialize
Creates an instance of this command.
13 14 15 |
# File 'lib/rcite/cli/cmd_cite.rb', line 13 def initialize super end |
Class Method Details
+ (Object) name
This command's name. See RCite::CLI::Command.
8 9 10 |
# File 'lib/rcite/cli/cmd_cite.rb', line 8 def self.name 'cite'.freeze end |
Instance Method Details
- (String) run!
Cites the text specified on the command line. See RCite::CLI::Command.
In particular, this method validates all options (in addition to the validation already performed by Slop) using #validate_opts and then uses Processor#cite to cite the specified text, handling any exceptions that are thrown by the processor.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rcite/cli/cmd_cite.rb', line 36 def run! validate_opts processor = RCite::Processor.new processor.load_style(@slop[:style]) processor.load_data(@slop[:bib]) begin return processor.cite(@cmdline[0]) rescue ArgumentError => ex log.error(ex.) exit 1 end end |
- (void) setup_slop
This method returns an undefined value.
Creates this command's Slop instance and sets up the options this
command accepts. See RCite::CLI::Command.
21 22 23 24 25 26 |
# File 'lib/rcite/cli/cmd_cite.rb', line 21 def setup_slop @slop = Slop.new do on :s, :style=, 'path to the style file', true, required: true on :b, :bib=, 'path to the BibTeX file', true, required: true end end |
- (void) validate_opts
This method returns an undefined value.
Validates the options passed to rcite cite. Checks if all files are
readable and if the user has specified the text ID to process. Logs
errors and exits otherwise.
55 56 57 58 59 60 61 62 63 |
# File 'lib/rcite/cli/cmd_cite.rb', line 55 def validate_opts Command.validate_file(@slop[:style]) Command.validate_file(@slop[:bib]) unless @cmdline[0] log.error("Please specify a text ID. See #{0} help cite for help.") exit 1 end end |