Class: RCite::CLI::BibCommand
- Inherits:
-
Command
- Object
- Command
- RCite::CLI::BibCommand
- Defined in:
- lib/rcite/cli/cmd_bib.rb
Overview
Command that creates a bibliography entry of a text. This provides the command line interface to Processor#bib.
Class Method Summary (collapse)
-
+ (Object) name
This command's name.
Instance Method Summary (collapse)
-
- (BibCommand) initialize
constructor
Creates an instance of this command.
-
- (String) run!
Creates a bibliography entry for 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 bib.
Methods inherited from Command
Constructor Details
- (BibCommand) initialize
Creates an instance of this command.
13 14 15 |
# File 'lib/rcite/cli/cmd_bib.rb', line 13 def initialize super end |
Class Method Details
+ (Object) name
This command's name. See Command.
8 9 10 |
# File 'lib/rcite/cli/cmd_bib.rb', line 8 def self.name 'bib'.freeze end |
Instance Method Details
- (String) run!
Creates a bibliography entry for the text specified on the command line. See Command.
In particular, this method validates all options (in addition to the validation already performed by Slop) using #validate_opts and then uses Processor#bib to generate a bibliography entry for the specified text, handling any exceptions that are thrown by the processor.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rcite/cli/cmd_bib.rb', line 38 def run! validate_opts processor = RCite::Processor.new processor.load_style(@slop[:style]) processor.load_data(@slop[:bib]) begin return processor.bib(@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 Command.
21 22 23 24 25 26 |
# File 'lib/rcite/cli/cmd_bib.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 bib. Checks if all files are
readable and if the user has specified the text ID to process. Logs
errors and exits otherwise.
57 58 59 60 61 62 63 64 65 |
# File 'lib/rcite/cli/cmd_bib.rb', line 57 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 |