Class: Indexer::Command
- Inherits:
-
Object
- Object
- Indexer::Command
- Defined in:
- lib/indexer/command.rb
Overview
Command line interface.
Defined Under Namespace
Modules: CleanBinding Classes: Form
Class Method Summary collapse
-
.run(argv = ARGV) ⇒ Object
Shortcut to ‘new.run(argv)`.
Instance Method Summary collapse
- #adding(*sources) ⇒ Object
- #generate(type, outfile = nil) ⇒ Object
- #help ⇒ Object
-
#initialize ⇒ Command
constructor
A new instance of Command.
- #run(argv = ARGV) ⇒ Object
-
#show(*fields) ⇒ Object
Show returns information from the ‘.index` file.
- #using(*sources) ⇒ Object
Constructor Details
#initialize ⇒ Command
Returns a new instance of Command.
17 18 19 20 21 |
# File 'lib/indexer/command.rb', line 17 def initialize @force = false @stdout = false @static = false end |
Class Method Details
.run(argv = ARGV) ⇒ Object
Shortcut to ‘new.run(argv)`.
10 11 12 |
# File 'lib/indexer/command.rb', line 10 def self.run(argv=ARGV) new.run(argv) end |
Instance Method Details
#adding(*sources) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/indexer/command.rb', line 80 def adding(*sources) raise Error.exception("no sources given") if sources.empty? = Metadata.open = Metadata.lock((.sources & sources), :force=>true) if @stdout puts .to_yaml else .save! end end |
#generate(type, outfile = nil) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/indexer/command.rb', line 92 def generate(type, outfile=nil) case type.downcase when 'gemspec' create_gemspec(outfile) when 'ruby', 'index.rb', 'indexfile' create_ruby(outfile) when 'yaml', 'index.yml', 'index.yaml' create_yaml(outfile) else raise Error.exception("unknown file type") end end |
#help ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/indexer/command.rb', line 106 def help puts <<-END index [command-option] [options...] [arguments...] (none) [fields...] update index and provide information from index -u --using <sources...> create index using given information sources -a --adding <sources...> update index appending additional information sources -r --remove <sources...> update index removing given information sources -g --generate <type> [fname] generate a file (gemspec, indexfile, metadata) -h --help show this help message -o --stdout output to console instead of saving to file -f --force force protected file overwrite if file already exists or is up to date -s --static keep index as is or generate static format if generator supports it END end |
#run(argv = ARGV) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/indexer/command.rb', line 26 def run(argv=ARGV) cmd = nil args = cli(argv, '-d --debug' => lambda{ $DEBUG = true }, '-w --warn' => lambda{ $VERBOSE = true }, '-f --force' => lambda{ @force = true }, '-o --stdout' => lambda{ @stdout = true }, '-s --static' => lambda{ @static = true }, '-u --using' => lambda{ no_cmd!(cmd); cmd = :using }, '-a --adding' => lambda{ no_cmd!(cmd); cmd = :adding }, '-g --generate' => lambda{ no_cmd!(cmd); cmd = :generate }, '-h --help' => lambda{ no_cmd!(cmd); cmd = :help } ) send(cmd || :show, *args) rescue => error raise error if $DEBUG $stderr.puts "#{File.basename($0)} error: #{error}" exit -1 end |
#show(*fields) ⇒ Object
Show returns information from the ‘.index` file. Before doing so it always ensures the `.index` file is up to date. To suppress this update use the `-S/–static` option.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/indexer/command.rb', line 51 def show(*fields) if @static if Metadata.exists? = Metadata.open puts .about(*fields) else raise Error.exception(".index file not found", IOError) end else Metadata.lock!(:force=>@force) unless fields.empty? = Metadata.open puts .about(*fields) end end end |