Class: RCite::CLI::CiteCommand

Inherits:
Command
  • Object
show all
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

Instance Method Summary collapse

Methods inherited from Command

#help, #run, validate_file

Constructor Details

#initializeCiteCommand

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

.nameObject

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

#run!String

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.

Returns:

  • (String)

    the generated citation.



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.message)
    exit 1
  end
end

#setup_slopvoid

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

#validate_optsvoid

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