Class: Changit::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/changit/cli.rb', line 7

def initialize
  @options = {}
  @options[:target_paths] = []

  opt_parser = OptionParser.new do |opt|
    opt.banner = "Usage: changit [OPTIONS]"
    opt.separator  ""
    opt.separator  "Options"

    opt.on("-s", "--source SOURCE","Which gitconfig file to copy from") do |src_path|
      @options[:src_path] = src_path
    end

    opt.on("-t", "--target TARGET","Which directory to copy the config to."\
                                  " To copy to different directories, pass more than one -t argument each for one directory"
          ) do |target_path|
      @options[:target_paths] << target_path
    end

    opt.on("-v", "--version","Show version number") do
      puts Changit::VERSION
      exit
    end

    opt.on("-h", "--help","Show CLI options") do
      puts opt_parser
      exit
    end
  end

  opt_parser.parse!

  @options[:target_paths] = nil if @options[:target_paths].empty?
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/changit/cli.rb', line 5

def options
  @options
end