Class: Repofetch::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/repofetch/cli.rb

Overview

Command line interface for repofetch.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil, args = ARGV) ⇒ CLI

Define the command line interface.

Parameters:

  • config (Repofetch::Config) (defaults to: nil)

    The configuration to use. Defaults to Repofetch.config.

  • args (Array<String>) (defaults to: ARGV)

    Command line arguments.



18
19
20
21
22
# File 'lib/repofetch/cli.rb', line 18

def initialize(config = nil, args = ARGV)
  @config = config || Repofetch.config
  @args = args
  @repository_path = '.'
end

Instance Attribute Details

#pluginObject (readonly)

Returns the value of attribute plugin.



12
13
14
# File 'lib/repofetch/cli.rb', line 12

def plugin
  @plugin
end

#repository_pathObject (readonly)

Returns the value of attribute repository_path.



12
13
14
# File 'lib/repofetch/cli.rb', line 12

def repository_path
  @repository_path
end

Instance Method Details

#define_optionsObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/repofetch/cli.rb', line 36

def define_options
  OptionParser.new do |opts|
    opts.banner = 'Usage: repofetch [options] -- [plugin arguments]'

    add_repository_options(opts)
    add_plugin_options(opts)
    add_version_option(opts)
    add_options_notes(opts)
  end
end

#load_pluginsObject



47
48
49
# File 'lib/repofetch/cli.rb', line 47

def load_plugins
  @config.plugins.each { |plugin| require plugin }
end

#new_pluginObject



51
52
53
54
55
# File 'lib/repofetch/cli.rb', line 51

def new_plugin
  return @plugin.from_args(@args) unless @plugin.nil?

  Repofetch.get_plugin(@repository_path, @args)
end

#startInteger

Run the command line interface.

Returns:

  • (Integer)

    The exit code.



27
28
29
30
31
32
33
34
# File 'lib/repofetch/cli.rb', line 27

def start
  load_plugins
  define_options.parse!(@args)

  return @exit unless @exit.nil?

  start_plugin
end