Class: IgnoreIt::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/ignore_it.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



13
14
15
16
17
18
19
# File 'lib/ignore_it.rb', line 13

def initialize(*args)
  super
  @config = Config.new
  @creator = Creator.new
  @list = List.new
  $glob_settings[:output] = "./.gitignore"
end

Instance Method Details

#add(*templateName) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ignore_it.rb', line 25

def add(*templateName)
  if options[:output]
    return false unless @creator.check_output_path(options[:output])
    $glob_settings[:output] = if options[:output][-1] == '/'
      options[:output] + '.gitignore'
    else
      options[:output] + '/.gitignore'
    end
  end
  if options[:force]
    $glob_settings[:force] = true
  end
  templateName.each do |name|
    name = name.downcase
    if @list.check_list(name)
      @creator.create_api_ignore(name)
    else
      puts "The template #{name} you tried to fetch does not exist".colorize(:red)
      puts "Please checkout the available templates with " + "ignore-it list".colorize(:green)
    end
  end
end

#listObject



73
74
75
76
77
78
# File 'lib/ignore_it.rb', line 73

def list
  puts "---- Available templates from gitignore.io: ----"
  @list.show_list
  puts "---- Available user templates (see ~/.ignore-it/config.yml) ----"
  @list.show_own_files
end

#own(*fileName) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ignore_it.rb', line 49

def own(*fileName)
  if options[:output]
    return false unless @creator.check_output_path(options[:output])
    $glob_settings[:output] = if options[:output][-1] == '/'
      options[:output] + '.gitignore'
    else
      options[:output] + '/.gitignore'
    end
  end
  if options[:force] == true
    $glob_settings[:force] = true
  end
  fileName.each do |name|
    if @list.check_own_files(name)
      @creator.create_own_ignore(name)
    else
      puts "The template #{name} you tried to create does not exist".colorize(:red)
      puts "The following templates are available:".colorize(:red)
      @list.show_own_files
    end
  end
end